Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,41 @@ 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.
|
@@ -55,7 +90,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
+
|
22 |
+
@tool
|
23 |
+
def geocode_location(city: str) -> dict:
|
24 |
+
"""A tool that returns latitude and longitude for a given city name
|
25 |
+
Args:
|
26 |
+
city: a string representing the name of a city
|
27 |
+
"""
|
28 |
+
import requests
|
29 |
+
api_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1&language=en&format=json"
|
30 |
+
response = requests.get(api_url)
|
31 |
+
if response.status_code == 200:
|
32 |
+
data = response.json()
|
33 |
+
lat_lng = {"lat": data.get("latitude", "No latitude information available"),
|
34 |
+
"lng": data.get("longitude", "No longitude information available"),}
|
35 |
+
return lat_lng
|
36 |
+
else:
|
37 |
+
return "Error: Unable to fetch weather data."
|
38 |
+
|
39 |
+
@tool
|
40 |
+
def get_weather(lat:float, lng:float, ) -> dict:
|
41 |
+
"""A tool that fetches the weather for a given city
|
42 |
+
Args:
|
43 |
+
lat: a float representing latitude
|
44 |
+
lng: a float representing longitude
|
45 |
+
"""
|
46 |
+
import requests
|
47 |
+
api_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lng}¤t=temperature_2m&temperature_unit=fahrenheit"
|
48 |
+
response = requests.get(api_url)
|
49 |
+
if response.status_code == 200:
|
50 |
+
data = response.json()
|
51 |
+
current_temp = data.get("current", "No current weather information available")
|
52 |
+
return current_temp.get("temperature_2m", "No temperature available")
|
53 |
+
else:
|
54 |
+
return "Error: Unable to fetch weather data."
|
55 |
+
|
56 |
@tool
|
57 |
def get_current_time_in_timezone(timezone: str) -> str:
|
58 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
90 |
|
91 |
agent = CodeAgent(
|
92 |
model=model,
|
93 |
+
tools=[final_answer, get_current_time_in_timezone, geocode_location, get_weather], ## add your tools here (don't remove final answer)
|
94 |
max_steps=6,
|
95 |
verbosity_level=1,
|
96 |
grammar=None,
|