Spaces:
Sleeping
Sleeping
Creating my tool and adding tools to the agent.
Browse files
app.py
CHANGED
|
@@ -9,14 +9,27 @@ 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
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +68,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,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_weather_from_city(latitude: float, longitude: float)-> list: #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 fetches the weather from a site using the latitude and longitude
|
| 15 |
Args:
|
| 16 |
+
latitude: the latitude coordinate for the specific site
|
| 17 |
+
longitude: the longitude coordinate for the specific site
|
| 18 |
"""
|
| 19 |
+
api_url = "https://api.open-meteo.com/v1/forecast"
|
| 20 |
+
params = {"latitude": latitude, "longitude": longitude, "current_weather": True}
|
| 21 |
+
try:
|
| 22 |
+
response = requests.get(api_url, params=params)
|
| 23 |
+
response.raise_for_status()
|
| 24 |
+
weather_data = response.json()
|
| 25 |
+
current_weather = weather_data.get("current_weather", {})
|
| 26 |
+
temperature = current_weather.get("temperature")
|
| 27 |
+
windspeed = current_weather.get("windspeed")
|
| 28 |
+
weather_code = current_weather.get("weathercode")
|
| 29 |
+
return [temperature, windspeed, weather_code]
|
| 30 |
+
|
| 31 |
+
except requests.exceptions.RequestException as e:
|
| 32 |
+
return [-1, -1, -1]
|
| 33 |
|
| 34 |
@tool
|
| 35 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
+
tools=[final_answer, image_generation_tool, get_current_time_in_timezone, get_weather_from_city], ## add your tools here (don't remove final answer)
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|