Spaces:
Running
Running
Update agent.py
Browse files
agent.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from smolagents import CodeAgent,
|
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 |
-
|
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 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
"
|
25 |
-
"
|
26 |
-
"
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
response
|
31 |
-
response.
|
32 |
-
|
33 |
-
|
34 |
-
|
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()
|