File size: 1,150 Bytes
dddc250
98954d2
3aeb007
98954d2
dddc250
98954d2
dddc250
 
9531108
8a1137d
9531108
 
 
 
 
dddc250
 
795b59a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3aeb007
795b59a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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]