Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions utils/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,23 @@ 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:
logger.warning(f"处理当前消息图片URL时出错: {e}")
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

Expand All @@ -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:
Expand Down
11 changes: 1 addition & 10 deletions utils/message_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}]"
Expand Down