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 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"):