Spaces:
Sleeping
Sleeping
tools fix
Browse files- tools/weather.py +13 -9
- tools/web_search.py +7 -0
tools/weather.py
CHANGED
|
@@ -9,14 +9,18 @@ from smolagents.tools import Tool
|
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
class WeatherTool(Tool):
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
Args:
|
| 18 |
-
location: a string that representing the location that the user want to know the weather
|
| 19 |
"""
|
|
|
|
| 20 |
base_url = "https://api.open-meteo.com/v1/forecast"
|
| 21 |
|
| 22 |
key = os.getenv('GOOGLE_MAPS_API')
|
|
@@ -96,8 +100,8 @@ class WeatherTool(Tool):
|
|
| 96 |
|
| 97 |
description = weather_descriptions.get(current_weather_code, "Condizione meteo sconosciuta")
|
| 98 |
return description
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
|
| 103 |
|
|
|
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
class WeatherTool(Tool):
|
| 12 |
+
name = "weather_data"
|
| 13 |
+
description = "Fetches the current weather for a given location using Google Geocoding and Open-Meteo."
|
| 14 |
+
inputs = {'location': {'type': 'string', 'description': 'The location to fetch the weather.'}}
|
| 15 |
+
output_type = "string"
|
| 16 |
+
|
| 17 |
+
def get_current_weather_on_location(self, location: str) -> str:
|
| 18 |
"""
|
| 19 |
+
Fetches the current weather for a given location.
|
| 20 |
+
Args:
|
| 21 |
+
location: The location to fetch the weather.
|
|
|
|
|
|
|
| 22 |
"""
|
| 23 |
+
|
| 24 |
base_url = "https://api.open-meteo.com/v1/forecast"
|
| 25 |
|
| 26 |
key = os.getenv('GOOGLE_MAPS_API')
|
|
|
|
| 100 |
|
| 101 |
description = weather_descriptions.get(current_weather_code, "Condizione meteo sconosciuta")
|
| 102 |
return description
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
|
| 107 |
|
tools/web_search.py
CHANGED
|
@@ -20,6 +20,13 @@ class DuckDuckGoSearchTool(Tool):
|
|
| 20 |
self.ddgs = DDGS(**kwargs)
|
| 21 |
|
| 22 |
def forward(self, query: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
results = self.ddgs.text(query, max_results=self.max_results)
|
| 24 |
if len(results) == 0:
|
| 25 |
raise Exception("No results found! Try a less restrictive/shorter query.")
|
|
|
|
| 20 |
self.ddgs = DDGS(**kwargs)
|
| 21 |
|
| 22 |
def forward(self, query: str) -> str:
|
| 23 |
+
"""
|
| 24 |
+
Performs a DuckDuckGo web search.
|
| 25 |
+
Args:
|
| 26 |
+
query: The search query to perform.
|
| 27 |
+
Returns:
|
| 28 |
+
A formatted string with the top search results.
|
| 29 |
+
"""
|
| 30 |
results = self.ddgs.text(query, max_results=self.max_results)
|
| 31 |
if len(results) == 0:
|
| 32 |
raise Exception("No results found! Try a less restrictive/shorter query.")
|