lathashree01 commited on
Commit
2199539
·
verified ·
1 Parent(s): ad261fc

adding weather tool

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -4,20 +4,34 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
- from tools.visit_webpage import VisitWebpageTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
14
- #Keep this format for the description / args / args description but feel free to modify the tool
15
- """A tool that does nothing yet
16
  Args:
17
- arg1: the first argument
18
- arg2: the second argument
19
  """
20
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  @tool
23
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -56,7 +70,7 @@ with open("prompts.yaml", 'r') as stream:
56
 
57
  agent = CodeAgent(
58
  model=model,
59
- tools=[final_answer, VisitWebpageTool], ## add your tools here (don't remove final answer)
60
  max_steps=6,
61
  verbosity_level=1,
62
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ # from tools.visit_webpage import VisitWebpageTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
+ def get_weather(location:str,)-> dict: #it's import to specify the return type
14
+ """A tool that fetches the weather and temperature of a given location.
 
15
  Args:
16
+ location: A string representing location (Eg. London)
 
17
  """
18
+ base_url = "https://api.openweathermap.org/data/2.5/weather"
19
+ params = {
20
+ "q": location,
21
+ "appid": self.api_key,
22
+ "units": "metric" # Get temperature in Celsius
23
+ }
24
+ response = requests.get(base_url, params=params)
25
+
26
+ if response.status_code == 200:
27
+ data = response.json()
28
+ return {
29
+ "location": data["name"],
30
+ "temperature": data["main"]["temp"],
31
+ "weather": data["weather"][0]["description"]
32
+ }
33
+ else:
34
+ return {"error": "Could not fetch weather data"}
35
 
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str:
 
70
 
71
  agent = CodeAgent(
72
  model=model,
73
+ tools=[final_answer, get_weather], ## add your tools here (don't remove final answer)
74
  max_steps=6,
75
  verbosity_level=1,
76
  grammar=None,