SergeyO7 commited on
Commit
b748682
·
verified ·
1 Parent(s): b518461

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +29 -29
agent.py CHANGED
@@ -17,32 +17,32 @@ import shutil
17
  import traceback
18
 
19
 
20
- @tool
21
- def GoogleSearchTool(query: str) -> str:
22
- """Tool for performing Google searches using Custom Search JSON API
23
- Args:
24
- query (str): Search query string
25
- Returns:
26
- str: Formatted search results
27
- """
28
- api_key = os.environ.get("GOOGLE_API_KEY")
29
- cse_id = os.environ.get("GOOGLE_CSE_ID")
30
- if not api_key or not cse_id:
31
- raise ValueError("GOOGLE_API_KEY and GOOGLE_CSE_ID must be set in environment variables.")
32
- url = "https://www.googleapis.com/customsearch/v1"
33
- params = {
34
- "key": api_key,
35
- "cx": cse_id,
36
- "q": query,
37
- "num": 5 # Number of results to return
38
- }
39
- try:
40
- response = requests.get(url, params=params)
41
- response.raise_for_status()
42
- results = response.json().get("items", [])
43
- return "\n".join([f"{item['title']}: {item['link']}" for item in results]) or "No results found."
44
- except Exception as e:
45
- return f"Error performing Google search: {str(e)}"
46
 
47
 
48
  from langchain_community.document_loaders import ArxivLoader
@@ -297,13 +297,13 @@ class MagAgent:
297
  search_arxiv,
298
  # PNG2FENTool,
299
  # ChessEngineTool(),
300
- GoogleSearchTool,
301
  # ImageAnalysisTool,
302
  ],
303
  verbosity_level=2,
304
  # prompt_templates=prompt_templates,
305
  add_base_tools=False,
306
- max_steps=15
307
  )
308
  print("MagAgent initialized.")
309
 
@@ -330,7 +330,7 @@ class MagAgent:
330
  " - Provide answers that are concise, accurate, and properly punctuated according to standard English grammar.\n"
331
  " - Use quotation marks for direct quotes (e.g., \"Extreamly.\") and appropriate punctuation for lists, sentences, or clarifications.\n"
332
  " - If the question asks for a specific quote or response (e.g., what a character says), format the answer clearly, e.g., 'Character says, \"Exact quote.\"'\n\n"
333
- " -If asked about name of place or city, use full complete name without abbreviations (e.g. use Saint Petersburg instead of St.Petersburg). \n"
334
  "4. **Error Handling**:\n"
335
  " - If you cannot retrieve or process data (e.g., due to blocked requests), return a clear error message: \"Unable to retrieve data. Please refine the question or check external sources.\"\n\n"
336
  f"Answer the following question: {question} \n"
 
17
  import traceback
18
 
19
 
20
+ #@tool
21
+ #def GoogleSearchTool(query: str) -> str:
22
+ # """Tool for performing Google searches using Custom Search JSON API
23
+ # Args:
24
+ # query (str): Search query string
25
+ # Returns:
26
+ # str: Formatted search results
27
+ # """
28
+ # api_key = os.environ.get("GOOGLE_API_KEY")
29
+ # cse_id = os.environ.get("GOOGLE_CSE_ID")
30
+ # if not api_key or not cse_id:
31
+ # raise ValueError("GOOGLE_API_KEY and GOOGLE_CSE_ID must be set in environment variables.")
32
+ # url = "https://www.googleapis.com/customsearch/v1"
33
+ # params = {
34
+ # "key": api_key,
35
+ # "cx": cse_id,
36
+ # "q": query,
37
+ # "num": 5 # Number of results to return
38
+ # }
39
+ # try:
40
+ # response = requests.get(url, params=params)
41
+ # response.raise_for_status()
42
+ # results = response.json().get("items", [])
43
+ # return "\n".join([f"{item['title']}: {item['link']}" for item in results]) or "No results found."
44
+ # except Exception as e:
45
+ # return f"Error performing Google search: {str(e)}"
46
 
47
 
48
  from langchain_community.document_loaders import ArxivLoader
 
297
  search_arxiv,
298
  # PNG2FENTool,
299
  # ChessEngineTool(),
300
+ # GoogleSearchTool,
301
  # ImageAnalysisTool,
302
  ],
303
  verbosity_level=2,
304
  # prompt_templates=prompt_templates,
305
  add_base_tools=False,
306
+ max_steps=20
307
  )
308
  print("MagAgent initialized.")
309
 
 
330
  " - Provide answers that are concise, accurate, and properly punctuated according to standard English grammar.\n"
331
  " - Use quotation marks for direct quotes (e.g., \"Extreamly.\") and appropriate punctuation for lists, sentences, or clarifications.\n"
332
  " - If the question asks for a specific quote or response (e.g., what a character says), format the answer clearly, e.g., 'Character says, \"Exact quote.\"'\n\n"
333
+ " - If asked about name of place or city, use full complete name without abbreviations (e.g. use Saint Petersburg instead of St.Petersburg). \n"
334
  "4. **Error Handling**:\n"
335
  " - If you cannot retrieve or process data (e.g., due to blocked requests), return a clear error message: \"Unable to retrieve data. Please refine the question or check external sources.\"\n\n"
336
  f"Answer the following question: {question} \n"