smiquensi commited on
Commit
927b642
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -33,6 +33,39 @@ 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
 
@@ -55,7 +88,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,
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def get_weather_forecast(city: str) -> str:
38
+ """Fetches the weather forecast for the next 7 days using a free API (wttr.in).
39
+
40
+ Args:
41
+ city: The name of the city (e.g., 'Valencia', 'Madrid').
42
+
43
+ Returns:
44
+ A formatted 7-day weather forecast.
45
+ """
46
+ try:
47
+ url = f"https://wttr.in/{city}?format=j1&lang=es"
48
+ response = requests.get(url)
49
+
50
+ if response.status_code != 200:
51
+ return f"❌ Error: No pude obtener el clima para {city}. Verifica el nombre de la ciudad."
52
+
53
+ data = response.json()
54
+
55
+ forecast = f"🌤️ Pronóstico del tiempo en {city} para los próximos 7 días:\n"
56
+
57
+ for day in data["weather"]:
58
+ date = day["date"]
59
+ avg_temp = day["avgtempC"]
60
+ condition = day["hourly"][4]["weatherDesc"][0]["value"] # Clima a medio día
61
+
62
+ forecast += f"- 📅 {date}: {avg_temp}°C, {condition}\n"
63
+
64
+ return forecast
65
+
66
+ except Exception as e:
67
+ return f"❌ Error al obtener el clima: {str(e)}"
68
+
69
 
70
  final_answer = FinalAnswerTool()
71
 
 
88
 
89
  agent = CodeAgent(
90
  model=model,
91
+ tools=[final_answer, get_weather_forecast, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
92
  max_steps=6,
93
  verbosity_level=1,
94
  grammar=None,