Spaces:
Runtime error
Runtime error
Update
Browse files
app.py
CHANGED
|
@@ -1,5 +1,22 @@
|
|
| 1 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
|
|
|
|
|
|
| 5 |
agent.run("What is the sum of 2 and 6")
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool
|
| 2 |
+
import datetime
|
| 3 |
+
import pytz
|
| 4 |
|
| 5 |
+
@tool
|
| 6 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 7 |
+
"""A tool that fetches the current local time in a specified timezone.
|
| 8 |
+
Args:
|
| 9 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 10 |
+
"""
|
| 11 |
+
try:
|
| 12 |
+
# Create timezone object
|
| 13 |
+
tz = pytz.timezone(timezone)
|
| 14 |
+
# Get current time in that timezone
|
| 15 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 16 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 19 |
|
| 20 |
+
# Initialize the agent with both the DuckDuckGoSearchTool and the get_current_time_in_timezone tool
|
| 21 |
+
agent = CodeAgent(tools=[DuckDuckGoSearchTool(), get_current_time_in_timezone], model=HfApiModel())
|
| 22 |
agent.run("What is the sum of 2 and 6")
|