Spaces:
Sleeping
Sleeping
Update agents.py
Browse files
agents.py
CHANGED
@@ -51,42 +51,52 @@ def modulus(a: int, b: int) -> int:
|
|
51 |
# ---- Search Tools ---- #
|
52 |
@tool
|
53 |
def search_wikipedia(query: str) -> str:
|
54 |
-
"""
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
@tool
|
62 |
def search_web(query: str) -> str:
|
63 |
-
"""
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
@tool
|
71 |
def search_arxiv(query: str) -> str:
|
72 |
-
"""
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
Your answer should start
|
90 |
|
91 |
toolset = [
|
92 |
multiply,
|
|
|
51 |
# ---- Search Tools ---- #
|
52 |
@tool
|
53 |
def search_wikipedia(query: str) -> str:
|
54 |
+
"""Search Wikipedia for a query and return maximum 2 results.
|
55 |
+
|
56 |
+
Args:
|
57 |
+
query: The search query."""
|
58 |
+
search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
|
59 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
60 |
+
[
|
61 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
62 |
+
for doc in search_docs
|
63 |
+
])
|
64 |
+
return {"wiki_results": formatted_search_docs}
|
65 |
|
66 |
@tool
|
67 |
def search_web(query: str) -> str:
|
68 |
+
"""Search Tavily for a query and return maximum 3 results.
|
69 |
+
|
70 |
+
Args:
|
71 |
+
query: The search query."""
|
72 |
+
search_docs = TavilySearchResults(max_results=3).invoke(query=query)
|
73 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
74 |
+
[
|
75 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
76 |
+
for doc in search_docs
|
77 |
+
])
|
78 |
+
return {"web_results": formatted_search_docs}
|
79 |
|
80 |
@tool
|
81 |
def search_arxiv(query: str) -> str:
|
82 |
+
"""Search Arxiv for a query and return maximum 3 result.
|
83 |
+
|
84 |
+
Args:
|
85 |
+
query: The search query."""
|
86 |
+
search_docs = ArxivLoader(query=query, load_max_docs=3).load()
|
87 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
88 |
+
[
|
89 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
|
90 |
+
for doc in search_docs
|
91 |
+
])
|
92 |
+
return {"arvix_results": formatted_search_docs}
|
93 |
+
|
94 |
+
|
95 |
+
system_message = SystemMessage(content="""You are a helpful assistant tasked with answering questions using a set of tools.
|
96 |
+
Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
97 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
98 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
99 |
+
Your answer should only start with "FINAL ANSWER: ", then follows with the answer. """)
|
100 |
|
101 |
toolset = [
|
102 |
multiply,
|