refactor: simplify thinking process UI and reduce noise

- Remove redundant status steps (understanding, preparing, generating)
  from SSE stream — only emit retrieved docs and reasoning content
- ThinkingProcess: only show when there's actual reasoning or docs
- Collapse header shows concise state: thinking count or doc count
- Clean up unused icon imports

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 14:26:30 +08:00
parent ecd5c7ff31
commit 19b6cdcbd8
3 changed files with 32 additions and 70 deletions
+17 -20
View File
@@ -133,37 +133,34 @@ class RAGChain:
"""流式调用(返回答案流和文档,包含思考过程)"""
import time
# 0. 思考阶段开始
start_time = time.time()
yield {"type": "thinking", "stage": "understanding", "message": "正在理解问题..."}
# 1. 检索文档
yield {"type": "thinking", "stage": "retrieving", "message": "正在检索相关知识..."}
retrieval_start = time.time()
docs = await self.retriever.ainvoke(question)
retrieval_time = time.time() - retrieval_start
# 发送检索结果 — 包含文档标题和摘要
doc_details = []
for i, doc in enumerate(docs[:5]):
metadata = doc.metadata if hasattr(doc, 'metadata') else {}
title = metadata.get("title", metadata.get("filename", f"文档 {i+1}"))
preview = doc.page_content[:100].replace('\n', ' ')
doc_details.append(f"**{title}**: {preview}...")
# 发送检索结果(只在有文档时)
if docs:
doc_details = []
for i, doc in enumerate(docs[:5]):
metadata = doc.metadata if hasattr(doc, 'metadata') else {}
title = metadata.get("title", metadata.get("filename", f"文档 {i+1}"))
preview = doc.page_content[:100].replace('\n', ' ')
doc_details.append(f"**{title}**: {preview}...")
yield {
"type": "thinking",
"stage": "retrieved",
"message": f"检索到 {len(docs)} 篇相关文档",
"doc_count": len(docs),
"time": round(retrieval_time, 2),
"details": doc_details
}
yield {
"type": "thinking",
"stage": "retrieved",
"message": f"检索到 {len(docs)} 篇相关文档",
"doc_count": len(docs),
"time": round(retrieval_time, 2),
"details": doc_details
}
context = "\n\n".join(doc.page_content for doc in docs)
# 2. 构建prompt
yield {"type": "thinking", "stage": "generating", "message": f"基于 {len(docs)} 篇文档生成回答..."}
# 2. 构建prompt并流式生成
prompt_value = await self.prompt.ainvoke({"context": context, "question": question})
messages = prompt_value.to_messages()
-8
View File
@@ -85,16 +85,8 @@ class ConversationChain:
"""流式调用(包含思考过程,捕获推理模型的真实推理内容)"""
import time
# 思考阶段
start_time = time.time()
yield {"type": "thinking", "stage": "understanding", "message": "正在理解问题..."}
# 准备历史
history_messages = self._format_history(chat_history or [])
history_count = len([m for m in (chat_history or []) if m["role"] == "user"])
yield {"type": "thinking", "stage": "preparing", "message": f"加载对话上下文({history_count} 轮历史)..." if history_count > 0 else "准备生成回答..."}
yield {"type": "thinking", "stage": "generating", "message": "正在生成回答..."}
# 直接使用原始 OpenAI SDK 捕获推理内容
prompt_value = await self.prompt.ainvoke({