Spaces:
Sleeping
Sleeping
Update tools/WikipediaTool.py
Browse files- tools/WikipediaTool.py +9 -11
tools/WikipediaTool.py
CHANGED
|
@@ -1,18 +1,16 @@
|
|
| 1 |
from smolagents import Tool
|
| 2 |
import wikipedia
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
description = "Fetches the text content of a Wikipedia page given a topic."
|
| 7 |
inputs = {
|
| 8 |
-
"
|
| 9 |
}
|
| 10 |
output_type = "string"
|
| 11 |
|
| 12 |
-
def forward(self,
|
| 13 |
try:
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return f"Error fetching Wikipedia page: {e}"
|
|
|
|
| 1 |
from smolagents import Tool
|
| 2 |
import wikipedia
|
| 3 |
+
class LocalWikipediaTool(Tool):
|
| 4 |
+
name = "wikipedia_search"
|
| 5 |
+
description = "Search Wikipedia and return a summary."
|
|
|
|
| 6 |
inputs = {
|
| 7 |
+
"query": {"type": "string", "description": "Search term"}
|
| 8 |
}
|
| 9 |
output_type = "string"
|
| 10 |
|
| 11 |
+
def forward(self, query: str) -> str:
|
| 12 |
try:
|
| 13 |
+
page = wikipedia.page(query)
|
| 14 |
+
return page.content # full article text
|
| 15 |
+
except Exception:
|
| 16 |
+
return ""
|
|
|