feat: 工具调用改为独立 SSE 事件并以中文状态条展示

This commit is contained in:
2026-09-20 11:45:00 +08:00
parent 9b240b35a9
commit de0bbb1a9c
9 changed files with 179 additions and 19 deletions
+18 -2
View File
@@ -57,8 +57,24 @@ async def chat_stream(
async def gen():
try:
async for chunk in svc.stream_chat(actor, thread_id, body.content):
yield {"event": "token", "data": json.dumps({"text": chunk}, ensure_ascii=False)}
async for event in svc.stream_chat(actor, thread_id, body.content):
if event.kind == "token" and event.text:
yield {
"event": "token",
"data": json.dumps({"text": event.text}, ensure_ascii=False),
}
elif event.kind == "tool":
yield {
"event": "tool",
"data": json.dumps(
{
"phase": event.phase,
"name": event.name,
"label": event.label,
},
ensure_ascii=False,
),
}
yield {"event": "done", "data": "{}"}
except LookupError as e:
yield {"event": "error", "data": json.dumps({"message": str(e)}, ensure_ascii=False)}