fix(langchain-chat): R1 思考过程显示 + 选题推荐放宽 + RAG 诊断日志
三个独立修复 / 排查:
1. R1 思考过程不显示
- 根因: chat_test.py 等 <think> 开标签出现才进思考态,但 R1
流式输出本来就在 reasoning 态启动,永远不出 <think>,所有
reasoning 全部当 text 走到答案区
- 修法: 引入 r1_thinking_done 状态机,默认在思考态,
看到 </think> 切换;R1-70B 直连本地代理 deepseek-r1
(官方 deepseek-reasoner 把 reasoning 放独立字段,旧版
callback 取不到)
- 结果验证: "1+1" → 269 think + 40 text,思考与答案正确分流
2. 选题推荐场景拒答 + chat 模板标记泄漏
- 根因: prompt 写死了 "你只能回答有关选题推荐的问题"
+ 直接嵌入 <|im_start|>/<|im_end|> Qwen chat 标记
- 修法: 改写 Topic Recommend Assistant prompt,删 chat 标记,
行为准则改为"沾边查询用工具回答";agent_v2 增加 strip
防守层
- 结果验证: "钢铁行业研究重点方向" → agent 调工具,不再拒答
3. 知识库召回 0 排查(数据问题,未根治)
- 根因: kb_config.py 把所有 KB(政策库/钢铁库/报告库等)
都映射到 t_policy_total_bge_new_v2,但 Milvus 里根本没有
这个 collection(实际只有 11 个 p_* 个人库 + 1 个
t_journal_article_bge_v1)
- 临时改: search_tool.py 加诊断日志 [RAG诊断] 输出每个 KB
召回数;rag_search 内 for 循环里首个 KB 空就 return 的
bug 改 continue
- 待决策: kb_config 是否把默认 KB 映射到唯一存在的
t_journal_article_bge_v1,或重建对应集合
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ LangGraph 版 Agent runner。
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from typing import AsyncIterable, List, Optional
|
||||
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
@@ -26,10 +27,20 @@ from server.chat.tools_v2 import make_tools
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
_CHAT_MARKER_RE = re.compile(r"<\|im_(?:start|end)\|>")
|
||||
|
||||
|
||||
def _strip_chat_markers(text: str) -> str:
|
||||
"""剥掉 prompt 内嵌的 Qwen chat template 标记,避免模型 echo 泄漏到答案。"""
|
||||
return _CHAT_MARKER_RE.sub("", text or "")
|
||||
|
||||
|
||||
def _build_system_prompt(user_prompt_name: str, query: str, think_content: str) -> str:
|
||||
"""复用旧版 Think Test Bak + 用户业务 prompt 的拼装逻辑,但简化为单条 system message。"""
|
||||
base = get_prompt_template("agent_chat", "Think Test Bak")
|
||||
user = get_prompt_template("llm_chat", user_prompt_name) if user_prompt_name else ""
|
||||
user = _strip_chat_markers(user)
|
||||
think_content = _strip_chat_markers(think_content)
|
||||
|
||||
parts = []
|
||||
parts.append("你是浪潮开发的智能专家。回答用户问题前可以使用工具检索资料。")
|
||||
parts.append("严格要求:")
|
||||
|
||||
Reference in New Issue
Block a user