fix:修复表情包描述进入prompt问题

This commit is contained in:
SengokuCola
2025-08-09 21:16:57 +08:00
parent d279b0982d
commit b57671b639
7 changed files with 21 additions and 59 deletions

View File

@@ -308,7 +308,6 @@ class HeartFChatting:
return loop_info, reply_text, cycle_timers
async def _observe(self, message_data: Optional[Dict[str, Any]] = None) -> bool:
# sourcery skip: hoist-statement-from-if, merge-comparisons, reintroduce-else
if not message_data:
message_data = {}
action_type = "no_action"

View File

@@ -370,7 +370,7 @@ class MessageProcessBase(Message):
return "[图片,网卡了加载不出来]"
elif seg.type == "emoji":
if isinstance(seg.data, str):
return await get_image_manager().get_emoji_description(seg.data)
return await get_image_manager().get_emoji_tag(seg.data)
return "[表情,网卡了加载不出来]"
elif seg.type == "voice":
if isinstance(seg.data, str):
@@ -400,34 +400,6 @@ class MessageProcessBase(Message):
return f"[{timestamp}]{name} 说:{self.processed_plain_text}\n"
@dataclass
class MessageThinking(MessageProcessBase):
"""思考状态的消息类"""
def __init__(
self,
message_id: str,
chat_stream: "ChatStream",
bot_user_info: UserInfo,
reply: Optional["MessageRecv"] = None,
thinking_start_time: float = 0,
timestamp: Optional[float] = None,
):
# 调用父类初始化,传递时间戳
super().__init__(
message_id=message_id,
chat_stream=chat_stream,
bot_user_info=bot_user_info,
message_segment=None, # 思考状态不需要消息段
reply=reply,
thinking_start_time=thinking_start_time,
timestamp=timestamp,
)
# 思考状态特有属性
self.interrupt = False
@dataclass
class MessageSending(MessageProcessBase):
"""发送状态的消息类"""
@@ -488,26 +460,6 @@ class MessageSending(MessageProcessBase):
if self.message_segment:
self.processed_plain_text = await self._process_message_segments(self.message_segment)
# @classmethod
# def from_thinking(
# cls,
# thinking: MessageThinking,
# message_segment: Seg,
# is_head: bool = False,
# is_emoji: bool = False,
# ) -> "MessageSending":
# """从思考状态消息创建发送状态消息"""
# return cls(
# message_id=thinking.message_info.message_id,
# chat_stream=thinking.chat_stream,
# message_segment=message_segment,
# bot_user_info=thinking.message_info.user_info,
# reply=thinking.reply,
# is_head=is_head,
# is_emoji=is_emoji,
# sender_info=None,
# )
def to_dict(self):
ret = super().to_dict()
ret["message_info"]["user_info"] = self.chat_stream.user_info.to_dict()

View File

@@ -92,6 +92,18 @@ class ImageManager:
desc_obj.save()
except Exception as e:
logger.error(f"保存描述到数据库失败 (Peewee): {str(e)}")
async def get_emoji_tag(self, image_base64: str) -> str:
from src.chat.emoji_system.emoji_manager import get_emoji_manager
emoji_manager = get_emoji_manager()
if isinstance(image_base64, str):
image_base64 = image_base64.encode("ascii", errors="ignore").decode("ascii")
image_bytes = base64.b64decode(image_base64)
image_hash = hashlib.md5(image_bytes).hexdigest()
emoji = await emoji_manager.get_emoji_from_manager(image_hash)
emotion_list = emoji.emotion
tag_str = ",".join(emotion_list)
return f"[表情包:{tag_str}]"
async def get_emoji_description(self, image_base64: str) -> str:
"""获取表情包描述优先使用Emoji表中的缓存数据"""
@@ -107,7 +119,6 @@ class ImageManager:
# 优先使用EmojiManager查询已注册表情包的描述
try:
from src.chat.emoji_system.emoji_manager import get_emoji_manager
emoji_manager = get_emoji_manager()
cached_emoji_description = await emoji_manager.get_emoji_description_by_hash(image_hash)
if cached_emoji_description:

View File

@@ -57,7 +57,7 @@ TEMPLATE_DIR = os.path.join(PROJECT_ROOT, "template")
# 考虑到实际上配置文件中的mai_version是不会自动更新的,所以采用硬编码
# 对该字段的更新请严格参照语义化版本规范https://semver.org/lang/zh-CN/
MMC_VERSION = "0.10.0-snapshot.4"
MMC_VERSION = "0.10.0-snapshot.5"
def get_key_comment(toml_table, key):