added arxiv tool
Browse files- agent.py +17 -9
- requirements.txt +3 -1
agent.py
CHANGED
|
@@ -1,13 +1,6 @@
|
|
| 1 |
-
'''
|
| 2 |
-
TODO tools
|
| 3 |
-
|
| 4 |
-
Facultative
|
| 5 |
-
- wiki_search
|
| 6 |
-
- arxiv_search
|
| 7 |
-
'''
|
| 8 |
import os
|
| 9 |
from smolagents import CodeAgent, tool, DuckDuckGoSearchTool, OpenAIServerModel, VisitWebpageTool, Tool
|
| 10 |
-
from langchain_community.document_loaders import WikipediaLoader
|
| 11 |
|
| 12 |
@tool
|
| 13 |
def add(a:int, b:int) -> int:
|
|
@@ -102,6 +95,21 @@ def wiki_search(query: str) -> str:
|
|
| 102 |
return {"wiki_results": formatted_search_docs}
|
| 103 |
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
def get_agent() -> CodeAgent:
|
| 106 |
search_tool = DuckDuckGoSearchTool()
|
| 107 |
web_page_tool = VisitWebpageTool()
|
|
@@ -113,4 +121,4 @@ def get_agent() -> CodeAgent:
|
|
| 113 |
api_base="https://codestral.mistral.ai/v1/",
|
| 114 |
api_key=api_key)
|
| 115 |
|
| 116 |
-
return CodeAgent(tools=[add, subtract, multiply, divide, modulus, rounder, search_tool, web_page_tool, wiki_search], model=model)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
from smolagents import CodeAgent, tool, DuckDuckGoSearchTool, OpenAIServerModel, VisitWebpageTool, Tool
|
| 3 |
+
from langchain_community.document_loaders import WikipediaLoader, ArxivLoader
|
| 4 |
|
| 5 |
@tool
|
| 6 |
def add(a:int, b:int) -> int:
|
|
|
|
| 95 |
return {"wiki_results": formatted_search_docs}
|
| 96 |
|
| 97 |
|
| 98 |
+
@tool
|
| 99 |
+
def arvix_search(query: str) -> str:
|
| 100 |
+
"""Search Arxiv for a query and return maximum 3 result.
|
| 101 |
+
|
| 102 |
+
Args:
|
| 103 |
+
query: The search query."""
|
| 104 |
+
search_docs = ArxivLoader(query=query, load_max_docs=3).load()
|
| 105 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
| 106 |
+
[
|
| 107 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
|
| 108 |
+
for doc in search_docs
|
| 109 |
+
])
|
| 110 |
+
return {"arvix_results": formatted_search_docs}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
def get_agent() -> CodeAgent:
|
| 114 |
search_tool = DuckDuckGoSearchTool()
|
| 115 |
web_page_tool = VisitWebpageTool()
|
|
|
|
| 121 |
api_base="https://codestral.mistral.ai/v1/",
|
| 122 |
api_key=api_key)
|
| 123 |
|
| 124 |
+
return CodeAgent(tools=[add, subtract, multiply, divide, modulus, rounder, search_tool, web_page_tool, wiki_search, arvix_search], model=model)
|
requirements.txt
CHANGED
|
@@ -5,4 +5,6 @@ langchain_community
|
|
| 5 |
wikipedia
|
| 6 |
duckduckgo_search
|
| 7 |
requests
|
| 8 |
-
markdownify
|
|
|
|
|
|
|
|
|
| 5 |
wikipedia
|
| 6 |
duckduckgo_search
|
| 7 |
requests
|
| 8 |
+
markdownify
|
| 9 |
+
arxiv
|
| 10 |
+
pymupdf
|