Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,48 @@ def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
21 |
"""
|
22 |
return "What magic will you build ?"
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
@tool
|
25 |
def model_download_tool(task: str) -> str:
|
26 |
"""
|
@@ -111,7 +153,7 @@ model = HfApiModel(
|
|
111 |
|
112 |
agent = CodeAgent(
|
113 |
model=model,
|
114 |
-
tools=[final_answer, image_generation_tool, get_stock_data_baostock], ## add your tools here (don't remove final answer)
|
115 |
max_steps=6,
|
116 |
verbosity_level=1,
|
117 |
grammar=None,
|
|
|
21 |
"""
|
22 |
return "What magic will you build ?"
|
23 |
|
24 |
+
# Weather Data Tool using weatherapi.com API
|
25 |
+
@tool
|
26 |
+
def weather_data_tool(location: str, api_key: str) -> str:
|
27 |
+
"""
|
28 |
+
A tool that fetches the current weather data for a given location using the weatherapi.com API.
|
29 |
+
|
30 |
+
Args:
|
31 |
+
location: The location for which to retrieve weather data (e.g., "London", "Paris", or "New York").
|
32 |
+
api_key: d3d95d8e1ada4f48a83112710251202
|
33 |
+
|
34 |
+
Returns:
|
35 |
+
A string with the current weather details (temperature, condition, etc.) or an error message.
|
36 |
+
"""
|
37 |
+
try:
|
38 |
+
# Construct the API URL for current weather data
|
39 |
+
url = f"http://api.weatherapi.com/v1/current.json?key={api_key}&q={location}&aqi=no"
|
40 |
+
response = requests.get(url)
|
41 |
+
if response.status_code != 200:
|
42 |
+
return f"Error: Unable to retrieve data. HTTP Status Code: {response.status_code}"
|
43 |
+
data = response.json()
|
44 |
+
# If the response includes an error, return its message
|
45 |
+
if "error" in data:
|
46 |
+
return f"Error: {data['error'].get('message', 'Unknown error')}"
|
47 |
+
# Extract location and current weather details
|
48 |
+
location_info = data.get("location", {})
|
49 |
+
current = data.get("current", {})
|
50 |
+
location_name = location_info.get("name", location)
|
51 |
+
region = location_info.get("region", "")
|
52 |
+
country = location_info.get("country", "")
|
53 |
+
temp_c = current.get("temp_c", "N/A")
|
54 |
+
condition = current.get("condition", {}).get("text", "N/A")
|
55 |
+
# Build a result string
|
56 |
+
result = f"Weather in {location_name}"
|
57 |
+
if region:
|
58 |
+
result += f", {region}"
|
59 |
+
if country:
|
60 |
+
result += f", {country}"
|
61 |
+
result += f": {temp_c}°C, {condition}."
|
62 |
+
return result
|
63 |
+
except Exception as e:
|
64 |
+
return f"An exception occurred: {str(e)}"
|
65 |
+
|
66 |
@tool
|
67 |
def model_download_tool(task: str) -> str:
|
68 |
"""
|
|
|
153 |
|
154 |
agent = CodeAgent(
|
155 |
model=model,
|
156 |
+
tools=[final_answer, image_generation_tool, get_stock_data_baostock, weather_data_tool], ## add your tools here (don't remove final answer)
|
157 |
max_steps=6,
|
158 |
verbosity_level=1,
|
159 |
grammar=None,
|