Spaces:
Sleeping
Sleeping
File size: 679 Bytes
e42df9e e427836 fb58427 e427836 593012b e427836 ba3b3ff e427836 ba3b3ff fb58427 e427836 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from smolagents import Tool
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
class WikipediaSearcher(Tool):
name = "wikipedia_search"
description = "Search Wikipedia for factual answers to questions."
def run(self, input_data: dict) -> str:
query = input_data.get("query", "")
if not query:
return "No query provided for Wikipedia search."
try:
wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
return wikipedia.run(query)
except Exception as e:
return f"Error retrieving Wikipedia data: {e}"
|