bluenevus commited on
Commit
c0bc619
·
1 Parent(s): 370009c

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +5 -17
app.py CHANGED
@@ -100,21 +100,14 @@ def openai_stream_generate(prompt, file_id=None):
100
  try:
101
  logging.info("Connecting to OpenAI gpt-4.1 for streaming completion...")
102
  messages = [{"role": "user", "content": prompt}]
103
- extra_kwargs = {}
104
- if file_id:
105
- if isinstance(file_id, list):
106
- extra_kwargs["files"] = file_id
107
- logging.info(f"Passing file_id list to OpenAI ChatCompletion: {file_id}")
108
- else:
109
- extra_kwargs["files"] = [file_id]
110
- logging.info(f"Passing file_id to OpenAI ChatCompletion: {file_id}")
111
  stream = openai.ChatCompletion.create(
112
  model=OPENAI_MODEL,
113
  messages=messages,
114
  max_tokens=32768,
115
  temperature=0.2,
116
- stream=True,
117
- **extra_kwargs
118
  )
119
  for chunk in stream:
120
  if 'choices' in chunk and chunk['choices'] and 'delta' in chunk['choices'][0] and 'content' in chunk['choices'][0]['delta']:
@@ -285,13 +278,8 @@ def process_document(action, selected_filename=None, chat_input=None, selected_p
285
  def thread_proposal():
286
  try:
287
  logging.info("Connecting to OpenAI gpt-4.1 for proposal streaming...")
288
- pass_files = []
289
- if rfp_fileid:
290
- pass_files.append(rfp_fileid)
291
- if gen_fileid:
292
- pass_files.append(gen_fileid)
293
- file_arg = pass_files if pass_files else None
294
- result = openai_stream_generate(prompt, file_id=file_arg[0] if file_arg else None)
295
  logging.info("Received proposal results from OpenAI.")
296
  docx_bytes = save_proposal_as_docx(result, rfp_filename)
297
  generated_docx_name = f"{os.path.splitext(rfp_filename)[0]}_{os.path.splitext(generated_docname)[0]}_proposal.docx"
 
100
  try:
101
  logging.info("Connecting to OpenAI gpt-4.1 for streaming completion...")
102
  messages = [{"role": "user", "content": prompt}]
103
+ # The OpenAI ChatCompletion API does NOT accept a file_id/files argument for completions.
104
+ # For now, just ignore file_id and rely on prompt content/context.
 
 
 
 
 
 
105
  stream = openai.ChatCompletion.create(
106
  model=OPENAI_MODEL,
107
  messages=messages,
108
  max_tokens=32768,
109
  temperature=0.2,
110
+ stream=True
 
111
  )
112
  for chunk in stream:
113
  if 'choices' in chunk and chunk['choices'] and 'delta' in chunk['choices'][0] and 'content' in chunk['choices'][0]['delta']:
 
278
  def thread_proposal():
279
  try:
280
  logging.info("Connecting to OpenAI gpt-4.1 for proposal streaming...")
281
+ # No file_id support for ChatCompletion, so ignore files here.
282
+ result = openai_stream_generate(prompt)
 
 
 
 
 
283
  logging.info("Received proposal results from OpenAI.")
284
  docx_bytes = save_proposal_as_docx(result, rfp_filename)
285
  generated_docx_name = f"{os.path.splitext(rfp_filename)[0]}_{os.path.splitext(generated_docname)[0]}_proposal.docx"