Spaces:
Sleeping
Sleeping
updated get_sunrise_sunset
Browse files
app.py
CHANGED
|
@@ -34,24 +34,36 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
@tool
|
| 37 |
-
|
| 38 |
-
|
|
|
|
| 39 |
Args:
|
| 40 |
-
|
| 41 |
-
lon: Longitude of the location.
|
| 42 |
"""
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
try:
|
| 46 |
response = requests.get(url)
|
|
|
|
| 47 |
data = response.json()
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
except Exception as e:
|
| 52 |
return f"Error fetching sunrise/sunset data: {str(e)}"
|
| 53 |
|
| 54 |
|
|
|
|
| 55 |
final_answer = FinalAnswerTool()
|
| 56 |
|
| 57 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
@@ -73,7 +85,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 73 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
-
tools=[final_answer,
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
@tool
|
| 37 |
+
|
| 38 |
+
def get_sunrise_sunset(location: dict) -> str:
|
| 39 |
+
"""Fetches the sunrise and sunset times for a given location.
|
| 40 |
Args:
|
| 41 |
+
location: A dictionary containing 'lat' (latitude) and 'lon' (longitude).
|
|
|
|
| 42 |
"""
|
| 43 |
+
lat = location.get("lat")
|
| 44 |
+
lon = location.get("lon")
|
| 45 |
+
|
| 46 |
+
if lat is None or lon is None:
|
| 47 |
+
return "Error: Missing latitude or longitude."
|
| 48 |
+
|
| 49 |
+
url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&daily=sunrise,sunset&timezone=auto"
|
| 50 |
|
| 51 |
try:
|
| 52 |
response = requests.get(url)
|
| 53 |
+
response.raise_for_status() # Verifica si hay errores HTTP
|
| 54 |
data = response.json()
|
| 55 |
+
|
| 56 |
+
if "daily" in data and "sunrise" in data["daily"] and "sunset" in data["daily"]:
|
| 57 |
+
sunrise = data["daily"]["sunrise"][0]
|
| 58 |
+
sunset = data["daily"]["sunset"][0]
|
| 59 |
+
return f"Sunrise: {sunrise}, Sunset: {sunset}"
|
| 60 |
+
else:
|
| 61 |
+
return "Error: Unexpected API response format"
|
| 62 |
except Exception as e:
|
| 63 |
return f"Error fetching sunrise/sunset data: {str(e)}"
|
| 64 |
|
| 65 |
|
| 66 |
+
|
| 67 |
final_answer = FinalAnswerTool()
|
| 68 |
|
| 69 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 85 |
|
| 86 |
agent = CodeAgent(
|
| 87 |
model=model,
|
| 88 |
+
tools=[final_answer, get_sunrise_sunset], ## add your tools here (don't remove final answer)
|
| 89 |
max_steps=6,
|
| 90 |
verbosity_level=1,
|
| 91 |
grammar=None,
|