diff --git a/utils/llm_utils.py b/utils/llm_utils.py index 913a4e7..0c823a7 100644 --- a/utils/llm_utils.py +++ b/utils/llm_utils.py @@ -241,13 +241,15 @@ async def call_llm(event: AstrMessageEvent, config: AstrBotConfig, context: Cont # 图片相关处理 image_urls = [] + image_processing_config = config.get("image_processing", {}) + use_image_caption = image_processing_config.get("use_image_caption", False) # 首先收集当前消息链中的图片(用户刚发送的,不受 image_count 限制) - if hasattr(event, "message_obj") and hasattr(event.message_obj, "message"): + if not use_image_caption and 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 + url = await component.convert_to_file_path() if url and url not in image_urls: image_urls.append(url) except Exception as e: @@ -255,7 +257,7 @@ async def call_llm(event: AstrMessageEvent, config: AstrBotConfig, context: Cont continue # 然后从历史消息中补充收集图片(受 image_count 限制) - history_image_count = config.get("image_processing", {}).get("image_count", 0) + history_image_count = image_processing_config.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 @@ -264,7 +266,7 @@ async def call_llm(event: AstrMessageEvent, config: AstrBotConfig, context: Cont for component in message.message: if isinstance(component, Image): try: - url = component.file or component.url + url = await component.convert_to_file_path() if url and url not in image_urls: image_urls.append(url) if len(image_urls) >= history_image_count: diff --git a/utils/message_utils.py b/utils/message_utils.py index d66dc74..7474cc1 100644 --- a/utils/message_utils.py +++ b/utils/message_utils.py @@ -1,6 +1,5 @@ from astrbot.api.all import * from typing import List, Dict, Any, Optional -import os import time from datetime import datetime from .image_caption import ImageCaptionUtils @@ -100,16 +99,8 @@ async def outline_message_list(message_list: List[BaseMessageComponent], umo: Op elif component_type == "image" or isinstance(i, Image): # 图片处理逻辑 try: - image = i.file if i.file else i.url + image = await i.convert_to_file_path() if image: - if image.startswith("file:///"): - image_path = image[8:] - if not os.path.exists(image_path): - logger.warning(f"持久化图片文件不存在: {image_path}") - outline += f"[图片: 文件不存在]" - continue - image = image_path - caption = await ImageCaptionUtils.generate_image_caption(image, umo=umo) if caption: outline += f"[图片: {caption}]"