Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,50 @@ 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.
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def get_weather(city: str, days: Optional[int] = 1) -> str:
|
| 23 |
+
"""
|
| 24 |
+
A tool that fetches weather information for a given city.
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
city (str): The city to get the weather for.
|
| 28 |
+
days (Optional[int]): The number of days for the forecast (default is 1).
|
| 29 |
+
|
| 30 |
+
Returns:
|
| 31 |
+
str: A formatted weather report.
|
| 32 |
+
"""
|
| 33 |
+
try:
|
| 34 |
+
# 1️⃣ Open-Meteo API URL (Basis-URL für Wetterdaten)
|
| 35 |
+
api_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1&language=en&format=json"
|
| 36 |
+
|
| 37 |
+
# 2️⃣ Stadt in Koordinaten umwandeln (da API GPS-Koordinaten benötigt)
|
| 38 |
+
response = requests.get(api_url)
|
| 39 |
+
response.raise_for_status()
|
| 40 |
+
data = response.json()
|
| 41 |
+
|
| 42 |
+
if "results" not in data or len(data["results"]) == 0:
|
| 43 |
+
return f"❌ Keine Wetterdaten für {city} gefunden."
|
| 44 |
+
|
| 45 |
+
lat = data["results"][0]["latitude"]
|
| 46 |
+
lon = data["results"][0]["longitude"]
|
| 47 |
+
|
| 48 |
+
# 3️⃣ Wetterdaten abrufen
|
| 49 |
+
weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t_weather=true"
|
| 50 |
+
weather_response = requests.get(weather_url)
|
| 51 |
+
weather_response.raise_for_status()
|
| 52 |
+
weather_data = weather_response.json()
|
| 53 |
+
|
| 54 |
+
# 4️⃣ Wetterdaten formatieren
|
| 55 |
+
weather = weather_data["current_weather"]
|
| 56 |
+
temp = weather["temperature"]
|
| 57 |
+
windspeed = weather["windspeed"]
|
| 58 |
+
condition = weather["weathercode"]
|
| 59 |
+
|
| 60 |
+
return f"🌍 Wetter in {city}: {temp}°C, Windgeschwindigkeit: {windspeed} km/h, Wettercode: {condition}"
|
| 61 |
+
|
| 62 |
+
except requests.exceptions.RequestException as e:
|
| 63 |
+
return f"❌ Fehler beim Abrufen der Wetterdaten: {str(e)}"
|
| 64 |
+
|
| 65 |
@tool
|
| 66 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 67 |
"""A tool that fetches the current local time in a specified timezone.
|