Humberto commited on
Commit
0aff985
·
verified ·
1 Parent(s): 9a8c112

Addition of a weather tool

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -4,19 +4,35 @@ 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_cutom_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:
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import requests
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_cutom_tool(city_name:str, api_key: str)-> 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 returns the weather in a given city
16
  Args:
17
+ city_name: the name of the city
 
18
  """
19
+ weather_url = "http://api.weatherapi.com/v1/current.json?key=" + api_key + "&q=" + city_name + "&aqi=no"
20
+
21
+ try:
22
+ r = requests.get(weather_url,timeout=3)
23
+ r.raise_for_status()
24
+ except requests.exceptions.HTTPError as errh:
25
+ print ("Http Error:",errh)
26
+ except requests.exceptions.ConnectionError as errc:
27
+ print ("Error Connecting:",errc)
28
+ except requests.exceptions.Timeout as errt:
29
+ print ("Timeout Error:",errt)
30
+ except requests.exceptions.RequestException as err:
31
+ print ("OOps: Something Else",err)
32
+
33
+ result = r.json()
34
+ return_msg = "The current weather in " + result['location']['region'] + " is " + result['current']['condition']['text']
35
+ return return_msg
36
 
37
  @tool
38
  def get_current_time_in_timezone(timezone: str) -> str: