refactor(expression_learner): 添加过滤机器人消息的功能,以优化学习过程

This commit is contained in:
Windpicker-owo
2025-11-02 11:48:33 +08:00
parent a30ee4ae8a
commit 8126ab0747

View File

@@ -182,11 +182,12 @@ class ExpressionLearner:
if time_diff < min_interval: if time_diff < min_interval:
return False return False
# 检查消息数量(只检查指定聊天流的消息) # 检查消息数量(只检查指定聊天流的消息,排除机器人自己的消息
recent_messages = await get_raw_msg_by_timestamp_with_chat_inclusive( recent_messages = await get_raw_msg_by_timestamp_with_chat_inclusive(
chat_id=self.chat_id, chat_id=self.chat_id,
timestamp_start=self.last_learning_time, timestamp_start=self.last_learning_time,
timestamp_end=time.time(), timestamp_end=time.time(),
filter_bot=True, # 过滤掉机器人自己的消息
) )
if not recent_messages or len(recent_messages) < self.min_messages_for_learning: if not recent_messages or len(recent_messages) < self.min_messages_for_learning:
@@ -506,12 +507,13 @@ class ExpressionLearner:
current_time = time.time() current_time = time.time()
# 获取上次学习时间 # 获取上次学习时间,过滤掉机器人自己的消息
random_msg: list[dict[str, Any]] | None = await get_raw_msg_by_timestamp_with_chat_inclusive( random_msg: list[dict[str, Any]] | None = await get_raw_msg_by_timestamp_with_chat_inclusive(
chat_id=self.chat_id, chat_id=self.chat_id,
timestamp_start=self.last_learning_time, timestamp_start=self.last_learning_time,
timestamp_end=current_time, timestamp_end=current_time,
limit=num, limit=num,
filter_bot=True, # 过滤掉机器人自己的消息,防止学习自己的表达方式
) )
# print(random_msg) # print(random_msg)