Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadded a weather tool
app.py
CHANGED
|
@@ -18,6 +18,39 @@ 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 SearchWebTool(query:str)-> list: #it's import to specify the return type
|
| 23 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def CityTemperatureTool(city: str) -> str:
|
| 23 |
+
"""
|
| 24 |
+
Get the current temperature (°F) for a city using Open-Meteo.
|
| 25 |
+
Example: CityTemperatureTool("Columbus")
|
| 26 |
+
"""
|
| 27 |
+
if not city.strip():
|
| 28 |
+
return "Please provide a valid city name."
|
| 29 |
+
|
| 30 |
+
# Geocode city to get coordinates
|
| 31 |
+
geo = requests.get(
|
| 32 |
+
"https://geocoding-api.open-meteo.com/v1/search",
|
| 33 |
+
params={"name": city, "count": 1}
|
| 34 |
+
).json()
|
| 35 |
+
results = geo.get("results")
|
| 36 |
+
if not results:
|
| 37 |
+
return f"Could not find '{city}'."
|
| 38 |
+
lat, lon = results[0]["latitude"], results[0]["longitude"]
|
| 39 |
+
|
| 40 |
+
# Get current temperature
|
| 41 |
+
weather = requests.get(
|
| 42 |
+
"https://api.open-meteo.com/v1/forecast",
|
| 43 |
+
params={
|
| 44 |
+
"latitude": lat,
|
| 45 |
+
"longitude": lon,
|
| 46 |
+
"current": "temperature_2m",
|
| 47 |
+
"temperature_unit": "fahrenheit"
|
| 48 |
+
}
|
| 49 |
+
).json()
|
| 50 |
+
|
| 51 |
+
temp = weather.get("current", {}).get("temperature_2m")
|
| 52 |
+
return f"{temp}°F" if temp is not None else "Temperature data not available."
|
| 53 |
+
|
| 54 |
@tool
|
| 55 |
def SearchWebTool(query:str)-> list: #it's import to specify the return type
|
| 56 |
#Keep this format for the description / args / args description but feel free to modify the tool
|