File size: 969 Bytes
0ee543e
 
 
8fe992b
0ee543e
 
 
 
 
 
 
 
 
 
 
 
 
 
9b5b26a
0ee543e
 
4a0108c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool
import datetime
import pytz

@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """A tool that fetches the current local time in a specified timezone.
    Args:
        timezone: A string representing a valid timezone (e.g., 'America/New_York').
    """
    try:
        # Create timezone object
        tz = pytz.timezone(timezone)
        # Get current time in that timezone
        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
        return f"The current local time in {timezone} is: {local_time}"
    except Exception as e:
        return f"Error fetching time for timezone '{timezone}': {str(e)}"

# Initialize the agent with both the DuckDuckGoSearchTool and the get_current_time_in_timezone tool
agent = CodeAgent(tools=[DuckDuckGoSearchTool(), get_current_time_in_timezone], model=HfApiModel())
agent.run("What is the current time in Asia/Kolkata")