temp: 不显示react_reason的调试信息
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 6m28s

This commit is contained in:
2026-05-01 13:27:20 +08:00
parent 4f6b9c096a
commit 3051a34ce7

View File

@@ -194,7 +194,7 @@ def _handle_ai_response():
# 2. 本地模型 <think> 标签模式 (如 Gemma, 本地 DeepSeek)
if "<think>" in raw_text:
think_match = re.search(r'<think>(.*?)(</think>|$)', raw_text, re.DOTALL)
think_match = re.search(r"<think>(.*?)(</think>|$)", raw_text, re.DOTALL)
if think_match:
display_thought = think_match.group(1).strip()
is_thinking = "</think>" not in raw_text
@@ -202,14 +202,14 @@ def _handle_ai_response():
# 正文部分应该是除去了整个 <think>...</think> 块后的剩余内容
# 注意:流式输出时可能 </think> 还没出来,此时也要把 <think> 到末尾的部分剔除,只显示正文
if is_thinking:
display_text = re.sub(r'<think>.*$', '', raw_text, flags=re.DOTALL).strip()
display_text = re.sub(r"<think>.*$", "", raw_text, flags=re.DOTALL).strip()
else:
display_text = re.sub(r'<think>.*?</think>', '', raw_text, flags=re.DOTALL).strip()
display_text = re.sub(r"<think>.*?</think>", "", raw_text, flags=re.DOTALL).strip()
elif "<" in raw_text and "think" in raw_text and not raw_text.startswith("<think>"):
# 处理一种特殊情况:模型正在输出 <think> 标签的过程中(例如刚输出了 "<thin"
# 此时正则表达式匹配不到完整的 "<think>",会导致残缺的标签显示在正文中
# 我们做个简单拦截:如果在开头发现了不完整的标签,暂时不显示它
if re.match(r'^<t[hink>]*$', raw_text):
if re.match(r"^<t[hink>]*$", raw_text):
display_text = ""
is_thinking = True
@@ -229,14 +229,6 @@ def _handle_ai_response():
if display_text or not is_thinking:
cursor = "" if not is_thinking else ""
message_placeholder.markdown(display_text + cursor)
else:
# 对于非 llm_call/fallback 的 token记录到思考过程用于调试
token = str(event.get("token", ""))
reasoning_token = str(event.get("reasoning_token", ""))
if token:
api_thought += f"\n[调试] 节点 {node_name} 输出: {repr(token)}"
display_thought = api_thought
thought_placeholder.info(f"**🤔 思考过程 (正在思考...)**\n\n{display_thought}")
# 2. 处理状态更新 (节点完成、工具结果等)
elif event_type == "state_update":