Antoine101's picture
Update tools.py
526ce64 verified
raw
history blame
1.09 kB
from langchain_community.retrievers import BM25Retriever
from langchain.tools import Tool
from langchain_community.tools import DuckDuckGoSearchRun
langchain_community.document_loaders.wikipedia.WikipediaLoader
search_tool = DuckDuckGoSearchRun()
def wiki_loader(query: str, lang: str='en', load_max_docs: int=2):
"""
Fetches content from Wikipedia based on a given query.
Parameters:
- query (str): The search query for Wikipedia.
- lang (str): The language of the Wikipedia to search in. Default is 'en'.
- load_max_docs (int): The maximum number of documents to load. Default is 2.
Returns:
- list: A list of documents containing the fetched Wikipedia content.
"""
try:
# Initialize the WikipediaLoader with the given query, language, and max documents
loader = WikipediaLoader(query=query, lang=lang, load_max_docs=load_max_docs)
# Load the documents
documents = loader.load()
print(documents)
return documents
except Exception as e:
print(f"An error occurred: {e}")
return []