Davit6174's picture
removed wiki search
795b59a verified
from langchain.tools import tool
from langchain_community.tools.ddg_search import DuckDuckGoSearchRun
import wikipedia
search = DuckDuckGoSearchRun()
@tool
def web_search(query: str) -> str:
"""
Performs a web search using DuckDuckGo and returns relevant results.
Args:
query (str): The search query.
Returns:
str: A relevant result or summary of results from the web.
"""
return search.run(query)
# @tool
# def wiki_search(query: str) -> str:
# """
# Looks up a topic on English Wikipedia and returns a summary.
# Args:
# query (str): The search query.
# Returns:
# str: A concise summary of the topic from English Wikipedia.
# """
# try:
# page = wikipedia.page(query)
# print(f"query: {query}, summary: {page.summary}")
# return page.summary
# except wikipedia.DisambiguationError as e:
# return f"Disambiguation: {', '.join(e.options[:5])}"
# except wikipedia.PageError:
# return "Page not found."
# except Exception as e:
# return f"Error: {e}"
tools = [web_search]