Spaces:
Sleeping
Sleeping
Delete wikipedia_searcher.py
Browse files- wikipedia_searcher.py +0 -33
wikipedia_searcher.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
from smolagents import Tool
|
| 2 |
-
from langchain_community.tools import WikipediaQueryRun
|
| 3 |
-
from langchain_community.utilities import WikipediaAPIWrapper
|
| 4 |
-
|
| 5 |
-
class WikipediaSearcher(Tool):
|
| 6 |
-
name = "wikipedia_search"
|
| 7 |
-
description = "Search Wikipedia and return a summary for a given query."
|
| 8 |
-
inputs = {
|
| 9 |
-
"query": {
|
| 10 |
-
"type": "string",
|
| 11 |
-
"description": "Search term for Wikipedia"
|
| 12 |
-
}
|
| 13 |
-
}
|
| 14 |
-
output_type = "string"
|
| 15 |
-
|
| 16 |
-
def __init__(self):
|
| 17 |
-
super().__init__()
|
| 18 |
-
self.wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
|
| 19 |
-
|
| 20 |
-
def forward(self, query: str) -> str:
|
| 21 |
-
try:
|
| 22 |
-
result = self.wikipedia.run(query)
|
| 23 |
-
# Optionally truncate long summaries for better display
|
| 24 |
-
if len(result) > 1000:
|
| 25 |
-
result = result[:1000] + "..."
|
| 26 |
-
return result.strip()
|
| 27 |
-
except Exception as e:
|
| 28 |
-
return f"Error retrieving Wikipedia data: {e}"
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|