Fix chunk handling in Backend_Api to ensure content is properly yielded as a string

This commit is contained in:
hlohaus
2026-04-06 03:06:46 +02:00
parent 1325c4d9f9
commit cd8c096f68
+2 -2
View File
@@ -186,8 +186,8 @@ class Backend_Api(Api):
stream=True,
)
for chunk in response:
if chunk.choices and chunk.choices[0].delta:
yield f"data: {json.dumps({'type': 'content', 'content': chunk.choices[0].delta.content})}\n\n"
if chunk.choices[0].delta.content:
yield f"data: {json.dumps({'type': 'content', 'content': str(chunk.choices[0].delta.content)})}\n\n"
except GeneratorExit:
pass
except Exception as e: