From 63a769540aec9c8d68e23fc180c90a40e6a86438 Mon Sep 17 00:00:00 2001 From: lacerate551 <128470311+lacerate551@users.noreply.github.com> Date: Sun, 21 Jun 2026 00:44:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(rag):=20=E5=9B=BE=E7=89=87=E5=8D=A0?= =?UTF-8?q?=E4=BD=8D=E7=AC=A6=E6=AD=A3=E5=88=99=E6=89=A9=E5=B1=95=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=20LLM=20=E8=BE=93=E5=87=BA=E7=9A=84=20placeholder=20U?= =?UTF-8?q?RL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LLM 有时输出 ![图片](https://via.placeholder.com/150) 而非 ![图片](图片URL),正则尾部增加 https?:// 匹配覆盖。 --- api/chat_routes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/chat_routes.py b/api/chat_routes.py index 3373e1a..3ee13c2 100644 --- a/api/chat_routes.py +++ b/api/chat_routes.py @@ -1417,10 +1417,11 @@ def _replace_table_image_placeholders(answer: str, images: List[Dict]) -> str: parts.append('[图片]') # 图片用完了 return ' '.join(parts) - # !? — 可选前导 !(LLM 有时加) - # \[(\d+)?张?图片\] — [图片] 或 [3张图片](张 可选) - # (?:\(图片URL\))? — 可选的 LLM 从上下文复制的假 URL - result = re.sub(r'!?\[(\d+)?张?图片\](?:\(图片URL\))?', _replacer, answer) + # !? — 可选前导 !(LLM 有时加) + # \[(\d+)?张?图片\] — [图片] 或 [3张图片](张 可选) + # (?:\((?:图片URL|https?://[^)]+)\))? — 可选的 LLM 从上下文复制的假 URL + # 匹配 (图片URL) 或 (https://via.placeholder.com/150) 等 + result = re.sub(r'!?\[(\d+)?张?图片\](?:\((?:图片URL|https?://[^)]+)\))?', _replacer, answer) if replaced_count > 0: logger.info(f"[图片占位符替换] 替换了 {replaced_count}/{len(images)} 个图片为 markdown 图片语法") return result