迁移:1515cef(fix:必要性修复)
This commit is contained in:
@@ -245,8 +245,9 @@ class HeartFChatting:
|
|||||||
# 统一使用 _should_process_messages 判断是否应该处理
|
# 统一使用 _should_process_messages 判断是否应该处理
|
||||||
should_process,interest_value = await self._should_process_messages(recent_messages if has_new_messages else None)
|
should_process,interest_value = await self._should_process_messages(recent_messages if has_new_messages else None)
|
||||||
if should_process:
|
if should_process:
|
||||||
earliest_message_data = recent_messages[0]
|
#earliest_message_data = recent_messages[0]
|
||||||
self.last_read_time = earliest_message_data.get("time")
|
#self.last_read_time = earliest_message_data.get("time")
|
||||||
|
self.context.last_read_time = time.time()
|
||||||
await self.cycle_processor.observe(interest_value = interest_value)
|
await self.cycle_processor.observe(interest_value = interest_value)
|
||||||
else:
|
else:
|
||||||
# Normal模式:消息数量不足,等待
|
# Normal模式:消息数量不足,等待
|
||||||
@@ -430,6 +431,8 @@ class HeartFChatting:
|
|||||||
logger.info(
|
logger.info(
|
||||||
f"{self.context.log_prefix} 累计消息数量达到{new_message_count}条(>{modified_exit_count_threshold}),结束等待"
|
f"{self.context.log_prefix} 累计消息数量达到{new_message_count}条(>{modified_exit_count_threshold}),结束等待"
|
||||||
)
|
)
|
||||||
|
logger.info(self.context.last_read_time)
|
||||||
|
logger.info(new_message)
|
||||||
return True,total_interest/new_message_count
|
return True,total_interest/new_message_count
|
||||||
|
|
||||||
# 检查累计兴趣值
|
# 检查累计兴趣值
|
||||||
@@ -452,9 +455,9 @@ class HeartFChatting:
|
|||||||
)
|
)
|
||||||
return True,accumulated_interest/new_message_count
|
return True,accumulated_interest/new_message_count
|
||||||
# 每10秒输出一次等待状态
|
# 每10秒输出一次等待状态
|
||||||
if int(time.time() - self.last_read_time) > 0 and int(time.time() - self.last_read_time) % 10 == 0:
|
if int(time.time() - self.context.last_read_time) > 0 and int(time.time() - self.context.last_read_time) % 10 == 0:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{self.context.log_prefix} 已等待{time.time() - self.last_read_time:.0f}秒,累计{new_message_count}条消息,继续等待..."
|
f"{self.context.log_prefix} 已等待{time.time() - self.context.last_read_time:.0f}秒,累计{new_message_count}条消息,继续等待..."
|
||||||
)
|
)
|
||||||
await asyncio.sleep(0.5)
|
await asyncio.sleep(0.5)
|
||||||
|
|
||||||
|
|||||||
@@ -724,7 +724,38 @@ class EmojiManager:
|
|||||||
if not emoji.is_deleted and emoji.hash == emoji_hash:
|
if not emoji.is_deleted and emoji.hash == emoji_hash:
|
||||||
return emoji
|
return emoji
|
||||||
return None # 如果循环结束还没找到,则返回 None
|
return None # 如果循环结束还没找到,则返回 None
|
||||||
|
|
||||||
|
async def get_emoji_tag_by_hash(self, emoji_hash: str) -> Optional[str]:
|
||||||
|
"""根据哈希值获取已注册表情包的描述
|
||||||
|
|
||||||
|
Args:
|
||||||
|
emoji_hash: 表情包的哈希值
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Optional[str]: 表情包描述,如果未找到则返回None
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# 先从内存中查找
|
||||||
|
emoji = await self.get_emoji_from_manager(emoji_hash)
|
||||||
|
if emoji and emoji.emotion:
|
||||||
|
logger.info(f"[缓存命中] 从内存获取表情包描述: {emoji.emotion}...")
|
||||||
|
return emoji.emotion
|
||||||
|
|
||||||
|
# 如果内存中没有,从数据库查找
|
||||||
|
try:
|
||||||
|
emoji_record = await self.get_emoji_from_db(emoji_hash)
|
||||||
|
if emoji_record and emoji_record[0].emotion:
|
||||||
|
logger.info(f"[缓存命中] 从数据库获取表情包描述: {emoji_record.emotion[:50]}...")
|
||||||
|
return emoji_record.emotion
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"从数据库查询表情包描述时出错: {e}")
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取表情包描述失败 (Hash: {emoji_hash}): {str(e)}")
|
||||||
|
return None
|
||||||
|
|
||||||
async def get_emoji_description_by_hash(self, emoji_hash: str) -> Optional[str]:
|
async def get_emoji_description_by_hash(self, emoji_hash: str) -> Optional[str]:
|
||||||
"""根据哈希值获取已注册表情包的描述
|
"""根据哈希值获取已注册表情包的描述
|
||||||
|
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ def init_prompt():
|
|||||||
{identity_block}
|
{identity_block}
|
||||||
|
|
||||||
{custom_prompt_block}
|
{custom_prompt_block}
|
||||||
{chat_context_description},以下是具体的聊天内容
|
{chat_context_description},以下是具体的聊天内容,其中[mxxx]是消息id。
|
||||||
{chat_content_block}
|
{chat_content_block}
|
||||||
|
|
||||||
{moderation_prompt}
|
{moderation_prompt}
|
||||||
|
|
||||||
现在请你根据{by_what}选择合适的action和触发action的消息:
|
现在请你根据聊天内容和用户的最新消息选择合适的action和触发action的消息:
|
||||||
{actions_before_now_block}
|
{actions_before_now_block}
|
||||||
|
|
||||||
{no_action_block}
|
{no_action_block}
|
||||||
@@ -89,7 +89,8 @@ def init_prompt():
|
|||||||
动作描述:{action_description}
|
动作描述:{action_description}
|
||||||
{action_require}
|
{action_require}
|
||||||
{{
|
{{
|
||||||
"action": "{action_name}",{action_parameters}{target_prompt}
|
"action": "{action_name}",{action_parameters},
|
||||||
|
"target_message_id":"触发action的消息id",
|
||||||
"reason":"触发action的原因"
|
"reason":"触发action的原因"
|
||||||
}}
|
}}
|
||||||
""",
|
""",
|
||||||
@@ -188,7 +189,6 @@ class ActionPlanner:
|
|||||||
action_description=action_info.description,
|
action_description=action_info.description,
|
||||||
action_parameters=param_text,
|
action_parameters=param_text,
|
||||||
action_require=require_text,
|
action_require=require_text,
|
||||||
target_prompt=target_prompt,
|
|
||||||
)
|
)
|
||||||
return action_options_block
|
return action_options_block
|
||||||
|
|
||||||
@@ -206,6 +206,9 @@ class ActionPlanner:
|
|||||||
Returns:
|
Returns:
|
||||||
找到的原始消息字典,如果未找到则返回None
|
找到的原始消息字典,如果未找到则返回None
|
||||||
"""
|
"""
|
||||||
|
# 检测message_id 是否为纯数字
|
||||||
|
if message_id.isdigit():
|
||||||
|
message_id = f"m{message_id}"
|
||||||
for item in message_id_list:
|
for item in message_id_list:
|
||||||
if item.get("id") == message_id:
|
if item.get("id") == message_id:
|
||||||
return item.get("message")
|
return item.get("message")
|
||||||
@@ -467,8 +470,6 @@ class ActionPlanner:
|
|||||||
mentioned_bonus = "\n- 有人提到你,或者at你"
|
mentioned_bonus = "\n- 有人提到你,或者at你"
|
||||||
|
|
||||||
if mode == ChatMode.FOCUS:
|
if mode == ChatMode.FOCUS:
|
||||||
by_what = "聊天内容"
|
|
||||||
target_prompt = '\n "target_message_id":"触发action的消息id"'
|
|
||||||
no_action_block = f"""重要说明:
|
no_action_block = f"""重要说明:
|
||||||
- 'no_reply' 表示只进行不进行回复,等待合适的回复时机
|
- 'no_reply' 表示只进行不进行回复,等待合适的回复时机
|
||||||
- 当你刚刚发送了消息,没有人回复时,选择no_reply
|
- 当你刚刚发送了消息,没有人回复时,选择no_reply
|
||||||
@@ -487,8 +488,6 @@ class ActionPlanner:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
else: # NORMAL Mode
|
else: # NORMAL Mode
|
||||||
by_what = "聊天内容和用户的最新消息"
|
|
||||||
target_prompt = ""
|
|
||||||
no_action_block = f"""重要说明:
|
no_action_block = f"""重要说明:
|
||||||
- 'reply' 表示只进行普通聊天回复,不执行任何额外动作
|
- 'reply' 表示只进行普通聊天回复,不执行任何额外动作
|
||||||
- 其他action表示在普通回复的基础上,执行相应的额外动作
|
- 其他action表示在普通回复的基础上,执行相应的额外动作
|
||||||
@@ -515,7 +514,7 @@ class ActionPlanner:
|
|||||||
chat_context_description = f"你正在和 {chat_target_name} 私聊"
|
chat_context_description = f"你正在和 {chat_target_name} 私聊"
|
||||||
|
|
||||||
action_options_block = await self._build_action_options(
|
action_options_block = await self._build_action_options(
|
||||||
current_available_actions, mode, target_prompt
|
current_available_actions, mode
|
||||||
)
|
)
|
||||||
|
|
||||||
moderation_prompt_block = "请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。"
|
moderation_prompt_block = "请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。"
|
||||||
@@ -533,7 +532,6 @@ class ActionPlanner:
|
|||||||
schedule_block=schedule_block,
|
schedule_block=schedule_block,
|
||||||
mood_block=mood_block,
|
mood_block=mood_block,
|
||||||
time_block=time_block,
|
time_block=time_block,
|
||||||
by_what=by_what,
|
|
||||||
chat_context_description=chat_context_description,
|
chat_context_description=chat_context_description,
|
||||||
chat_content_block=chat_content_block,
|
chat_content_block=chat_content_block,
|
||||||
actions_before_now_block=actions_before_now_block,
|
actions_before_now_block=actions_before_now_block,
|
||||||
|
|||||||
@@ -165,10 +165,11 @@ class ImageManager:
|
|||||||
from src.chat.emoji_system.emoji_manager import get_emoji_manager
|
from src.chat.emoji_system.emoji_manager import get_emoji_manager
|
||||||
|
|
||||||
emoji_manager = get_emoji_manager()
|
emoji_manager = get_emoji_manager()
|
||||||
cached_emoji_description = await emoji_manager.get_emoji_description_by_hash(image_hash)
|
tags = await emoji_manager.get_emoji_tag_by_hash(image_hash)
|
||||||
if cached_emoji_description:
|
if tags:
|
||||||
logger.info(f"[缓存命中] 使用已注册表情包描述: {cached_emoji_description[:50]}...")
|
tag_str = ",".join(tags)
|
||||||
return cached_emoji_description
|
logger.info(f"[缓存命中] 使用已注册表情包描述: {tag_str}...")
|
||||||
|
return f"[表情包:{tag_str}]"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"查询EmojiManager时出错: {e}")
|
logger.debug(f"查询EmojiManager时出错: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user