feat(chat): 添加图片消息判断工具函数

增加 `is_image_message` 函数,用于根据消息字典的内容判断该消息是否为图片类型。这有助于在处理不同消息类型时,能够准确识别并分流图片消息。
This commit is contained in:
tt-P607
2025-09-01 15:44:11 +08:00
committed by Windpicker-owo
parent d86cfa90ad
commit 2dbce6a738

View File

@@ -7,7 +7,7 @@ import io
import asyncio import asyncio
import numpy as np import numpy as np
from typing import Optional, Tuple from typing import Optional, Tuple, Dict, Any
from PIL import Image from PIL import Image
from rich.traceback import install from rich.traceback import install
@@ -24,6 +24,22 @@ install(extra_lines=3)
logger = get_logger("chat_image") logger = get_logger("chat_image")
def is_image_message(message: Dict[str, Any]) -> bool:
"""
判断消息是否为图片消息
Args:
message: 消息字典
Returns:
bool: 是否为图片消息
"""
return message.get("type") == "image" or (
isinstance(message.get("content"), dict) and
message["content"].get("type") == "image"
)
class ImageManager: class ImageManager:
_instance = None _instance = None
IMAGE_DIR = "data" # 图像存储根目录 IMAGE_DIR = "data" # 图像存储根目录