jesusgj commited on
Commit
f92d478
·
1 Parent(s): e812f22

Modified files

Browse files
Files changed (1) hide show
  1. agent.py +5 -13
agent.py CHANGED
@@ -1,14 +1,12 @@
1
-
2
-
3
  import os
4
  import re
5
  import requests
 
6
  from smolagents import CodeAgent, ToolCallingAgent, WebSearchTool, tool
7
  from smolagents import InferenceClientModel
8
  from dotenv import load_dotenv
9
  from markdownify import markdownify
10
  from requests.exceptions import RequestException
11
- from serpapi import GoogleSearch
12
 
13
  def initialize_agent():
14
  # Load environment variables from .env file
@@ -63,12 +61,8 @@ def initialize_agent():
63
  The search results, or an error message if the search fails.
64
  """
65
  try:
66
- params = {
67
- "q": query,
68
- "api_key": os.environ.get("SERPAPI_API_KEY"),
69
- }
70
- search = GoogleSearch(params)
71
- results = search.get_dict()
72
  if "ai_overview" in results:
73
  ai_overview = results["ai_overview"]
74
  output = ""
@@ -108,10 +102,8 @@ def initialize_agent():
108
  model=model,
109
  managed_agents=[web_agent],
110
  additional_authorized_imports=["time", "numpy", "pandas"],
111
- instructions="""You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. 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."""
112
  )
113
  return manager_agent
114
  else:
115
- return None
116
-
117
-
 
 
 
1
  import os
2
  import re
3
  import requests
4
+ import serpapi
5
  from smolagents import CodeAgent, ToolCallingAgent, WebSearchTool, tool
6
  from smolagents import InferenceClientModel
7
  from dotenv import load_dotenv
8
  from markdownify import markdownify
9
  from requests.exceptions import RequestException
 
10
 
11
  def initialize_agent():
12
  # Load environment variables from .env file
 
61
  The search results, or an error message if the search fails.
62
  """
63
  try:
64
+ client = serpapi.Client(api_key=os.environ.get("SERPAPI_API_KEY"))
65
+ results = client.search(q=query, engine="google")
 
 
 
 
66
  if "ai_overview" in results:
67
  ai_overview = results["ai_overview"]
68
  output = ""
 
102
  model=model,
103
  managed_agents=[web_agent],
104
  additional_authorized_imports=["time", "numpy", "pandas"],
105
+ instructions='''You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the a new line and the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. 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.'''
106
  )
107
  return manager_agent
108
  else:
109
+ return None