mchinea commited on
Commit
fe5f523
·
1 Parent(s): 86b31ff

update tools

Browse files
Files changed (2) hide show
  1. agent.py +22 -6
  2. tools.py +25 -2
agent.py CHANGED
@@ -68,13 +68,13 @@ class MyGAIAAgent:
68
  messages = [HumanMessage(content=question)]
69
  messages = self.graph.invoke({"messages": messages})
70
  answer = messages['messages'][-1].content
71
-
72
  '''
73
  user_input = {"messages": [("user", question)]}
74
  answer1 = self.graph.invoke(user_input)["messages"][-1].content
75
- print (answer1)
76
  '''
77
- return answer
 
78
 
79
  def _clean_answer(self, answer: any) -> str:
80
  """
@@ -139,7 +139,23 @@ class MyGAIAAgent:
139
  # test
140
  if __name__ == "__main__":
141
  question1 = "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)?"
142
- question2 = "Convert 10 miles to kilometers."
143
- question3 = "Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec. What does Teal'c say in response to the question ""Isn't that hot?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  agent = MyGAIAAgent()
145
- print(agent(question1))
 
68
  messages = [HumanMessage(content=question)]
69
  messages = self.graph.invoke({"messages": messages})
70
  answer = messages['messages'][-1].content
 
71
  '''
72
  user_input = {"messages": [("user", question)]}
73
  answer1 = self.graph.invoke(user_input)["messages"][-1].content
74
+ print (answer)
75
  '''
76
+ #print (self._clean_answer(answer))
77
+ return self._clean_answer(answer)
78
 
79
  def _clean_answer(self, answer: any) -> str:
80
  """
 
139
  # test
140
  if __name__ == "__main__":
141
  question1 = "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)?"
142
+ question2 = "In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?"
143
+ question5 = "Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?"
144
+ question6 = "Given this table defining * on the set S = {a, b, c, d, e} |*|a|b|c|d|e| |---|---|---|---|---|---||a|a|b|c|b|d||b|b|c|a|e|c||c|c|a|b|b|a||d|b|e|b|e|d||e|d|b|a|d|c| provide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order."
145
+ question7 = "Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec. What does Teal'c say in response to the question ""Isn't that hot?"
146
+ question8 = "What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?"
147
+ question9 = "I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far: milk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts I need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list."
148
+ question10 = "Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name."
149
+ question12 = "How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?"
150
+ question14 = "On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?"
151
+ question15 = "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations."
152
+ question16 = "What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer."
153
+ question17 = "Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters."
154
+ question18 = "What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?"
155
+ '''
156
+
157
+ question4 = "How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?"
158
+ question6 = "What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?"
159
+ '''
160
  agent = MyGAIAAgent()
161
+ print(agent(question18))
tools.py CHANGED
@@ -13,9 +13,11 @@ from langchain_core.tools import tool
13
 
14
  from langchain_core.messages import ToolMessage
15
  from langchain_tavily import TavilySearch
 
16
  from langchain_community.document_loaders import WikipediaLoader
17
  from langchain_community.document_loaders import ArxivLoader
18
 
 
19
  @tool
20
  def web_search(query: str) -> ToolMessage:
21
  """Search in the web with Tavily for a query and return maximum 5 results.
@@ -26,16 +28,36 @@ def web_search(query: str) -> ToolMessage:
26
  """
27
  return TavilySearch(max_results=5, include_images=False).invoke({"query": query})
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  @tool
31
  def wikipedia_search(query: str) -> Dict[str, list]:
32
- """Search Wikipedia for a given query and return the first 5 results.
33
  Args:
34
  query: The search term or topic.
35
  Returns:
36
  A dictionary containing the formatted Wikipedia results.
37
  """
38
- search_docs = WikipediaLoader(query=query, load_max_docs=5).load()
39
  formatted_search_docs = "\n\n---\n\n".join(
40
  [
41
  f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
@@ -350,6 +372,7 @@ level1_tools = [
350
  modulus,
351
  wikipedia_search,
352
  web_search,
 
353
  arvix_search,
354
  convert_units,
355
  query_table_data,
 
13
 
14
  from langchain_core.messages import ToolMessage
15
  from langchain_tavily import TavilySearch
16
+ from langchain_community.utilities import GoogleSerperAPIWrapper
17
  from langchain_community.document_loaders import WikipediaLoader
18
  from langchain_community.document_loaders import ArxivLoader
19
 
20
+
21
  @tool
22
  def web_search(query: str) -> ToolMessage:
23
  """Search in the web with Tavily for a query and return maximum 5 results.
 
28
  """
29
  return TavilySearch(max_results=5, include_images=False).invoke({"query": query})
30
 
31
+ @tool
32
+ def search_tool(query: str) -> str:
33
+ """Search in Google and returns an string with title, link, and snippet for the top 10 results.
34
+ Args:
35
+ query: str
36
+ Returns:
37
+ Title, link, and snippet for the top 10 results
38
+ """
39
+ searcher = GoogleSerperAPIWrapper(k=10)
40
+ retries = 3
41
+ result = ""
42
+ while retries > 0:
43
+ try:
44
+ search_results = searcher.results(query)["organic"]
45
+ for row in search_results:
46
+ result += f"Title: {row['title']}\nSnippet: {row['snippet']}\nURL: {row['link']}\n\n"
47
+ return result
48
+ except Exception as e:
49
+ retries -= 1
50
+ return f"There was an error with Google search: {e}"
51
 
52
  @tool
53
  def wikipedia_search(query: str) -> Dict[str, list]:
54
+ """Search Wikipedia for a given query and return the first 10 results.
55
  Args:
56
  query: The search term or topic.
57
  Returns:
58
  A dictionary containing the formatted Wikipedia results.
59
  """
60
+ search_docs = WikipediaLoader(query=query, load_max_docs=10).load()
61
  formatted_search_docs = "\n\n---\n\n".join(
62
  [
63
  f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
 
372
  modulus,
373
  wikipedia_search,
374
  web_search,
375
+ search_tool,
376
  arvix_search,
377
  convert_units,
378
  query_table_data,