Spaces:
Runtime error
Runtime error
get_weather function (tool) added which feteches the current weather data for given location
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
@@ -18,6 +19,27 @@ 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.
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
import requests
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
19 |
"""
|
20 |
return "What magic will you build ?"
|
21 |
|
22 |
+
@tool
|
23 |
+
def get_weather(location: str):
|
24 |
+
"""A tool that fetches the current weather data of a specified location.
|
25 |
+
Args:
|
26 |
+
location: A string representing a valid location name (e.g., 'Leicester/United Kingdom').
|
27 |
+
"""
|
28 |
+
url = "https://api.weatherapi.com/v1/current.json"
|
29 |
+
|
30 |
+
try:
|
31 |
+
response = requests.get(f'{url}?key={os.getenv('WEATHER_API_KEY')}&q={location}')
|
32 |
+
if (response.status_code==200):
|
33 |
+
return response.json()
|
34 |
+
else:
|
35 |
+
return response.json()
|
36 |
+
|
37 |
+
except Exception as e:
|
38 |
+
return f"Error fetching weather data for locaion '{location}': {str(e)}"
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
@tool
|
44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
45 |
"""A tool that fetches the current local time in a specified timezone.
|