Spaces:
Runtime error
Runtime error
File size: 1,589 Bytes
2f7ba87 9b5b26a 2f7ba87 c19d193 9b5b26a 2f7ba87 800a50a 9b5b26a 2f7ba87 9b5b26a 2f7ba87 ae7a494 800a50a 2f7ba87 8c01ffb 2f7ba87 800a50a 8c01ffb 2f7ba87 8c01ffb 2f7ba87 8fe992b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | from smolagents import CodeAgent, DuckDuckGoSearchTool, load_tool, tool
import datetime
import pytz
import requests
import yaml
# Predefined answers
PREDEFINED_RESPONSES = {
"tokyo": "The best time to visit Tokyo is during spring (March to May) or autumn (September to November).",
"eiffel tower": "The best time to visit the Eiffel Tower is early morning or late evening to avoid crowds.",
"rome": "The best time to visit the Colosseum is in the early morning or late afternoon to skip long lines.",
"machu picchu": "The dry season from May to October is the best time to visit Machu Picchu."
}
@tool
def get_current_time_in_timezone(timezone: str) -> str:
"""Fetches the current local time in a specified timezone."""
try:
tz = pytz.timezone(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: {str(e)}"
@tool
def get_best_time_to_visit(place: str) -> str:
"""Fetches the best time to visit a place based on predefined knowledge."""
place = place.lower()
return PREDEFINED_RESPONSES.get(place, f"Sorry, I don't have predefined info for {place}. Try a web search.")
web_search_tool = DuckDuckGoSearchTool()
agent = CodeAgent(
tools=[get_current_time_in_timezone, get_best_time_to_visit, web_search_tool],
max_steps=6,
verbosity_level=1,
name="TravelInfoAgent",
description="Provides travel and time zone information using predefined answers and web search."
)
|