Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- tools/time_tool.py +16 -0
- tools/tourist_activity.py +24 -0
tools/time_tool.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import pytz
|
| 3 |
+
from smolagents import tool
|
| 4 |
+
|
| 5 |
+
@tool
|
| 6 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 7 |
+
"""Fetches the current local time in a specified timezone.
|
| 8 |
+
Args:
|
| 9 |
+
timezone: A string representing a valid timezone (e.g., 'Asia/Tokyo').
|
| 10 |
+
"""
|
| 11 |
+
try:
|
| 12 |
+
tz = pytz.timezone(timezone)
|
| 13 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 14 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
tools/tourist_activity.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
from smolagents import tool
|
| 3 |
+
|
| 4 |
+
@tool
|
| 5 |
+
def suggest_tourist_activity(local_time: str, timezone: str) -> str:
|
| 6 |
+
"""Suggests a tourist activity based on local time.
|
| 7 |
+
Args:
|
| 8 |
+
local_time: A string representing the local time (e.g., "2026-01-19 21:30:15")
|
| 9 |
+
timezone: The timezone name (e.g., "Asia/Tokyo")
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
datetime_object = datetime.datetime.strptime(local_time, "%Y-%m-%d %H:%M:%S")
|
| 13 |
+
current_hour = datetime_object.hour
|
| 14 |
+
|
| 15 |
+
if 5 <= current_hour < 12:
|
| 16 |
+
activity = "Start your day with breakfast at a local café."
|
| 17 |
+
elif 12 <= current_hour < 18:
|
| 18 |
+
activity = "Explore a museum or walk through a shopping district."
|
| 19 |
+
elif 18 <= current_hour < 22:
|
| 20 |
+
activity = "Enjoy dinner and take a scenic city walk."
|
| 21 |
+
else:
|
| 22 |
+
activity = "Consider resting or exploring local nightlife."
|
| 23 |
+
|
| 24 |
+
return f"It's {local_time} in {timezone}. {activity}"
|