File size: 1,291 Bytes
d9fe58a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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