Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,4 +62,25 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 62 |
@tool
|
| 63 |
def get_weather(city: str, api_key: str) -> str:
|
| 64 |
"""
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
@tool
|
| 63 |
def get_weather(city: str, api_key: str) -> str:
|
| 64 |
"""
|
| 65 |
+
Fetches the current weather for a given city.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
city (str): The name of the city to fetch weather for.
|
| 69 |
+
api_key (str): Your API key for the OpenWeatherMap service.
|
| 70 |
+
|
| 71 |
+
Returns:
|
| 72 |
+
str: The current weather conditions in the city.
|
| 73 |
+
"""
|
| 74 |
+
try:
|
| 75 |
+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
|
| 76 |
+
response = requests.get(url)
|
| 77 |
+
data = response.json()
|
| 78 |
+
|
| 79 |
+
if response.status_code == 200:
|
| 80 |
+
temp = data["main"]["temp"]
|
| 81 |
+
description = data["weather"][0]["description"]
|
| 82 |
+
return f"The current temperature in {city} is {temp}°C with {description}."
|
| 83 |
+
else:
|
| 84 |
+
return f"Error fetching weather: {data.get('message', 'Unknown error')}"
|
| 85 |
+
except Exception as e:
|
| 86 |
+
return f"Error fetching weather: {str(e)}"
|