pavtch commited on
Commit
9d718ba
·
verified ·
1 Parent(s): ae7a494

added get_current_time_in_timezone tool

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -33,6 +33,24 @@ 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 +73,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_sunrise_sunset(lat: float, lon: float) -> str:
38
+ """Fetches the sunrise and sunset times for a given latitude and longitude.
39
+ Args:
40
+ lat: Latitude of the location.
41
+ lon: Longitude of the location.
42
+ """
43
+ url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&daily=sunrise,sunset&timezone=auto"
44
+
45
+ try:
46
+ response = requests.get(url)
47
+ data = response.json()
48
+ sunrise = data["daily"]["sunrise"][0]
49
+ sunset = data["daily"]["sunset"][0]
50
+ return f"Sunrise: {sunrise}, Sunset: {sunset}"
51
+ except Exception as e:
52
+ return f"Error fetching sunrise/sunset data: {str(e)}"
53
+
54
 
55
  final_answer = FinalAnswerTool()
56
 
 
73
 
74
  agent = CodeAgent(
75
  model=model,
76
+ tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
77
  max_steps=6,
78
  verbosity_level=1,
79
  grammar=None,