added proper syncs
Browse files
app.py
CHANGED
@@ -246,22 +246,25 @@ async def bot_comms(message, history):
|
|
246 |
gpt_outputs = []
|
247 |
stream = generation(message, history)
|
248 |
|
249 |
-
|
250 |
-
|
251 |
-
if
|
252 |
-
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
yield "".join(gpt_outputs)
|
256 |
-
|
257 |
-
|
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
|
263 |
-
|
264 |
-
|
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")
|