Update app.py
#626
by Bazila-w - opened
app.py
CHANGED
|
@@ -32,7 +32,35 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -55,7 +83,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
+
@tool
|
| 36 |
+
def get_current_weather(city: str) -> str:
|
| 37 |
+
"""Fetch current weather for a given city (no API key required).
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
city: Name of the city (e.g., 'Hyderabad', 'London')
|
| 41 |
+
"""
|
| 42 |
+
try:
|
| 43 |
+
url = f"https://wttr.in/{city}?format=j1"
|
| 44 |
+
response = requests.get(url)
|
| 45 |
+
data = response.json()
|
| 46 |
|
| 47 |
+
current = data["current_condition"][0]
|
| 48 |
+
|
| 49 |
+
temp_c = current["temp_C"]
|
| 50 |
+
feels_like = current["FeelsLikeC"]
|
| 51 |
+
humidity = current["humidity"]
|
| 52 |
+
weather_desc = current["weatherDesc"][0]["value"]
|
| 53 |
+
|
| 54 |
+
return (
|
| 55 |
+
f"Current weather in {city}:\n"
|
| 56 |
+
f"- Condition: {weather_desc}\n"
|
| 57 |
+
f"- Temperature: {temp_c}°C\n"
|
| 58 |
+
f"- Feels like: {feels_like}°C\n"
|
| 59 |
+
f"- Humidity: {humidity}%"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
except Exception as e:
|
| 63 |
+
return f"Error fetching weather for {city}: {str(e)}"
|
| 64 |
|
| 65 |
final_answer = FinalAnswerTool()
|
| 66 |
|
|
|
|
| 83 |
|
| 84 |
agent = CodeAgent(
|
| 85 |
model=model,
|
| 86 |
+
tools=[final_answer], get_current_weather, get_current_time_in_timezone ## add your tools here (don't remove final answer)
|
| 87 |
max_steps=6,
|
| 88 |
verbosity_level=1,
|
| 89 |
grammar=None,
|