From e2eb777ba41b571171266be9343fb73518e51a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=E2=82=82=E2=82=82H=E2=82=82=E2=82=85NO=E2=82=86?= <96930391+Sisyphbaous-DT-Project@users.noreply.github.com> Date: Mon, 1 Jun 2026 13:33:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20SpectreCore=E6=8F=92=E4=BB=B6call=5F?= =?UTF-8?q?llm()=E9=81=97=E6=BC=8F=E5=BD=93=E5=89=8D=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=AF=BC=E8=87=B4=E6=A8=A1=E5=9E=8B=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=AF=BB=E5=8F=96=E7=94=A8=E6=88=B7=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=9A=84=E5=9B=BE=E7=89=87=20(#96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:LLMUtils.call_llm() 中 image_urls 收集逻辑存在两个缺陷: 1. image_count 默认值为 0,导致整个图片收集块被 if image_count 短路跳过; 2. 即使配置了 image_count > 0,遍历范围也仅限于 history_messages,不包含 当前消息链(用户刚发送的消息),当前消息通过 outline_message_list() 转为 纯文本后图片 URL 丢失。 修复:在收集历史图片之前,先从当前消息链 (event.message_obj.message) 中 提取 Image 组件加入 image_urls,不受 image_count 限制;历史图片收集改为 补充逻辑,受 image_count 限制,并添加 URL 去重防止重复传递。 --- utils/llm_utils.py | 54 +++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/utils/llm_utils.py b/utils/llm_utils.py index 3713f43..913a4e7 100644 --- a/utils/llm_utils.py +++ b/utils/llm_utils.py @@ -241,28 +241,42 @@ async def call_llm(event: AstrMessageEvent, config: AstrBotConfig, context: Cont # 图片相关处理 image_urls = [] - if image_count := config.get("image_processing", {}).get("image_count", 0): - if history_messages: - messages_to_show = history_messages[-history_limit:] if len(history_messages) > history_limit else history_messages - for message in reversed(messages_to_show): - if hasattr(message, "message") and message.message: - for component in message.message: - if isinstance(component, Image): - try: - url = component.file or component.url - if url: - image_urls.append(url) - if len(image_urls) >= image_count: - break - except Exception as e: - logger.warning(f"处理图片URL时出错: {e}") - continue - if len(image_urls) >= image_count: - break + # 首先收集当前消息链中的图片(用户刚发送的,不受 image_count 限制) + if hasattr(event, "message_obj") and hasattr(event.message_obj, "message"): + for component in event.message_obj.message: + if isinstance(component, Image): + try: + url = component.file or component.url + if url and url not in image_urls: + image_urls.append(url) + except Exception as e: + logger.warning(f"处理当前消息图片URL时出错: {e}") + continue + + # 然后从历史消息中补充收集图片(受 image_count 限制) + history_image_count = config.get("image_processing", {}).get("image_count", 0) + if history_image_count and history_messages: + messages_to_show = history_messages[-history_limit:] if len(history_messages) > history_limit else history_messages + + for message in reversed(messages_to_show): + if hasattr(message, "message") and message.message: + for component in message.message: + if isinstance(component, Image): + try: + url = component.file or component.url + if url and url not in image_urls: + image_urls.append(url) + if len(image_urls) >= history_image_count: + break + except Exception as e: + logger.warning(f"处理历史消息图片URL时出错: {e}") + continue + if len(image_urls) >= history_image_count: + break - if image_urls: - system_prompt += f"\n\n已经按照从晚到早的顺序为你提供了聊天记录中的{len(image_urls)}张图片,你可以直接查看并理解它们。这些图片出现在聊天记录中。" + if image_urls: + system_prompt += f"\n\n已经按照从晚到早的顺序为你提供了聊天记录中的{len(image_urls)}张图片,你可以直接查看并理解它们。这些图片出现在聊天记录中。" # prompt 只保留用户当前消息,使用 MessageUtils 确保图片被转述 if hasattr(event, "message_obj") and hasattr(event.message_obj, "message"): From 76dbe7c6110c7af5344197ab1b16ff9898969d8b Mon Sep 17 00:00:00 2001 From: 23q3 <2335125256@qq.com> Date: Mon, 1 Jun 2026 13:47:44 +0800 Subject: [PATCH 2/2] release: v2.1.12 --- README.md | 6 +++--- changelogs/v2.1.12.md | 1 + main.py | 2 +- metadata.yaml | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 changelogs/v2.1.12.md diff --git a/README.md b/README.md index d279d88..9674540 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ![SpectreCore](https://avatars.githubusercontent.com/u/129108081?s=48&v=4) -[![version](https://img.shields.io/badge/version-v2.1.11-blue.svg?style=flat-square)](https://github.com/23q3/astrbot_plugin_SpectreCore) +[![version](https://img.shields.io/badge/version-v2.1.12-blue.svg?style=flat-square)](https://github.com/23q3/astrbot_plugin_SpectreCore) [![license](https://img.shields.io/badge/license-AGPL--3.0-green.svg?style=flat-square)](LICENSE) [![author](https://img.shields.io/badge/author-23q3-orange.svg?style=flat-square)](https://github.com/23q3) @@ -70,9 +70,9 @@ SpectreCore (影芯) 是一个为 AstrBot 设计的高级群聊互动插件, ## 📋 最新版本 -### v2.1.11 (2026-02-24) +### v2.1.12 (2026-06-01) -- 🐛 **修复机器人私聊消息存储路径错误** - 修复私聊中bot消息存入错误路径,导致用户看不到bot回复历史的问题 [#87](https://github.com/23q3/astrbot_plugin_SpectreCore/issues/87)[#90](https://github.com/23q3/astrbot_plugin_SpectreCore/pull/90) @Hola-Gracias +- 🐛 **修复图片遗漏** - call_llm()遗漏当前消息图片导致模型无法读取用户上传的图片 [#96](https://github.com/23q3/astrbot_plugin_SpectreCore/issues/96) ## ⚠️ 注意事项 diff --git a/changelogs/v2.1.12.md b/changelogs/v2.1.12.md new file mode 100644 index 0000000..f548393 --- /dev/null +++ b/changelogs/v2.1.12.md @@ -0,0 +1 @@ +- 🐛 **修复图片遗漏** - call_llm()遗漏当前消息图片导致模型无法读取用户上传的图片 [#96](https://github.com/23q3/astrbot_plugin_SpectreCore/issues/96) diff --git a/main.py b/main.py index 7a4bd43..a260278 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ "spectrecore", "23q3", "使大模型更好的主动回复群聊中的消息,带来生动和沉浸的群聊对话体验", - "2.1.11", + "2.1.12", "https://github.com/23q3/astrbot_plugin_SpectreCore" ) class SpectreCore(Star): diff --git a/metadata.yaml b/metadata.yaml index 78d60d7..72cffd1 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -1,7 +1,7 @@ name: spectrecore # 这是你的插件的唯一识别名。 desc: 使大模型更好的主动回复群聊中的消息,带来生动和沉浸的群聊对话体验 # 插件简短描述 help: 自动检测群聊消息并让AI模型进行回复,让群聊更加生动有趣。 # 插件的帮助信息 -version: v2.1.11 # 插件版本号。格式:v1.1.1 或者 v1.1 +version: v2.1.12 # 插件版本号。格式:v1.1.1 或者 v1.1 author: 23q3 # 作者 repo: https://github.com/23q3/astrbot_plugin_SpectreCore # 插件的仓库地址 display_name: 🌟 SpectreCore