Spaces:
Running
Running
Download tools/time_tool.py from EmincanY/First_agent_template: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/spaces/EmincanY/First_agent_template/resolve/main/tools/time_tool.py
- Command line
-
hf download hf://spaces/EmincanY/First_agent_template/tools/time_tool.py
-
curl -L -o time_tool.py https://huggingface.co/spaces/EmincanY/First_agent_template/resolve/main/tools/time_tool.py
670 Bytes
| from smolagents import tool | |
| import datetime | |
| import pytz | |
| 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)}" |