Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -1,7 +1,30 @@
|
|
| 1 |
from langchain_community.retrievers import BM25Retriever
|
| 2 |
from langchain.tools import Tool
|
| 3 |
from langchain_community.tools import DuckDuckGoSearchRun
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
search_tool = DuckDuckGoSearchRun()
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain_community.retrievers import BM25Retriever
|
| 2 |
from langchain.tools import Tool
|
| 3 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 4 |
+
langchain_community.document_loaders.wikipedia.WikipediaLoader
|
| 5 |
|
| 6 |
|
| 7 |
search_tool = DuckDuckGoSearchRun()
|
| 8 |
|
| 9 |
+
def wiki_loader(query: str, lang: str='en', load_max_docs: int=2):
|
| 10 |
+
"""
|
| 11 |
+
Fetches content from Wikipedia based on a given query.
|
| 12 |
+
|
| 13 |
+
Parameters:
|
| 14 |
+
- query (str): The search query for Wikipedia.
|
| 15 |
+
- lang (str): The language of the Wikipedia to search in. Default is 'en'.
|
| 16 |
+
- load_max_docs (int): The maximum number of documents to load. Default is 2.
|
| 17 |
+
|
| 18 |
+
Returns:
|
| 19 |
+
- list: A list of documents containing the fetched Wikipedia content.
|
| 20 |
+
"""
|
| 21 |
+
try:
|
| 22 |
+
# Initialize the WikipediaLoader with the given query, language, and max documents
|
| 23 |
+
loader = WikipediaLoader(query=query, lang=lang, load_max_docs=load_max_docs)
|
| 24 |
+
# Load the documents
|
| 25 |
+
documents = loader.load()
|
| 26 |
+
print(documents)
|
| 27 |
+
return documents
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"An error occurred: {e}")
|
| 30 |
+
return []
|