Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdd tool de clima
app.py
CHANGED
|
@@ -33,6 +33,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -56,7 +78,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def get_weather(city: str) -> str:
|
| 38 |
+
"""A tool that fetches the current weather for a specified city.
|
| 39 |
+
Args:
|
| 40 |
+
city: The name of the city to get the weather for.
|
| 41 |
+
"""
|
| 42 |
+
api_key = "c46c960cf2d8dd517715b8ff14818d7e" # Replace with your actual OpenWeather API key
|
| 43 |
+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
response = requests.get(url)
|
| 47 |
+
data = response.json()
|
| 48 |
+
|
| 49 |
+
if response.status_code == 200:
|
| 50 |
+
weather_description = data['weather'][0]['description']
|
| 51 |
+
temperature = data['main']['temp']
|
| 52 |
+
return f"The current weather in {city} is {weather_description} with a temperature of {temperature}°C."
|
| 53 |
+
else:
|
| 54 |
+
return f"Error fetching weather for city '{city}': {data['message']}"
|
| 55 |
+
except Exception as e:
|
| 56 |
+
return f"Error fetching weather for city '{city}': {str(e)}"
|
| 57 |
+
|
| 58 |
|
| 59 |
final_answer = FinalAnswerTool()
|
| 60 |
|
|
|
|
| 78 |
|
| 79 |
agent = CodeAgent(
|
| 80 |
model=model,
|
| 81 |
+
tools=[final_answer, get_weather], ## add your tools here (don't remove final answer)
|
| 82 |
max_steps=6,
|
| 83 |
verbosity_level=1,
|
| 84 |
grammar=None,
|