bluenevus commited on
Commit
646f721
·
1 Parent(s): f921f06

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -64,7 +64,7 @@ def openai_stream_generate(prompt, file_id=None):
64
  if file_id:
65
  extra_kwargs["files"] = [file_id]
66
  logging.info(f"Passing file_id to OpenAI ChatCompletion: {file_id}")
67
- stream = openai.chat.completions.create(
68
  model=OPENAI_MODEL,
69
  messages=messages,
70
  max_tokens=64000,
@@ -73,8 +73,8 @@ def openai_stream_generate(prompt, file_id=None):
73
  **extra_kwargs
74
  )
75
  for chunk in stream:
76
- if hasattr(chunk, 'choices') and chunk.choices and hasattr(chunk.choices[0].delta, 'content'):
77
- piece = chunk.choices[0].delta.content
78
  if piece:
79
  result_text.append(piece)
80
  logging.info("Received response from OpenAI streaming.")
@@ -241,7 +241,6 @@ def process_document(action, selected_filename=None, chat_input=None, selected_p
241
  def thread_proposal():
242
  try:
243
  logging.info("Connecting to OpenAI gpt-4.1 for proposal streaming...")
244
- # Attach both files if available and not None
245
  pass_files = []
246
  if rfp_fileid:
247
  pass_files.append(rfp_fileid)
 
64
  if file_id:
65
  extra_kwargs["files"] = [file_id]
66
  logging.info(f"Passing file_id to OpenAI ChatCompletion: {file_id}")
67
+ stream = openai.ChatCompletion.create(
68
  model=OPENAI_MODEL,
69
  messages=messages,
70
  max_tokens=64000,
 
73
  **extra_kwargs
74
  )
75
  for chunk in stream:
76
+ if 'choices' in chunk and chunk['choices'] and 'delta' in chunk['choices'][0] and 'content' in chunk['choices'][0]['delta']:
77
+ piece = chunk['choices'][0]['delta']['content']
78
  if piece:
79
  result_text.append(piece)
80
  logging.info("Received response from OpenAI streaming.")
 
241
  def thread_proposal():
242
  try:
243
  logging.info("Connecting to OpenAI gpt-4.1 for proposal streaming...")
 
244
  pass_files = []
245
  if rfp_fileid:
246
  pass_files.append(rfp_fileid)