Davit6174 commited on
Commit
3aeb007
·
verified ·
1 Parent(s): dbcf0db

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +15 -1
tools.py CHANGED
@@ -1,5 +1,6 @@
1
  from langchain.tools import tool
2
  from langchain_community.tools.ddg_search import DuckDuckGoSearchRun
 
3
 
4
  search = DuckDuckGoSearchRun()
5
 
@@ -8,4 +9,17 @@ def web_search(query: str) -> str:
8
  """Perform a web search using DuckDuckGo."""
9
  return search.run(query)
10
 
11
- tools = [web_search]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from langchain.tools import tool
2
  from langchain_community.tools.ddg_search import DuckDuckGoSearchRun
3
+ import wikipedia
4
 
5
  search = DuckDuckGoSearchRun()
6
 
 
9
  """Perform a web search using DuckDuckGo."""
10
  return search.run(query)
11
 
12
+ @tool
13
+ def wiki_search(query: str) -> str:
14
+ """Search Wikipedia and return a summary of the most relevant result."""
15
+ try:
16
+ page = wikipedia.page(query)
17
+ return page.summary
18
+ except wikipedia.DisambiguationError as e:
19
+ return f"Disambiguation: {', '.join(e.options[:5])}"
20
+ except wikipedia.PageError:
21
+ return "Page not found."
22
+ except Exception as e:
23
+ return f"Error: {e}"
24
+
25
+ tools = [web_search, wiki_search]