Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,21 +9,33 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
| 9 |
|
| 10 |
# --- Tools ---
|
| 11 |
class WebSearchTool(Tool):
|
| 12 |
-
"""Search the web using DuckDuckGo"""
|
| 13 |
name = "web_search"
|
| 14 |
description = "Search the web and return concise results. Input: search query string."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
def forward(self, query: str):
|
| 17 |
from smolagents import DuckDuckGoSearchTool
|
| 18 |
tool = DuckDuckGoSearchTool()
|
| 19 |
return tool.forward(query)
|
| 20 |
|
| 21 |
class WikipediaTool(Tool):
|
| 22 |
-
"""Fetch summaries from Wikipedia"""
|
| 23 |
name = "wikipedia_search"
|
| 24 |
description = "Fetch Wikipedia summary for a topic. Input: topic string."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
def forward(self, topic: str):
|
| 27 |
try:
|
| 28 |
summary = wikipedia.summary(topic, sentences=3)
|
| 29 |
return summary
|
|
@@ -31,11 +43,17 @@ class WikipediaTool(Tool):
|
|
| 31 |
return f"Wikipedia lookup failed: {e}"
|
| 32 |
|
| 33 |
class WeatherTool(Tool):
|
| 34 |
-
"""Get weather using Open-Meteo API"""
|
| 35 |
name = "weather"
|
| 36 |
-
description = "Get current weather. Input: city name."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
def forward(self, city: str):
|
| 39 |
try:
|
| 40 |
# Geocoding to get coordinates
|
| 41 |
geocode_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}"
|
|
|
|
| 9 |
|
| 10 |
# --- Tools ---
|
| 11 |
class WebSearchTool(Tool):
|
|
|
|
| 12 |
name = "web_search"
|
| 13 |
description = "Search the web and return concise results. Input: search query string."
|
| 14 |
+
inputs = {
|
| 15 |
+
"query": {
|
| 16 |
+
"type": "string",
|
| 17 |
+
"description": "The search query to look up on the web"
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
output_type = "string"
|
| 21 |
|
| 22 |
+
def forward(self, query: str) -> str:
|
| 23 |
from smolagents import DuckDuckGoSearchTool
|
| 24 |
tool = DuckDuckGoSearchTool()
|
| 25 |
return tool.forward(query)
|
| 26 |
|
| 27 |
class WikipediaTool(Tool):
|
|
|
|
| 28 |
name = "wikipedia_search"
|
| 29 |
description = "Fetch Wikipedia summary for a topic. Input: topic string."
|
| 30 |
+
inputs = {
|
| 31 |
+
"topic": {
|
| 32 |
+
"type": "string",
|
| 33 |
+
"description": "The topic to search for on Wikipedia"
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
output_type = "string"
|
| 37 |
|
| 38 |
+
def forward(self, topic: str) -> str:
|
| 39 |
try:
|
| 40 |
summary = wikipedia.summary(topic, sentences=3)
|
| 41 |
return summary
|
|
|
|
| 43 |
return f"Wikipedia lookup failed: {e}"
|
| 44 |
|
| 45 |
class WeatherTool(Tool):
|
|
|
|
| 46 |
name = "weather"
|
| 47 |
+
description = "Get current weather for a city. Input: city name."
|
| 48 |
+
inputs = {
|
| 49 |
+
"city": {
|
| 50 |
+
"type": "string",
|
| 51 |
+
"description": "The name of the city to get weather for"
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
output_type = "string"
|
| 55 |
|
| 56 |
+
def forward(self, city: str) -> str:
|
| 57 |
try:
|
| 58 |
# Geocoding to get coordinates
|
| 59 |
geocode_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}"
|