bstraehle commited on
Commit
9d7947a
·
verified ·
1 Parent(s): 9e680bf

Update crew.py

Browse files
Files changed (1) hide show
  1. crew.py +13 -9
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, file_path: str) -> str:
224
- """Given a question and data file, generate and execute code to answer the question.
225
 
226
  Args:
227
  question (str): Question to answer
228
- file_path (str): The data file path
229
 
230
  Returns:
231
  str: Answer to the question
@@ -234,10 +234,6 @@ def run_crew(question, file_path):
234
  RuntimeError: If processing fails"""
235
  try:
236
  client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
237
-
238
- file_data = read_file_json(file_path)
239
-
240
- print(f"=> File data:\n{file_data}")
241
 
242
  response = client.models.generate_content(
243
  model=CODE_GENERATION_MODEL,
@@ -396,7 +392,7 @@ def run_crew(question, file_path):
396
  "- Video Analysis Agent requires a question and **.mp4, .mpeg, .mov, .avi, .x-flv, .mpg, .webm, .wmv, or .3gpp video file**.\n"
397
  "- Document Analysis Agent requires a question and **.docx, .pptx, .pdf, .txt, .html, css, .js, .md, .xml, or .rtf document file**.\n"
398
  "- YouTube Analysis Agent requires a question and **YouTube URL**.\n"
399
- "- Code Generation Agent requires a question and **.csv, .xls, .xlsx, .json, or .jsonl data file**.\n"
400
  "- Code Execution Agent requires a question and **.py Python file**.\n"
401
  "Question: {question}",
402
  expected_output="The answer to the question."
@@ -421,7 +417,15 @@ def run_crew(question, file_path):
421
  # Process
422
 
423
  if file_path:
424
- question = f"{question} File path: {file_path}."
 
 
 
 
 
 
 
 
425
 
426
  answer = crew.kickoff(inputs={"question": question})
427
  final_answer = get_final_answer(FINAL_ANSWER_MODEL, question, str(answer))
 
220
  raise RuntimeError(f"Processing failed: {str(e)}")
221
 
222
  @tool("Code Generation Tool")
223
+ def code_generation_tool(question: str, file_data: str) -> str:
224
+ """Given a question and file data, generate and execute code to answer the question.
225
 
226
  Args:
227
  question (str): Question to answer
228
+ file_path (str): The file data
229
 
230
  Returns:
231
  str: Answer to the question
 
234
  RuntimeError: If processing fails"""
235
  try:
236
  client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
 
 
 
 
237
 
238
  response = client.models.generate_content(
239
  model=CODE_GENERATION_MODEL,
 
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 **file data**.\n"
396
  "- Code Execution Agent requires a question and **.py Python file**.\n"
397
  "Question: {question}",
398
  expected_output="The answer to the question."
 
417
  # Process
418
 
419
  if file_path:
420
+ if is_ext(file_path, ".csv") or
421
+ is_ext(file_path, ".xls") or
422
+ is_ext(file_path, ".xlsx") or
423
+ is_ext(file_path, ".json") or
424
+ is_ext(file_path, ".jsonl"):
425
+ file_data = read_file_json(file_path)
426
+ question = f"{question} File data: {file_data}."
427
+ else:
428
+ question = f"{question} File path: {file_path}."
429
 
430
  answer = crew.kickoff(inputs={"question": question})
431
  final_answer = get_final_answer(FINAL_ANSWER_MODEL, question, str(answer))