Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,6 +34,24 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# 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:
|
|
@@ -55,7 +73,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,
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
| 37 |
+
@tool
|
| 38 |
+
def get_weather(location: str) -> str:
|
| 39 |
+
"""A tool that fetches the current weather for a given location.
|
| 40 |
+
Args:
|
| 41 |
+
location: Name of the city or place (e.g., 'Bangalore').
|
| 42 |
+
"""
|
| 43 |
+
try:
|
| 44 |
+
# Using wttr.in which returns plaintext weather info
|
| 45 |
+
response = requests.get(f"https://wttr.in/{location}?format=3")
|
| 46 |
+
if response.status_code == 200:
|
| 47 |
+
return f"Weather in {location}: {response.text.strip()}"
|
| 48 |
+
else:
|
| 49 |
+
return f"Failed to get weather data for {location} (status code: {response.status_code})"
|
| 50 |
+
except Exception as e:
|
| 51 |
+
return f"Error fetching weather for {location}: {str(e)}"
|
| 52 |
+
|
| 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 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
+
tools=[final_answer , get_current_time_in_timezone, get_weather], ## add your tools here (don't remove final answer)
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|