mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 09:09:19 +08:00
feat: 工具调用改为独立 SSE 事件并以中文状态条展示
This commit is contained in:
@@ -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)}
|
||||
|
||||
Reference in New Issue
Block a user