fix:优化了normal的频率控制
This commit is contained in:
@@ -40,7 +40,7 @@ def init_prompt():
|
|||||||
{identity}
|
{identity}
|
||||||
|
|
||||||
你需要使用合适的语言习惯和句法,参考聊天内容,组织一条日常且口语化的回复。注意不要复读你说过的话。
|
你需要使用合适的语言习惯和句法,参考聊天内容,组织一条日常且口语化的回复。注意不要复读你说过的话。
|
||||||
{config_expression_style}
|
{config_expression_style}。回复不要浮夸,不要用夸张修辞,平淡一些。
|
||||||
{keywords_reaction_prompt}
|
{keywords_reaction_prompt}
|
||||||
请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。
|
请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。
|
||||||
不要浮夸,不要夸张修辞,请注意不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,at或 @等 )。只输出一条回复就好。
|
不要浮夸,不要夸张修辞,请注意不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,at或 @等 )。只输出一条回复就好。
|
||||||
@@ -63,7 +63,7 @@ def init_prompt():
|
|||||||
{identity},
|
{identity},
|
||||||
你需要使用合适的语法和句法,参考聊天内容,组织一条日常且口语化的回复。注意不要复读你说过的话。
|
你需要使用合适的语法和句法,参考聊天内容,组织一条日常且口语化的回复。注意不要复读你说过的话。
|
||||||
|
|
||||||
{config_expression_style}
|
{config_expression_style}。回复不要浮夸,不要用夸张修辞,平淡一些。
|
||||||
{keywords_reaction_prompt}
|
{keywords_reaction_prompt}
|
||||||
请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。
|
请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。
|
||||||
不要浮夸,不要夸张修辞,请注意不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,at或 @等 )。只输出一条回复就好。
|
不要浮夸,不要夸张修辞,请注意不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,at或 @等 )。只输出一条回复就好。
|
||||||
|
|||||||
@@ -542,10 +542,7 @@ class NormalChat:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# 处理消息
|
# 处理消息
|
||||||
if time.time() - self.start_time > 300:
|
self.adjust_reply_frequency()
|
||||||
self.adjust_reply_frequency(duration=300 / 60)
|
|
||||||
else:
|
|
||||||
self.adjust_reply_frequency(duration=(time.time() - self.start_time) / 60)
|
|
||||||
|
|
||||||
await self.normal_response(
|
await self.normal_response(
|
||||||
message=message,
|
message=message,
|
||||||
@@ -989,47 +986,73 @@ class NormalChat:
|
|||||||
# 返回最近的limit条记录,按时间倒序排列
|
# 返回最近的limit条记录,按时间倒序排列
|
||||||
return sorted(self.recent_replies[-limit:], key=lambda x: x["time"], reverse=True)
|
return sorted(self.recent_replies[-limit:], key=lambda x: x["time"], reverse=True)
|
||||||
|
|
||||||
def adjust_reply_frequency(self, duration: int = 10):
|
def adjust_reply_frequency(self):
|
||||||
"""
|
"""
|
||||||
调整回复频率
|
根据预设规则动态调整回复意愿(willing_amplifier)。
|
||||||
|
- 评估周期:10分钟
|
||||||
|
- 目标频率:由 global_config.chat.talk_frequency 定义(例如 1条/分钟)
|
||||||
|
- 调整逻辑:
|
||||||
|
- 0条回复 -> 5.0x 意愿
|
||||||
|
- 达到目标回复数 -> 1.0x 意愿(基准)
|
||||||
|
- 达到目标2倍回复数 -> 0.2x 意愿
|
||||||
|
- 中间值线性变化
|
||||||
|
- 增益抑制:如果最近5分钟回复过快,则不增加意愿。
|
||||||
"""
|
"""
|
||||||
# 获取最近30分钟内的消息统计
|
# --- 1. 定义参数 ---
|
||||||
|
evaluation_minutes = 10.0
|
||||||
|
target_replies_per_min = global_config.chat.talk_frequency # 目标频率:e.g. 1条/分钟
|
||||||
|
target_replies_in_window = target_replies_per_min * evaluation_minutes # 10分钟内的目标回复数
|
||||||
|
|
||||||
stats = get_recent_message_stats(minutes=duration, chat_id=self.stream_id)
|
if target_replies_in_window <= 0:
|
||||||
bot_reply_count = stats["bot_reply_count"]
|
logger.debug(f"[{self.stream_name}] 目标回复频率为0或负数,不调整意愿放大器。")
|
||||||
|
|
||||||
total_message_count = stats["total_message_count"]
|
|
||||||
if total_message_count == 0:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# --- 2. 获取近期统计数据 ---
|
||||||
|
stats_10_min = get_recent_message_stats(minutes=evaluation_minutes, chat_id=self.stream_id)
|
||||||
|
bot_reply_count_10_min = stats_10_min["bot_reply_count"]
|
||||||
|
|
||||||
|
# --- 3. 计算新的意愿放大器 (willing_amplifier) ---
|
||||||
|
# 基于回复数在 [0, target*2] 区间内进行分段线性映射
|
||||||
|
if bot_reply_count_10_min <= target_replies_in_window:
|
||||||
|
# 在 [0, 目标数] 区间,意愿从 5.0 线性下降到 1.0
|
||||||
|
new_amplifier = 5.0 + (bot_reply_count_10_min - 0) * (1.0 - 5.0) / (target_replies_in_window - 0)
|
||||||
|
elif bot_reply_count_10_min <= target_replies_in_window * 2:
|
||||||
|
# 在 [目标数, 目标数*2] 区间,意愿从 1.0 线性下降到 0.2
|
||||||
|
over_target_cap = target_replies_in_window * 2
|
||||||
|
new_amplifier = 1.0 + (bot_reply_count_10_min - target_replies_in_window) * (
|
||||||
|
0.2 - 1.0
|
||||||
|
) / (over_target_cap - target_replies_in_window)
|
||||||
|
else:
|
||||||
|
# 超过目标数2倍,直接设为最小值
|
||||||
|
new_amplifier = 0.2
|
||||||
|
|
||||||
|
# --- 4. 检查是否需要抑制增益 ---
|
||||||
|
# "如果邻近5分钟内,回复数量 > 频率/2,就不再进行增益"
|
||||||
|
suppress_gain = False
|
||||||
|
if new_amplifier > self.willing_amplifier: # 仅在计算结果为增益时检查
|
||||||
|
suppression_minutes = 5.0
|
||||||
|
# 5分钟内目标回复数的一半
|
||||||
|
suppression_threshold = (target_replies_per_min / 2) * suppression_minutes # e.g., (1/2)*5 = 2.5
|
||||||
|
stats_5_min = get_recent_message_stats(minutes=suppression_minutes, chat_id=self.stream_id)
|
||||||
|
bot_reply_count_5_min = stats_5_min["bot_reply_count"]
|
||||||
|
|
||||||
|
if bot_reply_count_5_min > suppression_threshold:
|
||||||
|
suppress_gain = True
|
||||||
|
|
||||||
|
# --- 5. 更新意愿放大器 ---
|
||||||
|
if suppress_gain:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"[{self.stream_name}]({self.willing_amplifier}) 最近{duration}分钟 回复数量: {bot_reply_count},消息总数: {total_message_count}"
|
f"[{self.stream_name}] 回复增益被抑制。最近5分钟内回复数 ({bot_reply_count_5_min}) "
|
||||||
|
f"> 阈值 ({suppression_threshold:.1f})。意愿放大器保持在 {self.willing_amplifier:.2f}"
|
||||||
)
|
)
|
||||||
|
# 不做任何改动
|
||||||
# 计算回复频率
|
else:
|
||||||
_reply_frequency = bot_reply_count / total_message_count
|
# 限制最终值在 [0.2, 5.0] 范围内
|
||||||
|
self.willing_amplifier = max(0.2, min(5.0, new_amplifier))
|
||||||
differ = global_config.chat.talk_frequency - (bot_reply_count / duration)
|
|
||||||
|
|
||||||
# 如果回复频率低于0.5,增加回复概率
|
|
||||||
if differ > 0.1:
|
|
||||||
mapped = 1 + (differ - 0.1) * 4 / 0.9
|
|
||||||
mapped = max(1, min(5, mapped))
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"[{self.stream_name}] 回复频率低于{global_config.chat.talk_frequency},增加回复概率,differ={differ:.3f},映射值={mapped:.2f}"
|
f"[{self.stream_name}] 调整回复意愿。10分钟内回复: {bot_reply_count_10_min} (目标: {target_replies_in_window:.0f}) -> "
|
||||||
|
f"意愿放大器更新为: {self.willing_amplifier:.2f}"
|
||||||
)
|
)
|
||||||
self.willing_amplifier += mapped * 0.1 # 你可以根据实际需要调整系数
|
|
||||||
elif differ < -0.1:
|
|
||||||
mapped = 1 - (differ + 0.1) * 4 / 0.9
|
|
||||||
mapped = max(1, min(5, mapped))
|
|
||||||
logger.debug(
|
|
||||||
f"[{self.stream_name}] 回复频率高于{global_config.chat.talk_frequency},减少回复概率,differ={differ:.3f},映射值={mapped:.2f}"
|
|
||||||
)
|
|
||||||
self.willing_amplifier -= mapped * 0.1
|
|
||||||
|
|
||||||
if self.willing_amplifier > 5:
|
|
||||||
self.willing_amplifier = 5
|
|
||||||
elif self.willing_amplifier < 0.1:
|
|
||||||
self.willing_amplifier = 0.1
|
|
||||||
|
|
||||||
def _get_sender_name(self, message: MessageRecv) -> str:
|
def _get_sender_name(self, message: MessageRecv) -> str:
|
||||||
"""获取发送者名称,用于planner"""
|
"""获取发送者名称,用于planner"""
|
||||||
|
|||||||
Reference in New Issue
Block a user