feat:允许关闭FOCUS模式
This commit is contained in:
@@ -182,10 +182,10 @@ class BotConfig:
|
||||
|
||||
# [heartflow] # 启用启用heart_flowC(心流聊天)模式时生效, 需要填写token消耗量巨大的相关模型
|
||||
# 启用后麦麦会自主选择进入heart_flowC模式(持续一段时间), 进行长时间高质量的聊天
|
||||
enable_heart_flowC: bool = True # 是否启用heart_flowC(心流聊天, HFC)模式
|
||||
reply_trigger_threshold: float = 3.0 # 心流聊天触发阈值,越低越容易触发
|
||||
probability_decay_factor_per_second: float = 0.2 # 概率衰减因子,越大衰减越快
|
||||
default_decay_rate_per_second: float = 0.98 # 默认衰减率,越大衰减越慢
|
||||
allow_focus_mode: bool = True # 是否允许子心流进入 FOCUSED 状态
|
||||
|
||||
# sub_heart_flow_update_interval: int = 60 # 子心流更新频率,间隔 单位秒
|
||||
# sub_heart_flow_freeze_time: int = 120 # 子心流冻结时间,超过这个时间没有回复,子心流会冻结,间隔 单位秒
|
||||
@@ -417,11 +417,6 @@ class BotConfig:
|
||||
config.model_normal_probability = response_config.get(
|
||||
"model_normal_probability", config.model_normal_probability
|
||||
)
|
||||
|
||||
# 添加 enable_heart_flowC 的加载逻辑 (假设它在 [response] 部分)
|
||||
if config.INNER_VERSION in SpecifierSet(">=1.4.0"):
|
||||
config.enable_heart_flowC = response_config.get("enable_heart_flowC", config.enable_heart_flowC)
|
||||
|
||||
def heartflow(parent: dict):
|
||||
heartflow_config = parent["heartflow"]
|
||||
config.sub_heart_flow_stop_time = heartflow_config.get(
|
||||
@@ -445,6 +440,8 @@ class BotConfig:
|
||||
config.default_decay_rate_per_second = heartflow_config.get(
|
||||
"default_decay_rate_per_second", config.default_decay_rate_per_second
|
||||
)
|
||||
if config.INNER_VERSION in SpecifierSet(">=1.5.1"):
|
||||
config.allow_focus_mode = heartflow_config.get("allow_focus_mode", config.allow_focus_mode)
|
||||
|
||||
def willing(parent: dict):
|
||||
willing_config = parent["willing"]
|
||||
|
||||
@@ -264,6 +264,13 @@ class SubHeartflowManager:
|
||||
current_state = self.mai_state_info.get_current_state()
|
||||
focused_limit = current_state.get_focused_chat_max_num()
|
||||
|
||||
# --- 新增:检查是否允许进入 FOCUS 模式 --- #
|
||||
if not global_config.allow_focus_mode:
|
||||
if int(time.time()) % 60 == 0: # 每60秒输出一次日志避免刷屏
|
||||
logger.debug(f"{log_prefix} 配置不允许进入 FOCUSED 状态 (allow_focus_mode=False)")
|
||||
return # 如果不允许,直接返回
|
||||
# --- 结束新增 ---
|
||||
|
||||
logger.debug(f"{log_prefix} 当前状态 ({current_state.value}) 开始尝试提升到FOCUSED状态")
|
||||
|
||||
if int(time.time()) % 20 == 0: # 每20秒输出一次
|
||||
|
||||
@@ -213,17 +213,22 @@ async def _build_readable_messages_internal(
|
||||
original_len = len(content)
|
||||
limit = -1 # 默认不截断
|
||||
|
||||
if percentile < 0.6: # 60% 之前的消息 (即最旧的 60%)
|
||||
limit = 170
|
||||
elif percentile < 0.8: # 60% 到 80% 之前的消息 (即中间的 20%)
|
||||
limit = 250
|
||||
if percentile < 0.2: # 60% 之前的消息 (即最旧的 60%)
|
||||
limit = 50
|
||||
replace_content = "......(记不清了)"
|
||||
elif percentile < 0.5: # 60% 之前的消息 (即最旧的 60%)
|
||||
limit = 100
|
||||
replace_content = "......(有点记不清了)"
|
||||
elif percentile < 0.7: # 60% 到 80% 之前的消息 (即中间的 20%)
|
||||
limit = 200
|
||||
replace_content = "......(内容太长了)"
|
||||
elif percentile < 1.0: # 80% 到 100% 之前的消息 (即较新的 20%)
|
||||
limit = 500
|
||||
# 最新的 20% (理论上 percentile 会趋近 1,但这里不需要显式处理,因为 limit 默认为 -1)
|
||||
limit = 300
|
||||
replace_content = "......(太长了)"
|
||||
|
||||
truncated_content = content
|
||||
if limit > 0 and original_len > limit:
|
||||
truncated_content = f"{content[:limit]}......(内容太长)"
|
||||
truncated_content = f"{content[:limit]}{replace_content}"
|
||||
|
||||
message_details.append((timestamp, name, truncated_content))
|
||||
else:
|
||||
@@ -343,7 +348,7 @@ async def build_readable_messages(
|
||||
messages_before_mark, replace_bot_name, merge_messages, timestamp_mode, truncate
|
||||
)
|
||||
formatted_after, _ = await _build_readable_messages_internal(
|
||||
messages_after_mark, replace_bot_name, merge_messages, timestamp_mode, truncate
|
||||
messages_after_mark, replace_bot_name, merge_messages, timestamp_mode,
|
||||
)
|
||||
|
||||
readable_read_mark = translate_timestamp_to_human_readable(read_mark, mode=timestamp_mode)
|
||||
|
||||
Reference in New Issue
Block a user