Dkapsis commited on
Commit
5037c4d
·
1 Parent(s): 465f9b7
__pycache__/agents.cpython-310.pyc CHANGED
Binary files a/__pycache__/agents.cpython-310.pyc and b/__pycache__/agents.cpython-310.pyc differ
 
__pycache__/config.cpython-310.pyc ADDED
Binary file (404 Bytes). View file
 
__pycache__/multi_agent.cpython-310.pyc CHANGED
Binary files a/__pycache__/multi_agent.cpython-310.pyc and b/__pycache__/multi_agent.cpython-310.pyc differ
 
__pycache__/prompts.cpython-310.pyc CHANGED
Binary files a/__pycache__/prompts.cpython-310.pyc and b/__pycache__/prompts.cpython-310.pyc differ
 
__pycache__/tools.cpython-310.pyc CHANGED
Binary files a/__pycache__/tools.cpython-310.pyc and b/__pycache__/tools.cpython-310.pyc differ
 
agents.py CHANGED
@@ -5,35 +5,23 @@ import os
5
  import tools
6
  import prompts
7
 
8
- if os.environ.get("OPENAI_API_KEY"):
9
- MANAGER_MODEL = "deepseek-ai/DeepSeek-R1"
10
- FINAL_ANSWER_MODEL = "deepseek-ai/DeepSeek-R1" # OpenAIServerModel
11
- else:
12
- MANAGER_MODEL = "deepseek-ai/DeepSeek-R1"
13
- FINAL_ANSWER_MODEL = "deepseek-ai/DeepSeek-R1" # OpenAIServerModel
14
-
15
- if os.environ.get("HF_TOKEN"):
16
- AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
17
- WEB_SEARCH_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
18
- IMAGE_ANALYSIS_MODEL = "HuggingFaceM4/idefics2-8b"
19
- AUDIO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
20
- VIDEO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
21
- YOUTUBE_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
22
- DOCUMENT_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
23
- ARITHMETIC_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
24
- CODE_GENERATION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
25
- CODE_EXECUTION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
26
- else:
27
- AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
28
- WEB_SEARCH_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
29
- IMAGE_ANALYSIS_MODEL = "HuggingFaceM4/idefics2-8b"
30
- AUDIO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
31
- VIDEO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
32
- YOUTUBE_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
33
- DOCUMENT_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
34
- ARITHMETIC_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
35
- CODE_GENERATION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
36
- CODE_EXECUTION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
37
 
38
  # Agents
39
 
@@ -42,7 +30,7 @@ def create_custom_web_search_agent(message):
42
  name="custom_web_search_agent",
43
  description=prompts.get_web_search_prompt(message),
44
  model=InferenceClientModel(WEB_SEARCH_MODEL),
45
- max_steps=2,
46
  tools=[tools.simple_web_search_tool, tools.visit_web_page_tool],
47
  )
48
 
@@ -51,7 +39,7 @@ def create_simple_web_search_agent(message):
51
  name="simple_web_search_agent",
52
  description=prompts.get_web_search_prompt(message),
53
  model=InferenceClientModel(WEB_SEARCH_MODEL),
54
- max_steps=2,
55
  tools=[tools.simple_web_search_tool, tools.visit_web_page_tool],
56
  )
57
 
@@ -61,7 +49,7 @@ def create_image_analysis_agent(message):
61
  description=prompts.get_image_analysis_prompt(message),
62
  model=InferenceClientModel(IMAGE_ANALYSIS_MODEL),
63
  tools=[tools.image_analysis_tool],
64
- max_steps=2,
65
  )
66
 
67
  def create_audio_analysis_agent(message):
@@ -70,13 +58,79 @@ def create_audio_analysis_agent(message):
70
  description=prompts.get_audio_analysis_prompt(message),
71
  model=InferenceClientModel(AUDIO_ANALYSIS_MODEL),
72
  tools=[tools.audio_analysis_tool],
73
- max_steps=2,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  )
75
 
76
  def create_manager_agent(message):
77
  simple_web_search_agent = create_simple_web_search_agent(message)
78
  image_analysis_agent = create_image_analysis_agent(message)
79
  audio_analysis_agent = create_audio_analysis_agent(message)
 
 
 
 
 
 
80
 
81
  return CodeAgent(
82
  name="manager_agent",
@@ -89,6 +143,12 @@ def create_manager_agent(message):
89
  simple_web_search_agent,
90
  image_analysis_agent,
91
  audio_analysis_agent,
 
 
 
 
 
 
92
  ],
93
  max_steps=10,
94
  additional_authorized_imports=[
@@ -123,7 +183,7 @@ def create_final_answer_agent(message):
123
  return CodeAgent(
124
  name="final_answer_agent",
125
  description="Given a question and an initial answer, return the final refined answer following strict formatting rules.",
126
- model=OpenAIServerModel(FINAL_ANSWER_MODEL),
127
- max_steps=3,
128
  tools=[],
129
  )
 
5
  import tools
6
  import prompts
7
 
8
+ MANAGER_MODEL_GPT = "gpt-4.5-preview"
9
+ FINAL_ANSWER_MODEL_GEMINI = "gemini-2.5-pro-preview-03-25"
10
+ AGENT_MODEL_GTP = "gpt-4.1-mini"
11
+
12
+ MANAGER_MODEL = "deepseek-ai/DeepSeek-R1"
13
+ # FINAL_ANSWER_MODEL = "gpt-4o" # OpenAIServerModel
14
+ FINAL_ANSWER_MODEL = "deepseek-ai/DeepSeek-R1" # OpenAIServerModel
15
+ AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
16
+ WEB_SEARCH_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
17
+ IMAGE_ANALYSIS_MODEL = "HuggingFaceM4/idefics2-8b"
18
+ AUDIO_ANALYSIS_MODEL = "Qwen/Qwen2-Audio-7B-Instruct"
19
+ VIDEO_ANALYSIS_MODEL = "llava-hf/LLaVA-NeXT-Video-7B-hf"
20
+ YOUTUBE_ANALYSIS_MODEL = "llava-hf/LLaVA-NeXT-Video-7B-hf"
21
+ DOCUMENT_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
22
+ ARITHMETIC_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
23
+ CODE_GENERATION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
24
+ CODE_EXECUTION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  # Agents
27
 
 
30
  name="custom_web_search_agent",
31
  description=prompts.get_web_search_prompt(message),
32
  model=InferenceClientModel(WEB_SEARCH_MODEL),
33
+ max_steps=3,
34
  tools=[tools.simple_web_search_tool, tools.visit_web_page_tool],
35
  )
36
 
 
39
  name="simple_web_search_agent",
40
  description=prompts.get_web_search_prompt(message),
41
  model=InferenceClientModel(WEB_SEARCH_MODEL),
42
+ max_steps=3,
43
  tools=[tools.simple_web_search_tool, tools.visit_web_page_tool],
44
  )
45
 
 
49
  description=prompts.get_image_analysis_prompt(message),
50
  model=InferenceClientModel(IMAGE_ANALYSIS_MODEL),
51
  tools=[tools.image_analysis_tool],
52
+ max_steps=3,
53
  )
54
 
55
  def create_audio_analysis_agent(message):
 
58
  description=prompts.get_audio_analysis_prompt(message),
59
  model=InferenceClientModel(AUDIO_ANALYSIS_MODEL),
60
  tools=[tools.audio_analysis_tool],
61
+ max_steps=3,
62
+ )
63
+
64
+ def create_video_analysis_agent(message):
65
+ return CodeAgent(
66
+ name="video_analysis_agent",
67
+ description=prompts.get_video_analysis_prompt(message),
68
+ model=InferenceClientModel(VIDEO_ANALYSIS_MODEL),
69
+ tools=[tools.video_analysis_tool],
70
+ max_steps=3,
71
+ )
72
+
73
+ def create_youtube_analysis_agent(message):
74
+ return CodeAgent(
75
+ name="youtube_analysis_agent",
76
+ description=prompts.get_youtube_analysis_prompt(message),
77
+ model=InferenceClientModel(YOUTUBE_ANALYSIS_MODEL),
78
+ tools=[tools.youtube_analysis_tool],
79
+ max_steps=3,
80
+ )
81
+
82
+ def create_document_analysis_agent(message):
83
+ return CodeAgent(
84
+ name="document_analysis_agent",
85
+ description=prompts.get_document_analysis_prompt(message),
86
+ model=InferenceClientModel(DOCUMENT_ANALYSIS_MODEL),
87
+ tools=[tools.document_analysis_tool],
88
+ max_steps=3,
89
+ )
90
+
91
+ def create_arithmetic_agent(message):
92
+ return CodeAgent(
93
+ name="arithmetic_agent",
94
+ description=prompts.get_arithmetic_prompt(message),
95
+ model=InferenceClientModel(ARITHMETIC_MODEL),
96
+ tools=[
97
+ tools.add,
98
+ tools.subtract,
99
+ tools.multiply,
100
+ tools.divide,
101
+ tools.modulus,
102
+ ],
103
+ max_steps=3,
104
+ )
105
+
106
+ def create_code_generation_agent(message):
107
+ return CodeAgent(
108
+ name="code_generation_agent",
109
+ description=prompts.get_code_generation_prompt(message),
110
+ model=InferenceClientModel(CODE_GENERATION_MODEL),
111
+ tools=[tools.code_generation_tool],
112
+ max_steps=3,
113
+ )
114
+
115
+ def create_code_execution_agent(message):
116
+ return CodeAgent(
117
+ name="code_execution_agent",
118
+ description=prompts.get_code_execution_prompt(message),
119
+ model=InferenceClientModel(CODE_EXECUTION_MODEL),
120
+ tools=[tools.code_execution_tool],
121
+ max_steps=3,
122
  )
123
 
124
  def create_manager_agent(message):
125
  simple_web_search_agent = create_simple_web_search_agent(message)
126
  image_analysis_agent = create_image_analysis_agent(message)
127
  audio_analysis_agent = create_audio_analysis_agent(message)
128
+ video_analysis_agent = create_video_analysis_agent(message)
129
+ youtube_analysis_agent = create_youtube_analysis_agent(message)
130
+ document_analysis_agent = create_document_analysis_agent(message)
131
+ arithmetic_agent = create_arithmetic_agent(message)
132
+ code_generation_agent = create_code_generation_agent(message)
133
+ code_execution_agent = create_code_execution_agent(message)
134
 
135
  return CodeAgent(
136
  name="manager_agent",
 
143
  simple_web_search_agent,
144
  image_analysis_agent,
145
  audio_analysis_agent,
146
+ video_analysis_agent,
147
+ youtube_analysis_agent,
148
+ document_analysis_agent,
149
+ arithmetic_agent,
150
+ code_generation_agent,
151
+ code_execution_agent,
152
  ],
153
  max_steps=10,
154
  additional_authorized_imports=[
 
183
  return CodeAgent(
184
  name="final_answer_agent",
185
  description="Given a question and an initial answer, return the final refined answer following strict formatting rules.",
186
+ # model=OpenAIServerModel(FINAL_ANSWER_MODEL),
187
+ model=InferenceClientModel(FINAL_ANSWER_MODEL),
188
  tools=[],
189
  )
app.py CHANGED
@@ -7,6 +7,7 @@ from huggingface_hub import login
7
  from dotenv import load_dotenv
8
 
9
  from multi_agent import orchestrate
 
10
 
11
  # (Keep Constants as is)
12
  # --- Constants ---
@@ -151,7 +152,7 @@ def test_init_agent_for_chat(question,
151
  anthropic_api_key,
152
  space_id,
153
  hf_token,
154
- serpapi_api_key,
155
  file_name
156
  ):
157
 
@@ -173,19 +174,26 @@ def test_init_agent_for_chat(question,
173
  os.environ["ANTHROPIC_API_KEY"] = anthropic_api_key
174
  os.environ["SPACE_ID"] = space_id
175
  os.environ["HF_TOKEN"] = hf_token
176
- os.environ["SERPAPI_API_KEY"] = serpapi_api_key
 
 
 
 
 
 
 
177
 
178
  submitted_answer = orchestrate(question, file_name)
179
 
180
  except Exception as e:
181
  raise gr.Error(e)
182
- finally:
183
- del os.environ["OPENAI_API_KEY"]
184
- del os.environ["GEMINI_API_KEY"]
185
- del os.environ["ANTHROPIC_API_KEY"]
186
- del os.environ["SPACE_ID"]
187
- del os.environ["HF_TOKEN"]
188
- del os.environ["OPENAI_API_KEY"]
189
 
190
  return submitted_answer
191
 
@@ -197,8 +205,9 @@ with gr.Blocks() as demo:
197
  **Instructions:**
198
 
199
  1. Who is in the final of champions league in 2025?
200
- 2. What is the colour of the suit in this image: https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fimages.hdqwalls.com%2Fwallpapers%2Fblack-superman-henry-cavill-xa.jpg&f=1&nofb=1&ipt=451cdc8bb05635ac59e50dc567cb68ae38ad45a626622ee7760b2c3ef828d5a7?
201
- 3. Which of the fruits shown in the 2008 painting “Embroidery from Uzbekistan” were served as part of the October 1949 breakfast menu for the ocean liner that was later used as a floating prop for the film “The Last Voyage”? Give the items as a comma-separated list, ordering them in clockwise order based on their arrangement in the painting starting from the 12 o’clock position. Use the plural form of each fruit.
 
202
 
203
  """
204
  )
@@ -207,37 +216,38 @@ with gr.Blocks() as demo:
207
  space_id = gr.Textbox(
208
  label="space Id *",
209
  type="password",
210
- placeholder="sk‑...",
211
  interactive=True
212
  )
213
  hf_token = gr.Textbox(
214
  label="HF Token *",
215
  type="password",
 
216
  interactive=True
217
  )
218
- serpapi_api_key = gr.Textbox(
219
- label="Serpapi API Key *",
220
  type="password",
221
- placeholder="sk-ant-...",
222
  interactive=True
223
  )
224
 
225
  with gr.Row():
226
- openai_api_key = gr.Textbox(
227
- label="OpenAI API Key *",
228
  type="password",
229
- placeholder="sk‑...",
230
  interactive=True
231
  )
232
  gemini_api_key = gr.Textbox(
233
- label="Gemini API Key *",
234
  type="password",
235
  interactive=True
236
  )
237
  anthropic_api_key = gr.Textbox(
238
- label="Anthropic API Key *",
239
  type="password",
240
- placeholder="sk-ant-...",
241
  interactive=True
242
  )
243
 
@@ -268,7 +278,7 @@ with gr.Blocks() as demo:
268
  gr.LoginButton()
269
  submit_btn.click(
270
  fn=test_init_agent_for_chat,
271
- inputs=[question, openai_api_key, gemini_api_key, anthropic_api_key, space_id, hf_token, serpapi_api_key, file_name],
272
  outputs=answer
273
  )
274
  # gr.ChatInterface(test_init_agent_for_chat(
@@ -278,7 +288,7 @@ with gr.Blocks() as demo:
278
  # anthropic_api_key = anthropic_api_key,
279
  # space_id = space_id,
280
  # hf_token = hf_token,
281
- # serpapi_api_key = serpapi_api_key
282
  # ), type="messages")
283
 
284
  # run_button = gr.Button("Run Evaluation & Submit All Answers")
 
7
  from dotenv import load_dotenv
8
 
9
  from multi_agent import orchestrate
10
+ from config import config
11
 
12
  # (Keep Constants as is)
13
  # --- Constants ---
 
152
  anthropic_api_key,
153
  space_id,
154
  hf_token,
155
+ serper_api_key,
156
  file_name
157
  ):
158
 
 
174
  os.environ["ANTHROPIC_API_KEY"] = anthropic_api_key
175
  os.environ["SPACE_ID"] = space_id
176
  os.environ["HF_TOKEN"] = hf_token
177
+ os.environ["SERPER_API_KEY"] = serper_api_key
178
+
179
+ config.OPENAI_API_KEY = openai_api_key
180
+ config.GEMINI_API_KEY = gemini_api_key
181
+ config.ANTHROPIC_API_KEY = anthropic_api_key
182
+ config.SPACE_ID = space_id
183
+ config.HF_TOKEN = hf_token
184
+ config.SERPER_API_KEY = serper_api_key
185
 
186
  submitted_answer = orchestrate(question, file_name)
187
 
188
  except Exception as e:
189
  raise gr.Error(e)
190
+ # finally:
191
+ # del os.environ["OPENAI_API_KEY"]
192
+ # del os.environ["GEMINI_API_KEY"]
193
+ # del os.environ["ANTHROPIC_API_KEY"]
194
+ # del os.environ["SPACE_ID"]
195
+ # del os.environ["HF_TOKEN"]
196
+ # del os.environ["SERPER_API_KEY"]
197
 
198
  return submitted_answer
199
 
 
205
  **Instructions:**
206
 
207
  1. Who is in the final of champions league in 2025?
208
+ 2. Who is in the final of champions league form 2020 to 2025?
209
+ 3. What is the colour of the suit in this image: https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fimages.hdqwalls.com%2Fwallpapers%2Fblack-superman-henry-cavill-xa.jpg&f=1&nofb=1&ipt=451cdc8bb05635ac59e50dc567cb68ae38ad45a626622ee7760b2c3ef828d5a7?
210
+ 4. Which of the fruits shown in the 2008 painting “Embroidery from Uzbekistan” were served as part of the October 1949 breakfast menu for the ocean liner that was later used as a floating prop for the film “The Last Voyage”? Give the items as a comma-separated list, ordering them in clockwise order based on their arrangement in the painting starting from the 12 o’clock position. Use the plural form of each fruit.
211
 
212
  """
213
  )
 
216
  space_id = gr.Textbox(
217
  label="space Id *",
218
  type="password",
219
+ placeholder="Dkapsis/assignment-gaia-agent",
220
  interactive=True
221
  )
222
  hf_token = gr.Textbox(
223
  label="HF Token *",
224
  type="password",
225
+ placeholder="hf_password",
226
  interactive=True
227
  )
228
+ openai_api_key = gr.Textbox(
229
+ label="OpenAI API Key *",
230
  type="password",
231
+ placeholder="sk‑...",
232
  interactive=True
233
  )
234
 
235
  with gr.Row():
236
+ serper_api_key = gr.Textbox(
237
+ label="Serper API Key",
238
  type="password",
239
+ placeholder="password",
240
  interactive=True
241
  )
242
  gemini_api_key = gr.Textbox(
243
+ label="Gemini API Key",
244
  type="password",
245
  interactive=True
246
  )
247
  anthropic_api_key = gr.Textbox(
248
+ label="Anthropic API Key",
249
  type="password",
250
+ placeholder="password",
251
  interactive=True
252
  )
253
 
 
278
  gr.LoginButton()
279
  submit_btn.click(
280
  fn=test_init_agent_for_chat,
281
+ inputs=[question, openai_api_key, gemini_api_key, anthropic_api_key, space_id, hf_token, serper_api_key, file_name],
282
  outputs=answer
283
  )
284
  # gr.ChatInterface(test_init_agent_for_chat(
 
288
  # anthropic_api_key = anthropic_api_key,
289
  # space_id = space_id,
290
  # hf_token = hf_token,
291
+ # serper_api_key = serper_api_key
292
  # ), type="messages")
293
 
294
  # run_button = gr.Button("Run Evaluation & Submit All Answers")
config.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ class Config:
2
+ OPENAI_API_KEY = None
3
+ GEMINI_API_KEY = None
4
+ ANTHROPIC_API_KEY = None
5
+ SPACE_ID = None
6
+ HF_TOKEN = None
7
+ SERPER_API_KEY = None
8
+
9
+ config = Config()
prompts.py CHANGED
@@ -21,6 +21,48 @@ def get_audio_analysis_prompt(message, file_path=None):
21
 
22
  return prompt
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def get_manager_prompt(message, file_path=None):
25
  prompt = f"""Your job is to answer the following question.
26
  Answer the following question. If needed, delegate to one of your coworkers:\n
 
21
 
22
  return prompt
23
 
24
+ def get_video_analysis_prompt(message, file_path=None):
25
+ prompt = f"""
26
+ As an expert video analysis assistant, you analyze the video to answer the question. Given a question and video file, analyze the video and answer the question: {message}
27
+ """
28
+
29
+ return prompt
30
+
31
+ def get_youtube_analysis_prompt(message, file_path=None):
32
+ prompt = f"""
33
+ As an expert YouTube analysis assistant, you analyze the video to answer the question. Given a question and YouTube URL, analyze the video and answer the question: {message}
34
+ """
35
+
36
+ return prompt
37
+
38
+ def get_document_analysis_prompt(message, file_path=None):
39
+ prompt = f"""
40
+ As an expert document analysis assistant, you analyze the document to answer the question. Given a question and document file, analyze the document and answer the question: {message}
41
+ """
42
+
43
+ return prompt
44
+
45
+ def get_arithmetic_prompt(message, file_path=None):
46
+ prompt = f"""
47
+ As an expert arithmetic assistant, you perform the calculation to answer the question. Given a question and two numbers, perform the calculation and answer the question: {message}
48
+ """
49
+
50
+ return prompt
51
+
52
+ def get_code_generation_prompt(message, file_path=None):
53
+ prompt = f"""
54
+ As an expert Python code generation assistant, you generate and execute code to answer the question. Given a question and JSON data, generate and execute code to answer the question: {message}
55
+ """
56
+
57
+ return prompt
58
+
59
+ def get_code_execution_prompt(message, file_path=None):
60
+ prompt = f"""
61
+ As an expert Python code execution assistant, you execute code to answer the question. Given a question and Python file, execute the file to answer the question: {message}
62
+ """
63
+
64
+ return prompt
65
+
66
  def get_manager_prompt(message, file_path=None):
67
  prompt = f"""Your job is to answer the following question.
68
  Answer the following question. If needed, delegate to one of your coworkers:\n
tools.py CHANGED
@@ -1,12 +1,22 @@
1
 
2
  import os
3
  import base64
4
- from smolagents import DuckDuckGoSearchTool, VisitWebpageTool
5
  from smolagents.tools import tool
6
 
 
 
7
  # Tools
8
 
9
- simple_web_search_tool = DuckDuckGoSearchTool()
 
 
 
 
 
 
 
 
10
  visit_web_page_tool = VisitWebpageTool()
11
 
12
  @tool
@@ -98,4 +108,266 @@ def audio_analysis_tool(question: str, file_path: str) -> str:
98
 
99
  return prompt # The agent model will process this
100
  except Exception as e:
101
- raise RuntimeError(f"Audio analysis failed: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  import os
3
  import base64
4
+ from smolagents import DuckDuckGoSearchTool, VisitWebpageTool, GoogleSearchTool
5
  from smolagents.tools import tool
6
 
7
+ from config import config
8
+
9
  # Tools
10
 
11
+ if not os.environ.get("SERPER_API_KEY"):
12
+ print("---------------DEN VRIKA KEY-----------")
13
+ print("---------------DEN VRIKA KEY-----------")
14
+ simple_web_search_tool = DuckDuckGoSearchTool()
15
+ else:
16
+ print("!!!!!!!!!!!!! VRIKA KEY !!!!!!!!!!!!!!!!")
17
+ print("!!!!!!!!!!!!! VRIKA KEY !!!!!!!!!!!!!!!!")
18
+ simple_web_search_tool = GoogleSearchTool("serper")
19
+
20
  visit_web_page_tool = VisitWebpageTool()
21
 
22
  @tool
 
108
 
109
  return prompt # The agent model will process this
110
  except Exception as e:
111
+ raise RuntimeError(f"Audio analysis failed: {str(e)}")
112
+
113
+ @tool
114
+ def video_analysis_tool(question: str, file_path: str) -> str:
115
+ """
116
+ Given a question and a video file path, analyze the video to answer the question.
117
+
118
+ Args:
119
+ question (str): A question about the video.
120
+ file_path (str): Path to the video file.
121
+
122
+ Returns:
123
+ str: Structured prompt with video and question (for agent model to process).
124
+
125
+ Raises:
126
+ RuntimeError: If processing fails.
127
+ """
128
+ try:
129
+ # Read and encode video to base64
130
+ with open(file_path, "rb") as video_file:
131
+ video_data = base64.b64encode(video_file.read()).decode("utf-8")
132
+
133
+ # Format the content in a vision+text style prompt, adapted for video
134
+ prompt = {
135
+ "inputs": {
136
+ "video": video_data,
137
+ "question": question
138
+ }
139
+ }
140
+
141
+ return prompt # The agent model will process this
142
+ except Exception as e:
143
+ raise RuntimeError(f"Video analysis failed: {str(e)}")
144
+
145
+ @tool
146
+ def youtube_analysis_tool(question: str, url: str) -> str:
147
+ """
148
+ Given a question and a YouTube video URL, analyze the video to answer the question.
149
+
150
+ Args:
151
+ question (str): A question about the YouTube video.
152
+ url (str): The YouTube URL.
153
+
154
+ Returns:
155
+ str: Structured prompt with URL and question (for agent model to process).
156
+
157
+ Raises:
158
+ RuntimeError: If processing fails.
159
+ """
160
+ try:
161
+ # Prepare structured input to be processed by the agent model
162
+ prompt = {
163
+ "inputs": {
164
+ "youtube_url": url,
165
+ "question": question
166
+ }
167
+ }
168
+
169
+ return prompt # The agent model will handle downloading and processing
170
+ except Exception as e:
171
+ raise RuntimeError(f"YouTube analysis failed: {str(e)}")
172
+
173
+ @tool
174
+ def document_analysis_tool(question: str, file_path: str) -> str:
175
+ """
176
+ Given a question and a document file path, analyze the document to answer the question.
177
+
178
+ Args:
179
+ question (str): A question about the document.
180
+ file_path (str): Path to the document file.
181
+
182
+ Returns:
183
+ str: Structured prompt with document content and question (for agent model to process).
184
+
185
+ Raises:
186
+ RuntimeError: If processing fails.
187
+ """
188
+ try:
189
+ if is_ext(file_path, ".docx"):
190
+ # Extract text from .docx files
191
+ text_data = read_docx_text(file_path)
192
+ prompt = {
193
+ "inputs": {
194
+ "document_type": "docx",
195
+ "document_content": text_data,
196
+ "question": question
197
+ }
198
+ }
199
+ elif is_ext(file_path, ".pptx"):
200
+ # Extract text from .pptx files
201
+ text_data = read_pptx_text(file_path)
202
+ prompt = {
203
+ "inputs": {
204
+ "document_type": "pptx",
205
+ "document_content": text_data,
206
+ "question": question
207
+ }
208
+ }
209
+ else:
210
+ # For PDFs or other binary files, encode to base64
211
+ with open(file_path, "rb") as file:
212
+ encoded_data = base64.b64encode(file.read()).decode("utf-8")
213
+ prompt = {
214
+ "inputs": {
215
+ "document_type": "binary",
216
+ "document_base64": encoded_data,
217
+ "question": question
218
+ }
219
+ }
220
+
221
+ return prompt # Agent model will handle document type accordingly
222
+ except Exception as e:
223
+ raise RuntimeError(f"Document analysis failed: {str(e)}")
224
+
225
+ @tool
226
+ def arithmetic_tool(question: str, a: float, b: float) -> dict:
227
+ """
228
+ Given a question and two numbers, perform the calculation to answer the question.
229
+
230
+ Args:
231
+ question (str): A natural language arithmetic question.
232
+ a (float): First number.
233
+ b (float): Second number.
234
+
235
+ Returns:
236
+ dict: Structured input for the model or agent to interpret and compute.
237
+
238
+ Raises:
239
+ RuntimeError: If input or processing fails.
240
+ """
241
+ try:
242
+ prompt = {
243
+ "inputs": {
244
+ "question": question,
245
+ "a": a,
246
+ "b": b
247
+ }
248
+ }
249
+
250
+ return prompt # Let the model/agent evaluate and compute the result
251
+ except Exception as e:
252
+ raise RuntimeError(f"Arithmetic processing failed: {str(e)}")
253
+
254
+ @tool
255
+ def code_generation_tool(question: str, json_data: str) -> dict:
256
+ """
257
+ Given a question and JSON data, generate and execute code to answer the question.
258
+
259
+ Args:
260
+ question (str): The question to be answered.
261
+ json_data (str): Input JSON data as a string.
262
+
263
+ Returns:
264
+ dict: Structured input for the agent or model to process and respond.
265
+
266
+ Raises:
267
+ RuntimeError: If formatting or processing fails.
268
+ """
269
+ try:
270
+ prompt = {
271
+ "inputs": {
272
+ "question": question,
273
+ "json_data": json_data
274
+ }
275
+ }
276
+
277
+ return prompt # Model or code-executing agent will handle the execution logic
278
+ except Exception as e:
279
+ raise RuntimeError(f"Code generation processing failed: {str(e)}")
280
+
281
+ @tool
282
+ def code_execution_tool(question: str, file_path: str) -> dict:
283
+ """
284
+ Given a question and a Python file, prepare code execution context to answer the question.
285
+
286
+ Args:
287
+ question (str): The question to be answered.
288
+ file_path (str): Path to the Python file.
289
+
290
+ Returns:
291
+ dict: Structured input with base64-encoded file and question.
292
+
293
+ Raises:
294
+ RuntimeError: If encoding or file handling fails.
295
+ """
296
+ try:
297
+ # Read and encode the Python file
298
+ with open(file_path, "rb") as py_file:
299
+ code_data = base64.b64encode(py_file.read()).decode("utf-8")
300
+
301
+ # Construct prompt structure
302
+ prompt = {
303
+ "inputs": {
304
+ "question": question,
305
+ "python_file": code_data,
306
+ "file_name": os.path.basename(file_path)
307
+ }
308
+ }
309
+
310
+ return prompt # Model/agent will handle execution and answer
311
+ except Exception as e:
312
+ raise RuntimeError(f"Code execution processing failed: {str(e)}")
313
+
314
+ @tool
315
+ def add(a: float, b: float) -> float:
316
+ """Add two numbers.
317
+
318
+ Args:
319
+ a: First number
320
+ b: Second number
321
+ Returns:
322
+ Result number
323
+ """
324
+ return a + b
325
+
326
+ @tool
327
+ def subtract(a: float, b: float) -> float:
328
+ """Subtract two numbers.
329
+
330
+ Args:
331
+ a: First number
332
+ b: Second number
333
+ Returns:
334
+ Result number
335
+ """
336
+ return a - b
337
+
338
+ @tool
339
+ def multiply(a: float, b: float) -> float:
340
+ """Multiply two numbers.
341
+ Args:
342
+ a: First number
343
+ b: Second number
344
+ Returns:
345
+ Result number
346
+ """
347
+ return a * b
348
+
349
+ @tool
350
+ def divide(a: float, b: float) -> float:
351
+ """Divide two numbers.
352
+
353
+ Args:
354
+ a: First number
355
+ b: Second number
356
+ Returns:
357
+ Result number
358
+ """
359
+ if b == 0:
360
+ raise ValueError("Cannot divide by zero.")
361
+ return a / b
362
+
363
+ @tool
364
+ def modulus(a: float, b: float) -> float:
365
+ """Get the modulus of two numbers.
366
+
367
+ Args:
368
+ a: First number
369
+ b: Second number
370
+ Returns:
371
+ Result number
372
+ """
373
+ return a % b