Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,21 +34,27 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
@tool
|
| 37 |
-
def get_weather_api(city
|
| 38 |
-
"""A tool that
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
"""
|
| 42 |
api_key = 'ff33163dc424d6430b66535cb02dda7d'
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
@tool
|
| 37 |
+
def get_weather_api(city: str) -> str:
|
| 38 |
+
"""A tool that gets the current weather.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
city (str): A string that represents a city name.
|
| 42 |
"""
|
| 43 |
api_key = 'ff33163dc424d6430b66535cb02dda7d'
|
| 44 |
+
url = f"http://api.weatherstack.com/current?access_key={api_key}&query={city}"
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
response = requests.get(url)
|
| 48 |
+
data = response.json()
|
| 49 |
+
|
| 50 |
+
if 'current' in data and 'weather_descriptions' in data['current']:
|
| 51 |
+
temp = data['current']['weather_descriptions'][0]
|
| 52 |
+
return f"The current weather in {city} is {temp}."
|
| 53 |
+
else:
|
| 54 |
+
return f"Could not retrieve weather data for {city}."
|
| 55 |
+
except Exception as e:
|
| 56 |
+
return f"Error retrieving weather data: {str(e)}"
|
| 57 |
+
|
| 58 |
|
| 59 |
|
| 60 |
|