SergeyO7 commited on
Commit
cb6c54f
·
verified ·
1 Parent(s): 1c9ef67

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +28 -28
agent.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent, WikipediaSearchTool, LiteLLMModel, tool, load_tool # HfApiModel, OpenAIServerModel
2
  import asyncio
3
  import os
4
  import yaml
@@ -7,32 +7,31 @@ import requests
7
  from io import BytesIO
8
 
9
  # Simulated additional tools (implementation depends on external APIs or setup)
10
- @tool
11
- def GoogleSearchTool(query: str) -> str:
12
- """Tool for performing Google searches using Custom Search JSON API
13
- Args:
14
- query (str): Search query string
15
- Returns:
16
- str: Formatted search results
17
- """
18
- api_key = os.environ.get("GOOGLE_API_KEY")
19
- cse_id = os.environ.get("GOOGLE_CSE_ID")
20
- if not api_key or not cse_id:
21
- raise ValueError("GOOGLE_API_KEY and GOOGLE_CSE_ID must be set in environment variables.")
22
- url = "https://www.googleapis.com/customsearch/v1"
23
- params = {
24
- "key": api_key,
25
- "cx": cse_id,
26
- "q": query,
27
- "num": 5 # Number of results to return
28
- }
29
- try:
30
- response = requests.get(url, params=params)
31
- response.raise_for_status()
32
- results = response.json().get("items", [])
33
- return "\n".join([f"{item['title']}: {item['link']}" for item in results]) or "No results found."
34
- except Exception as e:
35
- return f"Error performing Google search: {str(e)}"
36
 
37
  @tool
38
  def ImageAnalysisTool(image_path: str) -> str:
@@ -103,7 +102,8 @@ class MagAgent:
103
  self.agent = CodeAgent(
104
  model= model,
105
  tools=[
106
- GoogleSearchTool,
 
107
  WikipediaSearchTool(),
108
  ImageAnalysisTool,
109
  # LocalFileAudioTool()
 
1
+ from smolagents import CodeAgent, DuckDuckSearchTool, WikipediaSearchTool, LiteLLMModel, tool, load_tool # HfApiModel, OpenAIServerModel
2
  import asyncio
3
  import os
4
  import yaml
 
7
  from io import BytesIO
8
 
9
  # Simulated additional tools (implementation depends on external APIs or setup)
10
+ #@tool
11
+ #def GoogleSearchTool(query: str) -> str:
12
+ # """Tool for performing Google searches using Custom Search JSON API
13
+ # Args:
14
+ # query (str): Search query string
15
+ # Returns:
16
+ # str: Formatted search results
17
+ # """
18
+ # cse_id = os.environ.get("GOOGLE_CSE_ID")
19
+ # if not api_key or not cse_id:
20
+ # raise ValueError("GOOGLE_API_KEY and GOOGLE_CSE_ID must be set in environment variables.")
21
+ # url = "https://www.googleapis.com/customsearch/v1"
22
+ # params = {
23
+ # "key": api_key,
24
+ # "cx": cse_id,
25
+ # "q": query,
26
+ # "num": 5 # Number of results to return
27
+ # }
28
+ # try:
29
+ # response = requests.get(url, params=params)
30
+ # response.raise_for_status()
31
+ # results = response.json().get("items", [])
32
+ # return "\n".join([f"{item['title']}: {item['link']}" for item in results]) or "No results found."
33
+ # except Exception as e:
34
+ # return f"Error performing Google search: {str(e)}"
 
35
 
36
  @tool
37
  def ImageAnalysisTool(image_path: str) -> str:
 
102
  self.agent = CodeAgent(
103
  model= model,
104
  tools=[
105
+ # GoogleSearchTool,
106
+ DuckDuckSearchTool(),
107
  WikipediaSearchTool(),
108
  ImageAnalysisTool,
109
  # LocalFileAudioTool()