bstraehle commited on
Commit
226f9ae
·
verified ·
1 Parent(s): c4abfca

Update crew.py

Browse files
Files changed (1) hide show
  1. crew.py +17 -9
crew.py CHANGED
@@ -11,7 +11,7 @@ from google import genai
11
  from google.genai import types
12
  from openinference.instrumentation.crewai import CrewAIInstrumentor
13
  from phoenix.otel import register
14
- from util import read_file, read_docx, read_pptx, is_ext
15
 
16
  ## LLMs
17
 
@@ -199,14 +199,19 @@ def run_crew(question, file_path):
199
  contents = []
200
 
201
  if is_ext(file_path, ".docx"):
202
- file_data = read_docx(file_path)
203
- contents = [f"{question}\n{file_data}"]
 
204
  elif is_ext(file_path, ".pptx"):
205
- file_data = read_pptx(file_path)
206
- contents = [f"{question}\n{file_data}"]
 
207
  else:
208
  file = client.files.upload(file=file_path)
209
  contents = [file, question]
 
 
 
210
 
211
  response = client.models.generate_content(
212
  model=DOCUMENT_ANALYSIS_MODEL,
@@ -233,11 +238,16 @@ def run_crew(question, file_path):
233
  try:
234
  client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
235
 
236
- file_data = read_file(file_path)
 
 
 
 
 
237
 
238
  response = client.models.generate_content(
239
  model=CODE_GENERATION_MODEL,
240
- contents=[f"{question}\n{file_data}"],
241
  config=types.GenerateContentConfig(
242
  tools=[types.Tool(code_execution=types.ToolCodeExecution)]
243
  ),
@@ -419,8 +429,6 @@ def run_crew(question, file_path):
419
  if file_path:
420
  question = f"{question} File path: {file_path}."
421
 
422
- print(f"### Question: {question}")
423
-
424
  initial_answer = crew.kickoff(inputs={"question": question})
425
  final_answer = get_final_answer(FINAL_ANSWER_MODEL, question, str(initial_answer))
426
 
 
11
  from google.genai import types
12
  from openinference.instrumentation.crewai import CrewAIInstrumentor
13
  from phoenix.otel import register
14
+ from util import read_file_json, read_docx_text, read_pptx_text, is_ext
15
 
16
  ## LLMs
17
 
 
199
  contents = []
200
 
201
  if is_ext(file_path, ".docx"):
202
+ file_data = read_docx_text(file_path)
203
+ final_question = f"{question}\n{file_data}"
204
+ contents = [final_question]
205
  elif is_ext(file_path, ".pptx"):
206
+ file_data = read_pptx_text(file_path)
207
+ final_question = f"{question}\n{file_data}"
208
+ contents = [final_question]
209
  else:
210
  file = client.files.upload(file=file_path)
211
  contents = [file, question]
212
+
213
+ print(f"### Initial question: {question}")
214
+ print(f"### Final question: {final_question}")
215
 
216
  response = client.models.generate_content(
217
  model=DOCUMENT_ANALYSIS_MODEL,
 
238
  try:
239
  client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
240
 
241
+ file_data = read_file_json(file_path)
242
+
243
+ final_question = f"{question}\n{file_data}"
244
+
245
+ print(f"### Initial question: {question}")
246
+ print(f"### Final question: {final_question}")
247
 
248
  response = client.models.generate_content(
249
  model=CODE_GENERATION_MODEL,
250
+ contents=[final_question],
251
  config=types.GenerateContentConfig(
252
  tools=[types.Tool(code_execution=types.ToolCodeExecution)]
253
  ),
 
429
  if file_path:
430
  question = f"{question} File path: {file_path}."
431
 
 
 
432
  initial_answer = crew.kickoff(inputs={"question": question})
433
  final_answer = get_final_answer(FINAL_ANSWER_MODEL, question, str(initial_answer))
434