feat:为no_reply增加正反馈
This commit is contained in:
@@ -155,12 +155,15 @@ class HeartFCMessageReceiver:
|
|||||||
groupinfo = message.message_info.group_info
|
groupinfo = message.message_info.group_info
|
||||||
userinfo = message.message_info.user_info
|
userinfo = message.message_info.user_info
|
||||||
messageinfo = message.message_info
|
messageinfo = message.message_info
|
||||||
|
|
||||||
|
|
||||||
chat = await get_chat_manager().get_or_create_stream(
|
chat = await get_chat_manager().get_or_create_stream(
|
||||||
platform=messageinfo.platform,
|
platform=messageinfo.platform,
|
||||||
user_info=userinfo,
|
user_info=userinfo,
|
||||||
group_info=groupinfo,
|
group_info=groupinfo,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await self.storage.store_message(message, chat)
|
||||||
|
|
||||||
subheartflow = await heartflow.get_or_create_subheartflow(chat.stream_id)
|
subheartflow = await heartflow.get_or_create_subheartflow(chat.stream_id)
|
||||||
message.update_chat_stream(chat)
|
message.update_chat_stream(chat)
|
||||||
@@ -170,10 +173,7 @@ class HeartFCMessageReceiver:
|
|||||||
message.raw_message, chat, userinfo
|
message.raw_message, chat, userinfo
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
# 5. 消息存储
|
|
||||||
# print(f"message: {message.message_info.time}")
|
|
||||||
await self.storage.store_message(message, chat)
|
|
||||||
|
|
||||||
# 6. 兴趣度计算与更新
|
# 6. 兴趣度计算与更新
|
||||||
interested_rate, is_mentioned = await _calculate_interest(message)
|
interested_rate, is_mentioned = await _calculate_interest(message)
|
||||||
|
|||||||
@@ -76,10 +76,14 @@ class ChattingObservation(Observation):
|
|||||||
|
|
||||||
self.last_observe_time = datetime.now().timestamp()
|
self.last_observe_time = datetime.now().timestamp()
|
||||||
initial_messages = get_raw_msg_before_timestamp_with_chat(self.chat_id, self.last_observe_time, 10)
|
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.last_observe_time = initial_messages[-1]["time"] if initial_messages else self.last_observe_time
|
||||||
self.talking_message = initial_messages
|
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 = 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:
|
def to_dict(self) -> dict:
|
||||||
"""将观察对象转换为可序列化的字典"""
|
"""将观察对象转换为可序列化的字典"""
|
||||||
|
|||||||
@@ -599,6 +599,7 @@ def build_readable_messages(
|
|||||||
copy_messages.sort(key=lambda x: x.get("time", 0))
|
copy_messages.sort(key=lambda x: x.get("time", 0))
|
||||||
|
|
||||||
if read_mark <= 0:
|
if read_mark <= 0:
|
||||||
|
print(f"read_mark: {read_mark}")
|
||||||
# 没有有效的 read_mark,直接格式化所有消息
|
# 没有有效的 read_mark,直接格式化所有消息
|
||||||
formatted_string, _, pic_id_mapping, _ = _build_readable_messages_internal(
|
formatted_string, _, pic_id_mapping, _ = _build_readable_messages_internal(
|
||||||
copy_messages, replace_bot_name, merge_messages, timestamp_mode, truncate
|
copy_messages, replace_bot_name, merge_messages, timestamp_mode, truncate
|
||||||
|
|||||||
@@ -291,23 +291,31 @@ class NoReplyAction(BaseAction):
|
|||||||
over_count = bot_message_count - talk_frequency_threshold
|
over_count = bot_message_count - talk_frequency_threshold
|
||||||
|
|
||||||
# 根据超过的数量设置不同的提示词
|
# 根据超过的数量设置不同的提示词
|
||||||
if over_count <= 5:
|
if over_count <= 3:
|
||||||
frequency_block = "你感觉稍微有些累,回复的有点多了。\n"
|
frequency_block = "你感觉稍微有些累,回复的有点多了。\n"
|
||||||
elif over_count <= 10:
|
elif over_count <= 5:
|
||||||
frequency_block = "你今天说话比较多,感觉有点疲惫,想要稍微休息一下。\n"
|
frequency_block = "你今天说话比较多,感觉有点疲惫,想要稍微休息一下。\n"
|
||||||
elif over_count <= 20:
|
|
||||||
frequency_block = (
|
|
||||||
"你发现自己说话太多了,感觉很累,需要好好休息一下,不想频繁回复。\n"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
frequency_block = "你感到非常疲惫,今天话说得太多了,想要安静一会儿,除非有重要的事情否则不想回复。\n"
|
frequency_block = (
|
||||||
|
"你发现自己说话太多了,感觉很累,想要安静一会儿,除非有重要的事情否则不想回复。\n"
|
||||||
|
)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{self.log_prefix} 过去10分钟发言{bot_message_count}条,超过阈值{talk_frequency_threshold},添加疲惫提示"
|
f"{self.log_prefix} 过去10分钟发言{bot_message_count}条,超过阈值{talk_frequency_threshold},添加疲惫提示"
|
||||||
)
|
)
|
||||||
else:
|
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(
|
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:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user