Oyelami Oyewole A. commited on
Commit
eef0b54
·
verified ·
1 Parent(s): 9f39c86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -1
app.py CHANGED
@@ -18,6 +18,56 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -55,7 +105,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,
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def get_weather_forecast(city_name: str) -> str:
23
+ """Fetches the current weather forecast for a specified city using Open-Meteo API.
24
+
25
+ Args:
26
+ city_name: The name of the city to fetch the weather forecast for.
27
+
28
+ Returns:
29
+ A string describing the current weather forecast.
30
+ """
31
+ try:
32
+ # Geocode the city name to get latitude and longitude
33
+ geolocator = Nominatim(user_agent="weather_app")
34
+ location = geolocator.geocode(city_name)
35
+ if not location:
36
+ return f"Could not find location for '{city_name}'."
37
+
38
+ latitude = location.latitude
39
+ longitude = location.longitude
40
+
41
+ # Construct the API URL
42
+ api_url = (
43
+ f"https://api.open-meteo.com/v1/forecast?"
44
+ f"latitude={latitude}&longitude={longitude}&current_weather=true"
45
+ )
46
+
47
+ # Make the API request
48
+ response = requests.get(api_url)
49
+ response.raise_for_status()
50
+ data = response.json()
51
+
52
+ # Extract weather information
53
+ weather = data.get("current_weather")
54
+ if not weather:
55
+ return f"No weather data available for '{city_name}'."
56
+
57
+ temperature = weather.get("temperature")
58
+ windspeed = weather.get("windspeed")
59
+ weather_code = weather.get("weathercode")
60
+
61
+ return (
62
+ f"Current weather in {city_name}:\n"
63
+ f"Temperature: {temperature}°C\n"
64
+ f"Wind Speed: {windspeed} km/h\n"
65
+ f"Weather Code: {weather_code}"
66
+ )
67
+
68
+ except Exception as e:
69
+ return f"An error occurred: {e}"
70
+
71
  @tool
72
  def get_current_time_in_timezone(timezone: str) -> str:
73
  """A tool that fetches the current local time in a specified timezone.
 
105
 
106
  agent = CodeAgent(
107
  model=model,
108
+ tools=[final_answer,get_current_time_in_timezone(timezone),get_weather_forecast(cityname) ], ## add your tools here (don't remove final answer)
109
  max_steps=6,
110
  verbosity_level=1,
111
  grammar=None,