feat:为no_reply增加正反馈

This commit is contained in:
SengokuCola
2025-06-23 22:43:17 +08:00
parent ab861d4854
commit 44a556c179
4 changed files with 26 additions and 13 deletions

View File

@@ -156,12 +156,15 @@ class HeartFCMessageReceiver:
userinfo = message.message_info.user_info
messageinfo = message.message_info
chat = await get_chat_manager().get_or_create_stream(
platform=messageinfo.platform,
user_info=userinfo,
group_info=groupinfo,
)
await self.storage.store_message(message, chat)
subheartflow = await heartflow.get_or_create_subheartflow(chat.stream_id)
message.update_chat_stream(chat)
@@ -171,9 +174,6 @@ class HeartFCMessageReceiver:
):
return
# 5. 消息存储
# print(f"message: {message.message_info.time}")
await self.storage.store_message(message, chat)
# 6. 兴趣度计算与更新
interested_rate, is_mentioned = await _calculate_interest(message)

View File

@@ -76,10 +76,14 @@ class ChattingObservation(Observation):
self.last_observe_time = datetime.now().timestamp()
initial_messages = get_raw_msg_before_timestamp_with_chat(self.chat_id, self.last_observe_time, 10)
print(f"initial_messages: {initial_messages}")
initial_messages_short = get_raw_msg_before_timestamp_with_chat(self.chat_id, self.last_observe_time, 5)
self.last_observe_time = initial_messages[-1]["time"] if initial_messages else self.last_observe_time
self.talking_message = initial_messages
self.talking_message_short = initial_messages_short
self.talking_message_str = build_readable_messages(self.talking_message, show_actions=True)
self.talking_message_str_truncate = build_readable_messages(self.talking_message, show_actions=True, truncate=True)
self.talking_message_str_short = build_readable_messages(self.talking_message_short, show_actions=True)
self.talking_message_str_truncate_short = build_readable_messages(self.talking_message_short, show_actions=True, truncate=True)
def to_dict(self) -> dict:
"""将观察对象转换为可序列化的字典"""

View File

@@ -599,6 +599,7 @@ def build_readable_messages(
copy_messages.sort(key=lambda x: x.get("time", 0))
if read_mark <= 0:
print(f"read_mark: {read_mark}")
# 没有有效的 read_mark直接格式化所有消息
formatted_string, _, pic_id_mapping, _ = _build_readable_messages_internal(
copy_messages, replace_bot_name, merge_messages, timestamp_mode, truncate

View File

@@ -291,23 +291,31 @@ class NoReplyAction(BaseAction):
over_count = bot_message_count - talk_frequency_threshold
# 根据超过的数量设置不同的提示词
if over_count <= 5:
if over_count <= 3:
frequency_block = "你感觉稍微有些累,回复的有点多了。\n"
elif over_count <= 10:
elif over_count <= 5:
frequency_block = "你今天说话比较多,感觉有点疲惫,想要稍微休息一下。\n"
elif over_count <= 20:
frequency_block = (
"你发现自己说话太多了,感觉很累,需要好好休息一下,不想频繁回复。\n"
)
else:
frequency_block = "你感到非常疲惫,今天话说得太多了,想要安静一会儿,除非有重要的事情否则不想回复。\n"
frequency_block = (
"你发现自己说话太多了,感觉很累,想要安静一会儿,除非有重要的事情否则不想回复。\n"
)
logger.info(
f"{self.log_prefix} 过去10分钟发言{bot_message_count}条,超过阈值{talk_frequency_threshold},添加疲惫提示"
)
else:
# 回复次数少时的正向提示
under_count = talk_frequency_threshold - bot_message_count
if under_count >= talk_frequency_threshold * 0.8: # 回复很少少于20%
frequency_block = "你感觉精力充沛,状态很好。\n"
elif under_count >= talk_frequency_threshold * 0.5: # 回复较少少于50%
frequency_block = "你感觉状态不错。\n"
else: # 刚好达到阈值
frequency_block = ""
logger.info(
f"{self.log_prefix} 过去10分钟发言{bot_message_count}条,未超过阈值{talk_frequency_threshold}"
f"{self.log_prefix} 过去10分钟发言{bot_message_count}条,未超过阈值{talk_frequency_threshold},添加正向提示"
)
except Exception as e: