fix(ai_auto_response): clean think noise from parsed fields

This commit is contained in:
liuwei
2026-04-10 17:06:13 +08:00
parent 52392edcc0
commit 4e7a8e6798

View File

@@ -75,12 +75,12 @@ class LLMResultParser:
data = cls.extract_json_object(response)
if isinstance(data, dict):
should_reply = cls.coerce_bool(data.get("should_reply", True), default=True)
reply_mode = str(data.get("reply_mode", fallback_reply_mode) or fallback_reply_mode)
reply_mode = cls._clean_text_field(data.get("reply_mode", fallback_reply_mode))
if reply_mode not in {"social_short", "qa_fast", "qa_with_context"}:
reply_mode = fallback_reply_mode
reply = str(data.get("reply", "") or "").strip()
reply_mode = fallback_reply_mode if fallback_reply_mode in {"social_short", "qa_fast", "qa_with_context"} else "social_short"
reply = cls._clean_text_field(data.get("reply", ""))
topic_id = str(data.get("topic_id", "") or "latest:0").strip() or "latest:0"
topic_summary = str(data.get("topic_summary", "") or fallback_topic).strip()
topic_summary = cls._clean_text_field(data.get("topic_summary", "") or fallback_topic)
if current_content and cls.looks_like_prompt_echo(reply, current_content):
should_reply = False
reply = ""
@@ -154,6 +154,12 @@ class LLMResultParser:
value = re.sub(r"<think>.*?</think>", "", value, flags=re.IGNORECASE | re.DOTALL)
return value
@classmethod
def _clean_text_field(cls, value: Any) -> str:
text = str(value or "")
text = cls._strip_think_blocks(text)
return text.strip()
@staticmethod
def _unwrap_result_payload(text: str) -> str:
raw = str(text or "").strip()