Update crew.py
Browse files
crew.py
CHANGED
|
@@ -220,12 +220,12 @@ def run_crew(question, file_path):
|
|
| 220 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 221 |
|
| 222 |
@tool("Code Generation Tool")
|
| 223 |
-
def code_generation_tool(question: str,
|
| 224 |
-
"""Given a question and
|
| 225 |
|
| 226 |
Args:
|
| 227 |
question (str): Question to answer
|
| 228 |
-
file_path (str): The
|
| 229 |
|
| 230 |
Returns:
|
| 231 |
str: Answer to the question
|
|
@@ -237,7 +237,7 @@ def run_crew(question, file_path):
|
|
| 237 |
|
| 238 |
response = client.models.generate_content(
|
| 239 |
model=CODE_GENERATION_MODEL,
|
| 240 |
-
contents=[f"{question}\n{
|
| 241 |
config=types.GenerateContentConfig(
|
| 242 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
| 243 |
),
|
|
@@ -392,8 +392,8 @@ def run_crew(question, file_path):
|
|
| 392 |
"- Video Analysis Agent requires a question and **.mp4, .mpeg, .mov, .avi, .x-flv, .mpg, .webm, .wmv, or .3gpp video file**.\n"
|
| 393 |
"- Document Analysis Agent requires a question and **.docx, .pptx, .pdf, .txt, .html, css, .js, .md, .xml, or .rtf document file**.\n"
|
| 394 |
"- YouTube Analysis Agent requires a question and **YouTube URL**.\n"
|
| 395 |
-
"- Code Generation Agent requires a question and **
|
| 396 |
-
"- Code Execution Agent requires a question and
|
| 397 |
"Question: {question}",
|
| 398 |
expected_output="The answer to the question."
|
| 399 |
)
|
|
@@ -416,18 +416,21 @@ def run_crew(question, file_path):
|
|
| 416 |
|
| 417 |
# Process
|
| 418 |
|
|
|
|
|
|
|
| 419 |
if file_path:
|
| 420 |
if is_ext(file_path, ".csv") or is_ext(file_path, ".xls") or is_ext(file_path, ".xlsx") or is_ext(file_path, ".json") or is_ext(file_path, ".jsonl"):
|
| 421 |
-
|
| 422 |
-
|
| 423 |
else:
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
final_answer = get_final_answer(FINAL_ANSWER_MODEL,
|
| 428 |
|
| 429 |
-
print(f"=>
|
| 430 |
-
print(f"=>
|
|
|
|
| 431 |
print(f"=> Final answer: {final_answer}")
|
| 432 |
|
| 433 |
return final_answer
|
|
|
|
| 220 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 221 |
|
| 222 |
@tool("Code Generation Tool")
|
| 223 |
+
def code_generation_tool(question: str, json_data: str) -> str:
|
| 224 |
+
"""Given a question and json data, generate and execute code to answer the question.
|
| 225 |
|
| 226 |
Args:
|
| 227 |
question (str): Question to answer
|
| 228 |
+
file_path (str): The JSON data
|
| 229 |
|
| 230 |
Returns:
|
| 231 |
str: Answer to the question
|
|
|
|
| 237 |
|
| 238 |
response = client.models.generate_content(
|
| 239 |
model=CODE_GENERATION_MODEL,
|
| 240 |
+
contents=[f"{question}\n{json_data}"],
|
| 241 |
config=types.GenerateContentConfig(
|
| 242 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
| 243 |
),
|
|
|
|
| 392 |
"- Video Analysis Agent requires a question and **.mp4, .mpeg, .mov, .avi, .x-flv, .mpg, .webm, .wmv, or .3gpp video file**.\n"
|
| 393 |
"- Document Analysis Agent requires a question and **.docx, .pptx, .pdf, .txt, .html, css, .js, .md, .xml, or .rtf document file**.\n"
|
| 394 |
"- YouTube Analysis Agent requires a question and **YouTube URL**.\n"
|
| 395 |
+
"- Code Generation Agent requires a question and **JSON data**.\n"
|
| 396 |
+
"- Code Execution Agent requires a question and **Python file**.\n"
|
| 397 |
"Question: {question}",
|
| 398 |
expected_output="The answer to the question."
|
| 399 |
)
|
|
|
|
| 416 |
|
| 417 |
# Process
|
| 418 |
|
| 419 |
+
final_question = question
|
| 420 |
+
|
| 421 |
if file_path:
|
| 422 |
if is_ext(file_path, ".csv") or is_ext(file_path, ".xls") or is_ext(file_path, ".xlsx") or is_ext(file_path, ".json") or is_ext(file_path, ".jsonl"):
|
| 423 |
+
json_data = read_file_json(file_path)
|
| 424 |
+
final_question = f"{question}\nJSON data:\n{json_data}."
|
| 425 |
else:
|
| 426 |
+
final_question = f"{question}\nFile path:\n{file_path}."
|
| 427 |
+
|
| 428 |
+
initial_answer = crew.kickoff(inputs={"question": final_question})
|
| 429 |
+
final_answer = get_final_answer(FINAL_ANSWER_MODEL, initial_question, str(initial_answer))
|
| 430 |
|
| 431 |
+
print(f"=> Initial question: {question}")
|
| 432 |
+
print(f"=> Final question: {final_question}")
|
| 433 |
+
print(f"=> Initial answer: {initial_answer}")
|
| 434 |
print(f"=> Final answer: {final_answer}")
|
| 435 |
|
| 436 |
return final_answer
|