File size: 3,143 Bytes
4ec2830
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b7d4477
4ec2830
b7d4477
 
69e6ec4
 
b7d4477
 
 
69e6ec4
b7d4477
 
 
 
69e6ec4
 
b7d4477
69e6ec4
4ec2830
b7d4477
4ec2830
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from typing import Any, Optional, List
from smolagents import tool
from smolagents.tools import Tool

import duckduckgo_search

@tool
def create_link_to_public_transport_map(routes: List[str]) -> str:
    """A tool that create a link for a map with public transport routes. It can be used to display a route on a map.
    Args:
        routes: list of routes to display on the map
    """
    try:
        return f"https://ntrd.top/?routes="+"&routes=".join(routes)
    except Exception as e:
        return f"Error fetching link to maps for route '{routes}'"


@tool
def terminus_to_routes(terminus: str) -> List[str]:
    """
    A tool that fetches the route numbers for a given terminus but works only for trams not for buses.
    Example: terminus_to_routes('ZAPADNI KOLODVOR') -> [1]; terminus_to_routes('ZAPRUDE') -> [8, 14]
    Args:
        terminus: the terminus to search for
    """

    terminus_to_route_map = {
        'ZAPADNI KOLODVOR': ['1'],
        'BORONGAJ': ['1', '9', '17', '32'],
        'CRNOMEREC': ['2', '6', '11', '31'],
        'SAVISCE': ['2', '3', '33'],
        'LJUBLJANICA': ['3', '9', '12', '34'],
        'SAVSKI MOST': ['4', '7', '31'],
        'DUBEC': ['4', '11', '34'],
        'PRECKO': ['5', '17', '32'],
        'PARK MAKSIMIR': ['5'],
        'SOPOT': ['6'],
        'DUBRAVA': ['7', '12'],
        'MIHALJEVAC': ['8', '14', '15', '33'],
        'ZAPRUDE': ['8', '14'],
        'ZITNJAK': ['13'],
        'KVATERNIKOV TRG': ['13'],
        'GRACANSKO DOLJE': ['15']
    }

    routes = terminus_to_route_map.get(terminus.upper(), None)
    if routes:
       return routes
    else:
       return f"No routes found for terminus '{terminus}'. Available terminus: {list(terminus_to_route_map.keys())}"


# class TerminusToRoutes(Tool):
#     name = "terminus_to_route"
#     description = "A tool that fetches the route numbers for a given terminus but works only for trams not for buses. Example: 'ZAPADNI KOLODVOR' -> [1]; 'ZAPRUDE' -> [8, 14]"
#     inputs = {'terminus': {'type': 'string', 'description': 'The terminus to search for.'}}
#     output_type = "list"
#
#     def __init__(self):
#         super().__init__()
#         self.terminus_to_route_map = {
#             'ZAPADNI KOLODVOR': [1],
#             'BORONGAJ': [1, 9, 17, 32],
#             'ČRNOMEREC': [2, 6, 11, 31],
#             'SAVIŠĆE': [2, 3, 33],
#             'LJUBLJANICA': [3, 9, 12, 34],
#             'SAVSKI MOST': [4, 7, 31],
#             'DUBEC': [4, 11, 34],
#             'PREČKO': [5, 17, 32],
#             'PARK MAKSIMIR': [5],
#             'SOPOT': [6],
#             'DUBRAVA': [7, 12],
#             'MIHALJEVAC': [8, 14, 15, 33],
#             'ZAPRUĐE': [8, 14],
#             'ŽITNJAK': [13],
#             'KVATERNIKOV TRG': [13],
#             'GRAČANSKO DOLJE': [15]
#         }
#
#     def forward(self, terminus: str) -> str:
#         routes = self.terminus_to_route_map.get(terminus.upper())
#         if routes:
#             return routes
#         else:
#             return f"No routes found for terminus '{terminus}'. Available terminus: {list(self.terminus_to_route_map.keys())}"