Update crew.py
Browse files
crew.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
# References:
|
|
|
2 |
# https://docs.crewai.com/introduction
|
3 |
# https://ai.google.dev/gemini-api/docs
|
4 |
|
5 |
import os
|
|
|
6 |
from crewai import Agent, Crew, Process, Task
|
7 |
from crewai.tools import tool
|
8 |
from google import genai
|
@@ -23,7 +25,6 @@ IMAGE_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
|
23 |
AUDIO_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
24 |
VIDEO_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
25 |
YOUTUBE_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
26 |
-
DOCUMENT_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
27 |
CODE_GENERATION_MODEL = "gemini-2.5-flash-preview-04-17"
|
28 |
CODE_EXECUTION_MODEL = "gemini-2.5-flash-preview-04-17"
|
29 |
|
@@ -178,34 +179,6 @@ def run_crew(question, file_path):
|
|
178 |
except Exception as e:
|
179 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
180 |
|
181 |
-
@tool("Document Analysis Tool")
|
182 |
-
def document_analysis_tool(question: str, file_path: str) -> str:
|
183 |
-
"""Answer a question about a document file. Supported document types include:
|
184 |
-
.xlxs, .txt, .csv, .xml, .rtf, .pdf, .md, .html, .css, .js, .py
|
185 |
-
|
186 |
-
Args:
|
187 |
-
question (str): Question about a document file
|
188 |
-
file_path (str): The document file path
|
189 |
-
|
190 |
-
Returns:
|
191 |
-
str: Answer to the question about the document file
|
192 |
-
|
193 |
-
Raises:
|
194 |
-
RuntimeError: If processing fails"""
|
195 |
-
try:
|
196 |
-
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
197 |
-
|
198 |
-
file = client.files.upload(file=file_path)
|
199 |
-
|
200 |
-
response = client.models.generate_content(
|
201 |
-
model=DOCUMENT_ANALYSIS_MODEL,
|
202 |
-
contents=[file, question]
|
203 |
-
)
|
204 |
-
|
205 |
-
return response.text
|
206 |
-
except Exception as e:
|
207 |
-
raise RuntimeError(f"Processing failed: {str(e)}")
|
208 |
-
|
209 |
@tool("Code Generation Tool")
|
210 |
def code_generation_tool(question: str) -> str:
|
211 |
"""Generate and execute Python code to answer a question.
|
@@ -326,17 +299,6 @@ def run_crew(question, file_path):
|
|
326 |
verbose=False
|
327 |
)
|
328 |
|
329 |
-
document_analysis_agent = Agent(
|
330 |
-
role="Document Analysis Agent",
|
331 |
-
goal="Analyze document of type .xlxs, .txt, .csv, .xml, .rtf, .pdf, .md, .html, .css, .js, .py to help answer question \"{question}\"",
|
332 |
-
backstory="As an expert document analysis assistant, you analyze the document to help answer the question.",
|
333 |
-
allow_delegation=False,
|
334 |
-
llm=AGENT_MODEL,
|
335 |
-
max_iter=2,
|
336 |
-
tools=[document_analysis_tool],
|
337 |
-
verbose=False
|
338 |
-
)
|
339 |
-
|
340 |
code_generation_agent = Agent(
|
341 |
role="Code Generation Agent",
|
342 |
goal="Generate Python code and execute it to help answer question \"{question}\"",
|
@@ -387,7 +349,6 @@ def run_crew(question, file_path):
|
|
387 |
audio_analysis_agent,
|
388 |
video_analysis_agent,
|
389 |
youtube_analysis_agent,
|
390 |
-
document_analysis_agent,
|
391 |
code_generation_agent,
|
392 |
code_execution_agent],
|
393 |
manager_agent=manager_agent,
|
|
|
1 |
# References:
|
2 |
+
|
3 |
# https://docs.crewai.com/introduction
|
4 |
# https://ai.google.dev/gemini-api/docs
|
5 |
|
6 |
import os
|
7 |
+
|
8 |
from crewai import Agent, Crew, Process, Task
|
9 |
from crewai.tools import tool
|
10 |
from google import genai
|
|
|
25 |
AUDIO_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
26 |
VIDEO_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
27 |
YOUTUBE_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
|
|
28 |
CODE_GENERATION_MODEL = "gemini-2.5-flash-preview-04-17"
|
29 |
CODE_EXECUTION_MODEL = "gemini-2.5-flash-preview-04-17"
|
30 |
|
|
|
179 |
except Exception as e:
|
180 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
@tool("Code Generation Tool")
|
183 |
def code_generation_tool(question: str) -> str:
|
184 |
"""Generate and execute Python code to answer a question.
|
|
|
299 |
verbose=False
|
300 |
)
|
301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
code_generation_agent = Agent(
|
303 |
role="Code Generation Agent",
|
304 |
goal="Generate Python code and execute it to help answer question \"{question}\"",
|
|
|
349 |
audio_analysis_agent,
|
350 |
video_analysis_agent,
|
351 |
youtube_analysis_agent,
|
|
|
352 |
code_generation_agent,
|
353 |
code_execution_agent],
|
354 |
manager_agent=manager_agent,
|