update tools.py
Browse files
tools.py
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
from langchain_community.tools import WikipediaQueryRun, ArxivQueryRun
|
| 4 |
+
from langchain_community.utilities import WikipediaAPIWrapper,ArxivAPIWrapper
|
| 5 |
+
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 6 |
+
from langchain_core.tools import tool
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
|
| 9 |
+
def wikipedia_tool() -> WikipediaQueryRun:
|
| 10 |
+
"""best search for biography, facts and history"""
|
| 11 |
+
return WikipediaQueryRun(
|
| 12 |
+
api_wrapper=WikipediaAPIWrapper(doc_content_chars_max= 4000)
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
def tavily_tool() -> TavilySearchResults:
|
| 16 |
+
"""web search for recents events and facts"""
|
| 17 |
+
return TavilySearchResults(max_results=5)
|
| 18 |
+
|
| 19 |
+
def arxiv_tool() -> ArxivQueryRun:
|
| 20 |
+
"""returns scientific and research papers"""
|
| 21 |
+
return ArxivQueryRun(
|
| 22 |
+
api_wrapper=ArxivAPIWrapper(top_k_results= 3, doc_content_chars_max = 4000)
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
@tool
|
| 26 |
+
def get_current_year() -> str:
|
| 27 |
+
"""returns the current year"""
|
| 28 |
+
return str(datetime.now().year)
|