sandz7 commited on
Commit
6402d69
Β·
1 Parent(s): 78e5800

added proper syncs

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -246,22 +246,25 @@ async def bot_comms(message, history):
246
  gpt_outputs = []
247
  stream = generation(message, history)
248
 
249
- async for chunk in stream:
250
- if chunk is not None:
251
- if hasattr(chunk, 'choices') and chunk.choices:
252
- delta_content = chunk.choices[0].delta.get("content", "")
253
- if delta_content:
254
- gpt_outputs.append(delta_content)
 
 
 
 
 
 
255
  yield "".join(gpt_outputs)
256
- elif hasattr(chunk, 'image_url'):
257
- # Process image response
258
- image_url = chunk.image_url.get("url", "")
259
- gpt_outputs.append(f"[Image: {image_url}]")
260
- yield "".join(gpt_outputs)
261
  else:
262
- logger.debug("Chunk does not contain expected attributes.")
263
- else:
264
- logger.debug("Chunk is None.")
265
  # gpt_outputs = []
266
  # # if mode == "chatting" or mode == "":
267
  # # logger.debug("On chatting or no mode.\n\n")
 
246
  gpt_outputs = []
247
  stream = generation(message, history)
248
 
249
+ try:
250
+ async for chunk in stream:
251
+ if chunk is not None:
252
+ if hasattr(chunk, 'choices') and chunk.choices:
253
+ delta_content = chunk.choices[0].delta.get("content", "")
254
+ if delta_content:
255
+ gpt_outputs.append(delta_content)
256
+ yield "".join(gpt_outputs)
257
+ elif hasattr(chunk, 'image_url'):
258
+ # Process image response
259
+ image_url = chunk.image_url.get("url", "")
260
+ gpt_outputs.append(f"[Image: {image_url}]")
261
  yield "".join(gpt_outputs)
262
+ else:
263
+ logger.debug("Chunk does not contain expected attributes.")
 
 
 
264
  else:
265
+ logger.debug("Chunk is None.")
266
+ except StopAsyncIteration:
267
+ pass
268
  # gpt_outputs = []
269
  # # if mode == "chatting" or mode == "":
270
  # # logger.debug("On chatting or no mode.\n\n")