Spaces:
Runtime error
Runtime error
Commit
Β·
76a8abb
1
Parent(s):
90a12ad
Scoring 10 out of 20
Browse files- agents.py +7 -5
- tooling.py +26 -1
agents.py
CHANGED
@@ -5,7 +5,7 @@ import torch
|
|
5 |
from smolagents import LiteLLMModel, OpenAIServerModel
|
6 |
from smolagents import (ToolCallingAgent,
|
7 |
CodeAgent,
|
8 |
-
|
9 |
VisitWebpageTool,
|
10 |
WikipediaSearchTool,
|
11 |
FinalAnswerTool,
|
@@ -15,7 +15,8 @@ from smolagents import (ToolCallingAgent,
|
|
15 |
from tooling import (vision_language_tool,
|
16 |
read_excel_tool,
|
17 |
speech_to_text_tool,
|
18 |
-
youtube_captions_tool
|
|
|
19 |
|
20 |
# Agent Model
|
21 |
model = OpenAIServerModel(model_id = "gpt-4.1",
|
@@ -43,7 +44,8 @@ def create_web_agent():
|
|
43 |
# Create Web Agent
|
44 |
return CodeAgent(model = model,
|
45 |
tools = [FinalAnswerTool(),
|
46 |
-
|
|
|
47 |
VisitWebpageTool(max_output_length = 75000),
|
48 |
WikipediaSearchTool(user_agent = "FinalAssignmentResearchBot ([email protected])",
|
49 |
language = "en",
|
@@ -61,7 +63,7 @@ def create_web_agent():
|
|
61 |
name = 'web_agent',
|
62 |
planning_interval = 3,
|
63 |
verbosity_level = 2,
|
64 |
-
max_steps =
|
65 |
provide_run_summary = True,
|
66 |
description = """
|
67 |
A team member that will use various tools to search for websites, to visit websites and to parse and read information from websites.
|
@@ -95,6 +97,6 @@ def create_manager_agent():
|
|
95 |
planning_interval = 3,
|
96 |
verbosity_level = 2,
|
97 |
stream_outputs = True,
|
98 |
-
max_steps =
|
99 |
provide_run_summary = True,
|
100 |
managed_agents = [vision_agent, web_agent])
|
|
|
5 |
from smolagents import LiteLLMModel, OpenAIServerModel
|
6 |
from smolagents import (ToolCallingAgent,
|
7 |
CodeAgent,
|
8 |
+
GoogleSearchTool,
|
9 |
VisitWebpageTool,
|
10 |
WikipediaSearchTool,
|
11 |
FinalAnswerTool,
|
|
|
15 |
from tooling import (vision_language_tool,
|
16 |
read_excel_tool,
|
17 |
speech_to_text_tool,
|
18 |
+
youtube_captions_tool,
|
19 |
+
DuckDuckGoSearchTool)
|
20 |
|
21 |
# Agent Model
|
22 |
model = OpenAIServerModel(model_id = "gpt-4.1",
|
|
|
44 |
# Create Web Agent
|
45 |
return CodeAgent(model = model,
|
46 |
tools = [FinalAnswerTool(),
|
47 |
+
GoogleSearchTool(),
|
48 |
+
DuckDuckGoSearchTool(),
|
49 |
VisitWebpageTool(max_output_length = 75000),
|
50 |
WikipediaSearchTool(user_agent = "FinalAssignmentResearchBot ([email protected])",
|
51 |
language = "en",
|
|
|
63 |
name = 'web_agent',
|
64 |
planning_interval = 3,
|
65 |
verbosity_level = 2,
|
66 |
+
max_steps = 20,
|
67 |
provide_run_summary = True,
|
68 |
description = """
|
69 |
A team member that will use various tools to search for websites, to visit websites and to parse and read information from websites.
|
|
|
97 |
planning_interval = 3,
|
98 |
verbosity_level = 2,
|
99 |
stream_outputs = True,
|
100 |
+
max_steps = 20,
|
101 |
provide_run_summary = True,
|
102 |
managed_agents = [vision_agent, web_agent])
|
tooling.py
CHANGED
@@ -9,7 +9,7 @@ import re
|
|
9 |
# Smolagents
|
10 |
import torch
|
11 |
from transformers import AutoProcessor, AutoModelForVision2Seq
|
12 |
-
from smolagents import
|
13 |
from smolagents.tools import PipelineTool
|
14 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
15 |
import librosa
|
@@ -300,3 +300,28 @@ The text below contains the information from the Excel File that has been loaded
|
|
300 |
"""
|
301 |
|
302 |
return excel_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Smolagents
|
10 |
import torch
|
11 |
from transformers import AutoProcessor, AutoModelForVision2Seq
|
12 |
+
from smolagents import tool, Tool
|
13 |
from smolagents.tools import PipelineTool
|
14 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
15 |
import librosa
|
|
|
300 |
"""
|
301 |
|
302 |
return excel_string
|
303 |
+
|
304 |
+
# Added as a fall backup...If Google doesn't work....may'be duck duck go does
|
305 |
+
class DuckDuckGoSearchTool(Tool):
|
306 |
+
name = "alternative_web_search"
|
307 |
+
description = """Use this as an alternative to perform a duckduckgo web search based on your query (think a Google search) then returns the top search results."""
|
308 |
+
inputs = {"query": {"type": "string", "description": "The search query to perform."}}
|
309 |
+
output_type = "string"
|
310 |
+
|
311 |
+
def __init__(self, max_results=10, **kwargs):
|
312 |
+
super().__init__()
|
313 |
+
self.max_results = max_results
|
314 |
+
try:
|
315 |
+
from duckduckgo_search import DDGS
|
316 |
+
except ImportError as e:
|
317 |
+
raise ImportError(
|
318 |
+
"You must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`."
|
319 |
+
) from e
|
320 |
+
self.ddgs = DDGS(**kwargs)
|
321 |
+
|
322 |
+
def forward(self, query: str) -> str:
|
323 |
+
results = self.ddgs.text(query, max_results=self.max_results)
|
324 |
+
if len(results) == 0:
|
325 |
+
raise Exception("No results found! Try a less restrictive/shorter query.")
|
326 |
+
postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
|
327 |
+
return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
|