Spaces:
Sleeping
Sleeping
Download tools/get_current_time_in_timezone.py from Justchidi/smolagent_practice: direct link, hf CLI and curl.
- Browser
- Download file 860 Bytes
-
https://huggingface.co/spaces/Justchidi/smolagent_practice/resolve/main/tools/get_current_time_in_timezone.py
- Command line
-
hf download hf://spaces/Justchidi/smolagent_practice/tools/get_current_time_in_timezone.py
-
curl -L -o get_current_time_in_timezone.py https://huggingface.co/spaces/Justchidi/smolagent_practice/resolve/main/tools/get_current_time_in_timezone.py
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)}" |