Spaces:
Sleeping
Sleeping
Update wikipedia_searcher.py
Browse files- wikipedia_searcher.py +7 -1
wikipedia_searcher.py
CHANGED
|
@@ -3,10 +3,16 @@ from langchain_community.utilities import WikipediaAPIWrapper
|
|
| 3 |
|
| 4 |
class WikipediaSearcher:
|
| 5 |
def __init__(self):
|
|
|
|
| 6 |
self.wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
|
| 7 |
|
| 8 |
def search(self, query: str) -> str:
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
|
|
|
|
| 3 |
|
| 4 |
class WikipediaSearcher:
|
| 5 |
def __init__(self):
|
| 6 |
+
# WikipediaAPIWrapper handles the direct Wikipedia API calls
|
| 7 |
self.wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
|
| 8 |
|
| 9 |
def search(self, query: str) -> str:
|
| 10 |
+
# Returns a concise summary or article snippet for the query
|
| 11 |
+
try:
|
| 12 |
+
result = self.wikipedia.run(query)
|
| 13 |
+
return result
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error retrieving Wikipedia data: {e}"
|
| 16 |
|
| 17 |
|
| 18 |
|