Spaces:
Running
Running
adding weather tool
Browse files
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
|
14 |
-
|
15 |
-
"""A tool that does nothing yet
|
16 |
Args:
|
17 |
-
|
18 |
-
arg2: the second argument
|
19 |
"""
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
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,
|