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