DiJeZet / tools /zet.py
grg's picture
removing cro letters from terminus_to_routes
69e6ec4
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())}"