Spaces:
Runtime error
Runtime error
added weather tool
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -33,7 +34,24 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 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,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
| 37 |
+
@tool
|
| 38 |
+
def get_weather(location: str) -> str:
|
| 39 |
+
"""A Tool that fetech current weather of a particular location
|
| 40 |
+
Args:
|
| 41 |
+
location: A String representing a Vaild Location(e.g., 'London' ").
|
| 42 |
+
"""
|
| 43 |
+
api = os.getenv(WEATHER_API)
|
| 44 |
+
if not api:
|
| 45 |
+
raise ValueError("API key not found")
|
| 46 |
|
| 47 |
+
url = f"http://api.weatherapi.com/v1/current.json?key={api_key}&q={location}&aqi=no"
|
| 48 |
+
try:
|
| 49 |
+
response = requests.get(url)
|
| 50 |
+
weather_info = response.json()
|
| 51 |
+
return weather_info
|
| 52 |
+
except requests.RequestExpection as e:
|
| 53 |
+
return f"Failed to fetch the data: {e}"
|
| 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=[get_weather, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|