dominik.smogor
Added token
d9fe58a
from typing import Any, Optional
from smolagents.tools import Tool
class FindTimezone(Tool):
name = "find_timezone"
description = "Finds apropriate time zone ID if given major city name in english"
inputs = {'city': {'type': 'string', 'description': 'English name of a major city for which time zone shall be found'}}
output_type = "string"
def forward(self, city: str) -> str:
def forward(self, city: str) -> str:
# Import zoneinfo for timezone handling
from zoneinfo import available_timezones
# Get all available timezones
all_zones = available_timezones()
# Convert city to lowercase for case-insensitive matching
city = city.lower()
# Search for timezone containing the city name
for zone in all_zones:
# Split timezone into components and check if city matches
components = zone.split('/')
if len(components) > 1 and components[-1].lower().replace('_',' ') == city:
return zone
# Return None if no match found
return None
def __init__(self, *args, **kwargs):
self.is_initialized = False