Spaces:
Sleeping
Sleeping
Create wikipedia_tool.py
Browse files- wikipedia_tool.py +23 -0
wikipedia_tool.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_community.document_loaders import WikipediaLoader
|
| 2 |
+
from smolagents import Tool
|
| 3 |
+
|
| 4 |
+
class WikipediaTool(Tool):
|
| 5 |
+
name = "WikipediaTool"
|
| 6 |
+
description = "This tool fetches documents from Wikipedia"
|
| 7 |
+
|
| 8 |
+
inputs = {
|
| 9 |
+
"query": {
|
| 10 |
+
"type": "string",
|
| 11 |
+
"description": "the query to search in Wikipedia",
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
output_type = "string"
|
| 16 |
+
|
| 17 |
+
def forward(self, query: str) -> str:
|
| 18 |
+
"""
|
| 19 |
+
Fetch documents from Wikipedia
|
| 20 |
+
https://python.langchain.com/docs/integrations/document_loaders/wikipedia/
|
| 21 |
+
"""
|
| 22 |
+
documents = WikipediaLoader(query=query, load_max_docs=1).load()
|
| 23 |
+
return documents[0].page_content
|