fix: harden rag streaming and queue status reporting

This commit is contained in:
wren
2026-05-11 20:39:24 +08:00
parent e749abd9ed
commit 2ca44f6312
3 changed files with 71 additions and 42 deletions
@@ -77,7 +77,9 @@ async def generate_stream(
if payload == "[DONE]":
break
chunk = json.loads(payload)
delta = chunk.get("choices", [{}])[0].get("delta", {})
choices = chunk.get("choices") or []
first_choice = choices[0] if choices and isinstance(choices[0], dict) else {}
delta = first_choice.get("delta", {})
text = delta.get("content", "")
if text:
yield _sse_line(
@@ -141,4 +143,4 @@ async def generate_stream(
def _sse_line(data: dict) -> str:
return f"data: {json.dumps(data, ensure_ascii=False)}\\n\\n"
return f"data: {json.dumps(data, ensure_ascii=False)}\n\n"