samoye16 commited on
Commit
c6e5dee
·
verified ·
1 Parent(s): c72c658

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +40 -30
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
- """Returns up to 2 documents related to a query from Wikipedia."""
55
- docs = WikipediaLoader(query=query, load_max_docs=2).load()
56
- return {"wiki_results": "\n\n---\n\n".join(
57
- f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}'
58
- for doc in docs
59
- )}
 
 
 
 
 
60
 
61
  @tool
62
  def search_web(query: str) -> str:
63
- """Fetches up to 3 web results using Tavily."""
64
- results = TavilySearchResults(max_results=3).invoke(query=query)
65
- return {"web_results": "\n\n---\n\n".join(
66
- f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}'
67
- for doc in results
68
- )}
 
 
 
 
 
69
 
70
  @tool
71
  def search_arxiv(query: str) -> str:
72
- """Retrieves up to 3 papers related to the query from ArXiv."""
73
- results = ArxivLoader(query=query, load_max_docs=3).load()
74
- return {"arvix_results": "\n\n---\n\n".join(
75
- f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}'
76
- for doc in results
77
- )}
78
-
79
-
80
- system_message = SystemMessage(content="""You are a helpful assistant tasked with answering questions using a set of tools. Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
81
-
82
- FINAL ANSWER: [YOUR FINAL ANSWER]
83
-
84
- YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma-separated list of numbers and/or strings.
85
- - If you are asked for a number, don't use a comma in the number and avoid units like $ or % unless specified otherwise.
86
- - If you are asked for a string, avoid using articles and abbreviations (e.g. for cities), and write digits in plain text unless specified otherwise.
87
- - If you are asked for a comma-separated list, apply the above rules depending on whether each item is a number or string.
88
-
89
- Your answer should start only with "FINAL ANSWER: ", followed by your result.""")
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,