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