From 49ae06ae45f26811312d118a3f8e9ac93e7ccf2d Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 7 Apr 2026 02:08:56 -0700 Subject: [PATCH] fix: strip markdown links, URLs, bold/italic from antaf response Antaf returns markdown with hyperlinks and formatting that TTS reads out as raw text. Now cleaned before sending to TTS. Co-Authored-By: Claude Opus 4.6 (1M context) --- modules/antaf/antaf_llm.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/antaf/antaf_llm.py b/modules/antaf/antaf_llm.py index a147b13..78aecf3 100644 --- a/modules/antaf/antaf_llm.py +++ b/modules/antaf/antaf_llm.py @@ -40,13 +40,24 @@ class LLMProvider(LLMProviderBase): @staticmethod def _clean_text(text): - """清理阿福返回文本中的脏数据""" + """清理阿福返回文本中的脏数据、链接、markdown""" + import re # 去掉阿福内部状态文本 junk = [ "完成资料引用", "内容生成", "正在思考", "正在搜索", ] for j in junk: text = text.replace(j, "") + # Markdown链接 [文字](url) → 只保留文字 + text = re.sub(r'\[([^\]]+)\]\([^)]+\)', r'\1', text) + # 裸URL + text = re.sub(r'https?://\S+', '', text) + # Markdown加粗 **文字** → 文字 + text = re.sub(r'\*\*([^*]+)\*\*', r'\1', text) + # Markdown斜体 *文字* → 文字 + text = re.sub(r'\*([^*]+)\*', r'\1', text) + # 多余空格 + text = re.sub(r' +', ' ', text) return text.strip() @staticmethod