From ed7af06555f402da8f3d97258c0c377dae3dfcb5 Mon Sep 17 00:00:00 2001 From: liuwei Date: Fri, 24 Apr 2026 14:47:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20ai=5Fauto=5Fresponse=20?= =?UTF-8?q?=E6=80=9D=E8=80=83=E6=A0=87=E7=AD=BE=E6=B3=84=E9=9C=B2=E6=B8=85?= =?UTF-8?q?=E6=B4=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增强 LLMResultParser 对 思考块的清洗能力 - 兼容完整的 ... 返回 - 兼容只有开标签、没有闭合标签的不完整思考块,避免将 Thinking about your request 透传到群里 - 兼容单独残留的 碎片标签 --- plugins/ai_auto_response/core/llm_result_parser.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/ai_auto_response/core/llm_result_parser.py b/plugins/ai_auto_response/core/llm_result_parser.py index b372aac..8c98847 100644 --- a/plugins/ai_auto_response/core/llm_result_parser.py +++ b/plugins/ai_auto_response/core/llm_result_parser.py @@ -151,7 +151,16 @@ class LLMResultParser: @staticmethod def _strip_think_blocks(text: str) -> str: value = str(text or "") - value = re.sub(r".*?", "", value, flags=re.IGNORECASE | re.DOTALL) + # 兼容完整的思考块: + # 某些模型会返回 ...,这类内容绝不能继续往下游透传。 + value = re.sub(r"]*>.*?", "", value, flags=re.IGNORECASE | re.DOTALL) + # 兼容不完整的思考块: + # 实际线上偶发只返回了开标签和中间内容,没有闭合 。 + # 这种情况下如果只匹配完整标签,会把“\nThinking about your request”原样漏出去。 + # 这里把“从开标签开始到文本结束”的尾巴整个清掉。 + value = re.sub(r"]*>.*$", "", value, flags=re.IGNORECASE | re.DOTALL) + # 兼容少数模型把关闭标签单独吐出来的情况,避免残留 之类碎片。 + value = re.sub(r"", "", value, flags=re.IGNORECASE) return value @classmethod