fix: harden rag streaming and queue status reporting
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user