smolagent_practice / tools /get_current_time_in_timezone.py
Justchidi's picture
Upload agent
6f4a389 verified
Raw History Blame Contribute Delete
860 Bytes
from smolagents import Tool
from typing import Any, Optional
class SimpleTool(Tool):
name = "get_current_time_in_timezone"
description = "Returns the current local time for a given timezone."
inputs = {"timeZone":{"type":"string","description":"A valid timezone string (e.g., 'America/New_York')"}}
output_type = "string"
def forward(self, timeZone: str) -> str:
"""
Returns the current local time for a given timezone.
Args:
timeZone: A valid timezone string (e.g., 'America/New_York')
"""
import pytz, datetime
try:
tz = pytz.timezone(timeZone)
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
return f"The current time in {timeZone} is {local_time}"
except Exception as e:
return f"Error: {str(e)}"