dlaima commited on
Commit
4fdeb60
·
verified ·
1 Parent(s): 5dd645a

Update wikipedia_searcher.py

Browse files
Files changed (1) hide show
  1. wikipedia_searcher.py +15 -17
wikipedia_searcher.py CHANGED
@@ -1,24 +1,23 @@
 
1
  from langchain_community.tools import WikipediaQueryRun
2
  from langchain_community.utilities import WikipediaAPIWrapper
3
 
4
- class WikipediaSearcher:
5
- """
6
- A simple wrapper class to query Wikipedia and retrieve summaries using LangChain's Wikipedia utilities.
7
- """
8
-
9
- def __init__(self) -> None:
10
- # Initialize the Wikipedia query runner with the API wrapper
 
 
 
 
 
 
11
  self.wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
12
 
13
- def search(self, query: str) -> str:
14
- """
15
- Search Wikipedia for a given query and return a summary or snippet.
16
-
17
- Args:
18
- query (str): The search query string.
19
- Returns:
20
- str: The Wikipedia summary or an error message.
21
- """
22
  try:
23
  return self.wikipedia.run(query)
24
  except Exception as e:
@@ -28,4 +27,3 @@ class WikipediaSearcher:
28
 
29
 
30
 
31
-
 
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
  return self.wikipedia.run(query)
23
  except Exception as e:
 
27
 
28
 
29