Update crew.py
Browse files
crew.py
CHANGED
|
@@ -208,12 +208,12 @@ def run_crew(question, file_path):
|
|
| 208 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 209 |
|
| 210 |
@tool("Code Generation Tool")
|
| 211 |
-
def code_generation_tool(question: str,
|
| 212 |
-
"""Given a question and
|
| 213 |
|
| 214 |
Args:
|
| 215 |
question (str): Question to answer
|
| 216 |
-
|
| 217 |
|
| 218 |
Returns:
|
| 219 |
str: Answer to the question
|
|
@@ -223,9 +223,11 @@ def run_crew(question, file_path):
|
|
| 223 |
try:
|
| 224 |
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
| 225 |
|
|
|
|
|
|
|
| 226 |
response = client.models.generate_content(
|
| 227 |
model=CODE_GENERATION_MODEL,
|
| 228 |
-
contents=[f"{question}\n{
|
| 229 |
config=types.GenerateContentConfig(
|
| 230 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
| 231 |
),
|
|
@@ -339,7 +341,7 @@ def run_crew(question, file_path):
|
|
| 339 |
|
| 340 |
code_generation_agent = Agent(
|
| 341 |
role="Code Generation Agent",
|
| 342 |
-
goal="Given a question and
|
| 343 |
backstory="As an expert Python code generation assistant, you generate and execute code to answer the question.",
|
| 344 |
allow_delegation=False,
|
| 345 |
llm=AGENT_MODEL,
|
|
@@ -373,15 +375,15 @@ def run_crew(question, file_path):
|
|
| 373 |
|
| 374 |
manager_task = Task(
|
| 375 |
agent=manager_agent,
|
| 376 |
-
description="Answer the following question. If needed, delegate to one of your coworkers
|
| 377 |
-
"- Web Search Agent requires a question only
|
| 378 |
-
"- Image Analysis Agent requires a question and **.png, .jpeg, .webp, .heic, or .heif image file
|
| 379 |
-
"- Audio Analysis Agent requires a question and **.wav, .mp3, .aiff, .aac, .ogg, or .flac audio file
|
| 380 |
-
"- Video Analysis Agent requires a question and **.mp4, .mpeg, .mov, .avi, .x-flv, .mpg, .webm, .wmv, or .3gpp video file
|
| 381 |
-
"- Document Analysis Agent requires a question and **.pdf, .txt, .html, css, .js, .md, .xml, or .rtf document file
|
| 382 |
-
"- YouTube Analysis Agent requires a question and **YouTube URL
|
| 383 |
-
"- Code Generation Agent requires a question and
|
| 384 |
-
"- Code Execution Agent requires a question and **.py Python file
|
| 385 |
"Question: {question}",
|
| 386 |
expected_output="The answer to the question."
|
| 387 |
)
|
|
@@ -405,12 +407,7 @@ def run_crew(question, file_path):
|
|
| 405 |
# Process
|
| 406 |
|
| 407 |
if file_path:
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
if file_data:
|
| 411 |
-
question = f"{question} JSON data: {file_data}" # sandbox contraints
|
| 412 |
-
else:
|
| 413 |
-
question = f"{question} File path: {file_path}."
|
| 414 |
|
| 415 |
initial_answer = crew.kickoff(inputs={"question": question})
|
| 416 |
final_answer = get_final_answer(FINAL_ANSWER_MODEL, question, str(initial_answer))
|
|
|
|
| 208 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 209 |
|
| 210 |
@tool("Code Generation Tool")
|
| 211 |
+
def code_generation_tool(question: str, file_path: str) -> str:
|
| 212 |
+
"""Given a question and data file, generate and execute code to answer the question.
|
| 213 |
|
| 214 |
Args:
|
| 215 |
question (str): Question to answer
|
| 216 |
+
file_path (str): The data file path
|
| 217 |
|
| 218 |
Returns:
|
| 219 |
str: Answer to the question
|
|
|
|
| 223 |
try:
|
| 224 |
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
| 225 |
|
| 226 |
+
file_data = read_file(file_path)
|
| 227 |
+
|
| 228 |
response = client.models.generate_content(
|
| 229 |
model=CODE_GENERATION_MODEL,
|
| 230 |
+
contents=[f"{question}\n{file_data}"],
|
| 231 |
config=types.GenerateContentConfig(
|
| 232 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
| 233 |
),
|
|
|
|
| 341 |
|
| 342 |
code_generation_agent = Agent(
|
| 343 |
role="Code Generation Agent",
|
| 344 |
+
goal="Given a question and data file, generate and execute code to answer the question: {question}",
|
| 345 |
backstory="As an expert Python code generation assistant, you generate and execute code to answer the question.",
|
| 346 |
allow_delegation=False,
|
| 347 |
llm=AGENT_MODEL,
|
|
|
|
| 375 |
|
| 376 |
manager_task = Task(
|
| 377 |
agent=manager_agent,
|
| 378 |
+
description="Answer the following question. If needed, delegate to one of your coworkers:\n"
|
| 379 |
+
"- Web Search Agent requires a question only.\n"
|
| 380 |
+
"- Image Analysis Agent requires a question and **.png, .jpeg, .webp, .heic, or .heif image file**.\n"
|
| 381 |
+
"- Audio Analysis Agent requires a question and **.wav, .mp3, .aiff, .aac, .ogg, or .flac audio file**.\n"
|
| 382 |
+
"- Video Analysis Agent requires a question and **.mp4, .mpeg, .mov, .avi, .x-flv, .mpg, .webm, .wmv, or .3gpp video file**.\n"
|
| 383 |
+
"- Document Analysis Agent requires a question and **.pdf, .txt, .html, css, .js, .md, .xml, or .rtf document file**.\n"
|
| 384 |
+
"- YouTube Analysis Agent requires a question and **YouTube URL**.\n"
|
| 385 |
+
"- Code Generation Agent requires a question and **.csv, .xls, .xlsx, .json, or .jsonl data file**.\n"
|
| 386 |
+
"- Code Execution Agent requires a question and **.py Python file**.\n"
|
| 387 |
"Question: {question}",
|
| 388 |
expected_output="The answer to the question."
|
| 389 |
)
|
|
|
|
| 407 |
# Process
|
| 408 |
|
| 409 |
if file_path:
|
| 410 |
+
question = f"{question} File path: {file_path}."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
initial_answer = crew.kickoff(inputs={"question": question})
|
| 413 |
final_answer = get_final_answer(FINAL_ANSWER_MODEL, question, str(initial_answer))
|