feat: 新增 react_reason 循环思考过程的流式显示
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m38s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m38s
- 修改 react_nodes.py,在推理时保存推理过程到状态 - 修改 agent_service.py,检测并发送推理过程事件到前端 - 修改 chat_area.py,接收并显示推理过程 - 修改 useChat.ts,添加对推理过程事件的支持
This commit is contained in:
@@ -139,7 +139,26 @@ def _handle_ai_response():
|
||||
import logging
|
||||
logging.debug(f"[Frontend Stream] 收到事件: {event_type}, 完整内容: {repr(event)}")
|
||||
|
||||
# 1. 处理各种控制事件,显示到思考过程
|
||||
# 1. 处理推理过程事件 - 这是新增的!
|
||||
if event_type == "react_reasoning":
|
||||
step = event.get("step", 1)
|
||||
action = event.get("action", "unknown")
|
||||
confidence = event.get("confidence", 0)
|
||||
reasoning = event.get("reasoning", "")
|
||||
|
||||
logging.info(f"[Frontend] 收到推理过程 #{step}: {action}")
|
||||
|
||||
# 添加到思考过程
|
||||
api_thought += f"\n\n🤔 **第 {step} 次推理**"
|
||||
api_thought += f"\n 📋 决策: {action}"
|
||||
api_thought += f"\n 📊 置信度: {confidence:.2f}"
|
||||
if reasoning:
|
||||
api_thought += f"\n 💭 推理过程: {reasoning}"
|
||||
|
||||
display_thought = api_thought
|
||||
thought_placeholder.info(f"**🤔 思考过程 (正在思考...)**\n\n{display_thought}▌")
|
||||
|
||||
# 2. 处理各种控制事件,显示到思考过程
|
||||
if event_type == "intent_classified":
|
||||
intent = event.get("intent", "unknown")
|
||||
confidence = event.get("confidence", 0)
|
||||
|
||||
@@ -181,8 +181,20 @@ export function useChat() {
|
||||
try {
|
||||
for await (const event of apiClient.chatStream(text, threadId, model)) {
|
||||
switch (event.type) {
|
||||
// 新增:处理推理过程事件
|
||||
case "react_reasoning":
|
||||
console.log(`🤔 收到推理过程 #${event.step}: ${event.action}`);
|
||||
updateCurrentMessage({
|
||||
reasoning: (currentMessageRef.current?.reasoning || "") +
|
||||
`\n\n🤔 **第 ${event.step} 次推理**` +
|
||||
`\n 📋 决策: ${event.action}` +
|
||||
`\n 📊 置信度: ${event.confidence.toFixed(2)}` +
|
||||
(event.reasoning ? `\n 💭 推理过程: ${event.reasoning}` : "")
|
||||
});
|
||||
break;
|
||||
|
||||
// 新增:处理意图分类事件
|
||||
case 'intent_classified':
|
||||
case "intent_classified":
|
||||
console.log(`🧠 意图识别: ${event.intent} (置信度: ${event.confidence})`);
|
||||
setLastIntent({
|
||||
intent: event.intent,
|
||||
|
||||
Reference in New Issue
Block a user