handle audio, remove extra sub-agent
Browse files- basic_agent.py +19 -25
- basic_agent_test.py +9 -3
basic_agent.py
CHANGED
@@ -26,12 +26,13 @@ Remember - The FINAL ANSWER must be a string, a number or a comma separated list
|
|
26 |
|
27 |
@smolagents.tool
|
28 |
def convert_from_url(url: str) -> str:
|
29 |
-
"""Convert
|
30 |
|
31 |
-
This method takes a
|
32 |
-
a markdown
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
Args:
|
37 |
url: the url to access the file. If the file is on the
|
@@ -42,7 +43,7 @@ def convert_from_url(url: str) -> str:
|
|
42 |
string that is in the markdown format.
|
43 |
"""
|
44 |
# Don't need third-party plugins.
|
45 |
-
md = markitdown.MarkItDown(enable_plugins=
|
46 |
result = md.convert(url)
|
47 |
return result.text_content
|
48 |
|
@@ -89,22 +90,6 @@ class BasicAgent:
|
|
89 |
|
90 |
print(f"NEW5: BasicAgent {self.manager_model_id=} {self.code_model_id=}")
|
91 |
|
92 |
-
file_convert_tool = [
|
93 |
-
convert_from_url,
|
94 |
-
smolagents.FinalAnswerTool(),
|
95 |
-
]
|
96 |
-
self.convert_files_to_markdown = smolagents.CodeAgent(
|
97 |
-
name="convert_files_to_markdown",
|
98 |
-
description=
|
99 |
-
"Given a url, it converts the file from various formats (such as pdf, excel, powerpoint, audio, csv, etc) into the markdown format",
|
100 |
-
model=self.code_model,
|
101 |
-
tools=file_convert_tool,
|
102 |
-
max_steps=6,
|
103 |
-
verbosity_level=2,
|
104 |
-
planning_interval=None,
|
105 |
-
additional_authorized_imports=["markitdown"],
|
106 |
-
)
|
107 |
-
|
108 |
math_tools = [
|
109 |
smolagents.FinalAnswerTool(),
|
110 |
]
|
@@ -153,23 +138,32 @@ class BasicAgent:
|
|
153 |
additional_authorized_imports=["wikipedia-api"],
|
154 |
)
|
155 |
|
|
|
|
|
|
|
|
|
156 |
self.manager_agent = smolagents.CodeAgent(
|
157 |
name="manager_agent",
|
158 |
description="Manger of other agents",
|
159 |
-
tools=
|
160 |
model=self.manager_model,
|
161 |
add_base_tools=True,
|
162 |
max_steps=10,
|
163 |
verbosity_level=2,
|
164 |
planning_interval=None,
|
165 |
additional_authorized_imports=[
|
166 |
-
"duckduckgo_search",
|
|
|
|
|
|
|
|
|
|
|
167 |
],
|
168 |
managed_agents=[
|
169 |
self.web_search_agent,
|
170 |
self.wikipedia_search_agent,
|
171 |
self.math_agent,
|
172 |
-
self.convert_files_to_markdown,
|
173 |
],
|
174 |
final_answer_checks=[self.check_results],
|
175 |
)
|
|
|
26 |
|
27 |
@smolagents.tool
|
28 |
def convert_from_url(url: str) -> str:
|
29 |
+
"""Convert data at a url into a markdown string.
|
30 |
|
31 |
+
This method takes a url as input and converts the contents
|
32 |
+
into a markdown. It can convert file formats such as
|
33 |
+
pdf, excel, xlsx, csv, powerpoint, ppt, etc.
|
34 |
+
|
35 |
+
It can also transcribe audio files such as mp3.
|
36 |
|
37 |
Args:
|
38 |
url: the url to access the file. If the file is on the
|
|
|
43 |
string that is in the markdown format.
|
44 |
"""
|
45 |
# Don't need third-party plugins.
|
46 |
+
md = markitdown.MarkItDown(enable_plugins=False)
|
47 |
result = md.convert(url)
|
48 |
return result.text_content
|
49 |
|
|
|
90 |
|
91 |
print(f"NEW5: BasicAgent {self.manager_model_id=} {self.code_model_id=}")
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
math_tools = [
|
94 |
smolagents.FinalAnswerTool(),
|
95 |
]
|
|
|
138 |
additional_authorized_imports=["wikipedia-api"],
|
139 |
)
|
140 |
|
141 |
+
manager_tools = [
|
142 |
+
convert_from_url,
|
143 |
+
smolagents.FinalAnswerTool(),
|
144 |
+
]
|
145 |
self.manager_agent = smolagents.CodeAgent(
|
146 |
name="manager_agent",
|
147 |
description="Manger of other agents",
|
148 |
+
tools=manager_tools,
|
149 |
model=self.manager_model,
|
150 |
add_base_tools=True,
|
151 |
max_steps=10,
|
152 |
verbosity_level=2,
|
153 |
planning_interval=None,
|
154 |
additional_authorized_imports=[
|
155 |
+
"duckduckgo_search",
|
156 |
+
"wikipedia-api",
|
157 |
+
"markitdown",
|
158 |
+
"requests",
|
159 |
+
"pandas",
|
160 |
+
"io",
|
161 |
],
|
162 |
managed_agents=[
|
163 |
self.web_search_agent,
|
164 |
self.wikipedia_search_agent,
|
165 |
self.math_agent,
|
166 |
+
# self.convert_files_to_markdown,
|
167 |
],
|
168 |
final_answer_checks=[self.check_results],
|
169 |
)
|
basic_agent_test.py
CHANGED
@@ -9,6 +9,8 @@ LOG = logging.getLogger(__name__)
|
|
9 |
|
10 |
QUESTIONS_PATH = "../questions.json"
|
11 |
|
|
|
|
|
12 |
# Local:
|
13 |
# https://huggingface.co/docs/smolagents/tutorials/inspect_runs
|
14 |
# https://cobusgreyling.medium.com/introduce-inspectability-to-huggingface-smolagents-571bd3f8da4c
|
@@ -53,7 +55,11 @@ print(f"{len(questions)=}")
|
|
53 |
# 'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733'},
|
54 |
#
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
question = questions[want]
|
58 |
|
59 |
q_task_id = question["task_id"]
|
@@ -61,12 +67,12 @@ q_text = question["question"]
|
|
61 |
q_filename = question.get("file_name", "")
|
62 |
|
63 |
if q_filename:
|
64 |
-
file_url = f"{
|
65 |
print("Question {task_id=} has attachment: {file_url=}")
|
66 |
quest_with_url = f"{q_text}\nFile url: {file_url}"
|
67 |
else:
|
68 |
quest_with_url = q_text
|
69 |
|
70 |
-
answer = ba(
|
71 |
|
72 |
LOG.warning(f"{answer=}")
|
|
|
9 |
|
10 |
QUESTIONS_PATH = "../questions.json"
|
11 |
|
12 |
+
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
13 |
+
|
14 |
# Local:
|
15 |
# https://huggingface.co/docs/smolagents/tutorials/inspect_runs
|
16 |
# https://cobusgreyling.medium.com/introduce-inspectability-to-huggingface-smolagents-571bd3f8da4c
|
|
|
55 |
# 'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733'},
|
56 |
#
|
57 |
|
58 |
+
# 18 has an xlsx file
|
59 |
+
# 13 has an mp3 file
|
60 |
+
# 11 has a py file
|
61 |
+
# 9 has an mp3 file
|
62 |
+
want = 9
|
63 |
question = questions[want]
|
64 |
|
65 |
q_task_id = question["task_id"]
|
|
|
67 |
q_filename = question.get("file_name", "")
|
68 |
|
69 |
if q_filename:
|
70 |
+
file_url = f"{DEFAULT_API_URL}/files/{q_task_id}"
|
71 |
print("Question {task_id=} has attachment: {file_url=}")
|
72 |
quest_with_url = f"{q_text}\nFile url: {file_url}"
|
73 |
else:
|
74 |
quest_with_url = q_text
|
75 |
|
76 |
+
answer = ba(quest_with_url)
|
77 |
|
78 |
LOG.warning(f"{answer=}")
|