File size: 773 Bytes
4fdeb60
e27578f
fb58427
 
4fdeb60
 
 
 
 
 
 
 
 
 
 
 
 
e27578f
 
4fdeb60
ba3b3ff
e27578f
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
26
27
28
29
30
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 and return a summary for a given query."
    inputs = {
        "query": {
            "type": "string",
            "description": "Search term for Wikipedia"
        }
    }
    output_type = "string"

    def __init__(self):
        super().__init__()
        self.wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())

    def forward(self, query: str) -> str:
        try:
            return self.wikipedia.run(query)
        except Exception as e:
            return f"Error retrieving Wikipedia data: {e}"