feat(chat): 添加图片消息判断工具函数
增加 `is_image_message` 函数,用于根据消息字典的内容判断该消息是否为图片类型。这有助于在处理不同消息类型时,能够准确识别并分流图片消息。
This commit is contained in:
@@ -7,7 +7,7 @@ import io
|
||||
import asyncio
|
||||
import numpy as np
|
||||
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional, Tuple, Dict, Any
|
||||
from PIL import Image
|
||||
from rich.traceback import install
|
||||
|
||||
@@ -24,6 +24,22 @@ install(extra_lines=3)
|
||||
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:
|
||||
_instance = None
|
||||
IMAGE_DIR = "data" # 图像存储根目录
|
||||
|
||||
Reference in New Issue
Block a user