Ynvers commited on
Commit
6b2b07c
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -7
app.py CHANGED
@@ -3,21 +3,55 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
 
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
 
 
 
 
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
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 +89,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,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import openmeteo_requests
7
+ import requests_cache
8
+ from retry_requests import retry
9
  from tools.final_answer import FinalAnswerTool
10
 
11
  from Gradio_UI import GradioUI
12
 
13
+ # Set up the Open-Meteo API client with caching and retry logic
14
+ cache_session = requests_cache.CachedSession('.cache', expire_after=3600)
15
+ retry_session = retry(cache_session, retries=5, backoff_factor=0.2)
16
+ openmeteo = openmeteo_requests.Client(session=retry_session)
17
+
18
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
19
  @tool
20
+ def get_weather(lat: float, lon: float) -> str: #it's import to specify the return type
21
  #Keep this format for the description / args / args description but feel free to modify the tool
22
+ """A tool that fetches the current weather information for given latitude and longitude.
23
  Args:
24
+ lat: Latitude of the location.
25
+ lon: Longitude of the location.
26
  """
27
+ url = "https://api.open-meteo.com/v1/forecast"
28
+ params = {
29
+ "latitude": lat,
30
+ "longitude": lon,
31
+ "hourly": ["temperature_2m", "wind_speed_10m", "weather_code", "relative_humidity_2m"],
32
+ "timezone": "auto"
33
+ }
34
+ try:
35
+ # Make the API call to fetch weather data
36
+ responses = openmeteo.weather_api(url, params=params)
37
+ response = responses[0]
38
+ # Extract and format relevant data
39
+ temperature = response.hourly['temperature_2m'][0] # Example: temperature at the first hour
40
+ wind_speed = response.hourly['wind_speed_10m'][0]
41
+ weather_code = response.hourly['weather_code'][0]
42
+ humidity = response.hourly['relative_humidity_2m'][0]
43
+
44
+ weather_report = (
45
+ f"Current weather:\n"
46
+ f"Temperature: {temperature}°C\n"
47
+ f"Wind Speed: {wind_speed} km/h\n"
48
+ f"Weather Code: {weather_code}\n"
49
+ f"Humidity: {humidity}%"
50
+ )
51
+ return weather_report
52
+ except Exception as e:
53
+ return f"Error fetching weather data: {str(e)}"
54
+
55
  @tool
56
  def get_current_time_in_timezone(timezone: str) -> str:
57
  """A tool that fetches the current local time in a specified timezone.
 
89
 
90
  agent = CodeAgent(
91
  model=model,
92
+ tools=[final_answer, get_weather, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
93
  max_steps=6,
94
  verbosity_level=1,
95
  grammar=None,