fix: 把完整消息拆成单个字符模拟流式输出
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Has been cancelled

This commit is contained in:
2026-05-07 01:58:29 +08:00
parent 2160dbced0
commit c5ea93b754

View File

@@ -189,12 +189,26 @@ class AIAgentService:
} }
# 处理普通 token # 处理普通 token
elif token_content: elif token_content:
yield { # 如果内容较长,拆成单个字符模拟流式效果
"type": "llm_token", if len(token_content) > 1:
"node": node_name, import asyncio
"token": token_content, for char in token_content:
"reasoning_token": reasoning_token yield {
} "type": "llm_token",
"node": node_name,
"token": char,
"reasoning_token": reasoning_token
}
# 短暂暂停,模拟打字效果
await asyncio.sleep(0.01)
else:
# 内容较短,直接发送
yield {
"type": "llm_token",
"node": node_name,
"token": token_content,
"reasoning_token": reasoning_token
}
# 返回更新后的 current_node # 返回更新后的 current_node
yield {"type": "_update_state", "current_node": new_current_node} yield {"type": "_update_state", "current_node": new_current_node}