🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -156,8 +156,12 @@ class InterestMonitorApp:
|
|||||||
self.mind_text_scroll = tk.Scrollbar(self.frame_mind_history)
|
self.mind_text_scroll = tk.Scrollbar(self.frame_mind_history)
|
||||||
self.mind_text_scroll.pack(side=tk.RIGHT, fill=tk.Y)
|
self.mind_text_scroll.pack(side=tk.RIGHT, fill=tk.Y)
|
||||||
self.mind_text = tk.Text(
|
self.mind_text = tk.Text(
|
||||||
self.frame_mind_history, height=25, state="disabled", wrap="word", font=("微软雅黑", 12),
|
self.frame_mind_history,
|
||||||
yscrollcommand=self.mind_text_scroll.set
|
height=25,
|
||||||
|
state="disabled",
|
||||||
|
wrap="word",
|
||||||
|
font=("微软雅黑", 12),
|
||||||
|
yscrollcommand=self.mind_text_scroll.set,
|
||||||
)
|
)
|
||||||
self.mind_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=1, padx=5, pady=5)
|
self.mind_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=1, padx=5, pady=5)
|
||||||
self.mind_text_scroll.config(command=self.mind_text.yview)
|
self.mind_text_scroll.config(command=self.mind_text.yview)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ MAX_FOCUSED_CHAT_NUM_FOCUSED = 40
|
|||||||
|
|
||||||
# -- 状态定义 --
|
# -- 状态定义 --
|
||||||
|
|
||||||
|
|
||||||
class MaiState(enum.Enum):
|
class MaiState(enum.Enum):
|
||||||
"""
|
"""
|
||||||
聊天状态:
|
聊天状态:
|
||||||
@@ -204,7 +205,9 @@ class MaiStateManager:
|
|||||||
if time_limit_exceeded:
|
if time_limit_exceeded:
|
||||||
next_state_candidate = random.choices(choices_list, weights=weights, k=1)[0]
|
next_state_candidate = random.choices(choices_list, weights=weights, k=1)[0]
|
||||||
resolved_candidate = _resolve_offline(next_state_candidate)
|
resolved_candidate = _resolve_offline(next_state_candidate)
|
||||||
logger.debug(f"规则{rule_id}:时间到,随机选择 {next_state_candidate.value},resolve 为 {resolved_candidate.value}")
|
logger.debug(
|
||||||
|
f"规则{rule_id}:时间到,随机选择 {next_state_candidate.value},resolve 为 {resolved_candidate.value}"
|
||||||
|
)
|
||||||
next_state = resolved_candidate # 直接使用解析后的状态
|
next_state = resolved_candidate # 直接使用解析后的状态
|
||||||
|
|
||||||
# 注意:enable_unlimited_hfc_chat 优先级高于 prevent_offline_state
|
# 注意:enable_unlimited_hfc_chat 优先级高于 prevent_offline_state
|
||||||
|
|||||||
@@ -640,7 +640,6 @@ class HeartFChatting:
|
|||||||
# 从计时器获取实际等待时间
|
# 从计时器获取实际等待时间
|
||||||
dang_qian_deng_dai = cycle_timers.get("等待新消息", 0.0)
|
dang_qian_deng_dai = cycle_timers.get("等待新消息", 0.0)
|
||||||
|
|
||||||
|
|
||||||
if not self._shutting_down:
|
if not self._shutting_down:
|
||||||
self._lian_xu_bu_hui_fu_ci_shu += 1
|
self._lian_xu_bu_hui_fu_ci_shu += 1
|
||||||
self._lian_xu_deng_dai_shi_jian += dang_qian_deng_dai # 累加等待时间
|
self._lian_xu_deng_dai_shi_jian += dang_qian_deng_dai # 累加等待时间
|
||||||
@@ -651,8 +650,10 @@ class HeartFChatting:
|
|||||||
|
|
||||||
# 检查是否同时达到次数和时间阈值
|
# 检查是否同时达到次数和时间阈值
|
||||||
time_threshold = 0.66 * WAITING_TIME_THRESHOLD * self.CONSECUTIVE_NO_REPLY_THRESHOLD
|
time_threshold = 0.66 * WAITING_TIME_THRESHOLD * self.CONSECUTIVE_NO_REPLY_THRESHOLD
|
||||||
if (self._lian_xu_bu_hui_fu_ci_shu >= self.CONSECUTIVE_NO_REPLY_THRESHOLD and
|
if (
|
||||||
self._lian_xu_deng_dai_shi_jian >= time_threshold):
|
self._lian_xu_bu_hui_fu_ci_shu >= self.CONSECUTIVE_NO_REPLY_THRESHOLD
|
||||||
|
and self._lian_xu_deng_dai_shi_jian >= time_threshold
|
||||||
|
):
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{self.log_prefix} 连续不回复达到阈值 ({self._lian_xu_bu_hui_fu_ci_shu}次) "
|
f"{self.log_prefix} 连续不回复达到阈值 ({self._lian_xu_bu_hui_fu_ci_shu}次) "
|
||||||
f"且累计等待时间达到 {self._lian_xu_deng_dai_shi_jian:.2f}秒 (阈值 {time_threshold}秒),"
|
f"且累计等待时间达到 {self._lian_xu_deng_dai_shi_jian:.2f}秒 (阈值 {time_threshold}秒),"
|
||||||
@@ -668,7 +669,6 @@ class HeartFChatting:
|
|||||||
)
|
)
|
||||||
# else: 次数和时间都未达到阈值,不做处理
|
# else: 次数和时间都未达到阈值,不做处理
|
||||||
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
@@ -806,7 +806,9 @@ class HeartFChatting:
|
|||||||
else:
|
else:
|
||||||
break # 遇到非文本回复,中断计数
|
break # 遇到非文本回复,中断计数
|
||||||
# 检查最近的3个循环即可,避免检查过多历史 (如果历史很长)
|
# 检查最近的3个循环即可,避免检查过多历史 (如果历史很长)
|
||||||
if len(self._cycle_history) > 0 and cycle.cycle_id <= self._cycle_history[0].cycle_id + (len(self._cycle_history) - 4):
|
if len(self._cycle_history) > 0 and cycle.cycle_id <= self._cycle_history[0].cycle_id + (
|
||||||
|
len(self._cycle_history) - 4
|
||||||
|
):
|
||||||
break
|
break
|
||||||
|
|
||||||
logger.debug(f"{self.log_prefix}[Planner] 检测到连续文本回复次数: {lian_xu_wen_ben_hui_fu}")
|
logger.debug(f"{self.log_prefix}[Planner] 检测到连续文本回复次数: {lian_xu_wen_ben_hui_fu}")
|
||||||
@@ -820,7 +822,9 @@ class HeartFChatting:
|
|||||||
logger.info(f"{self.log_prefix}[Planner] 连续回复 2 次,80% 概率移除 text_reply 和 emoji_reply (触发)")
|
logger.info(f"{self.log_prefix}[Planner] 连续回复 2 次,80% 概率移除 text_reply 和 emoji_reply (触发)")
|
||||||
actions_to_remove_temporarily.extend(["text_reply", "emoji_reply"])
|
actions_to_remove_temporarily.extend(["text_reply", "emoji_reply"])
|
||||||
else:
|
else:
|
||||||
logger.info(f"{self.log_prefix}[Planner] 连续回复 2 次,80% 概率移除 text_reply 和 emoji_reply (未触发)")
|
logger.info(
|
||||||
|
f"{self.log_prefix}[Planner] 连续回复 2 次,80% 概率移除 text_reply 和 emoji_reply (未触发)"
|
||||||
|
)
|
||||||
elif lian_xu_wen_ben_hui_fu == 1:
|
elif lian_xu_wen_ben_hui_fu == 1:
|
||||||
if probability_roll < 0.4: # 40% 概率
|
if probability_roll < 0.4: # 40% 概率
|
||||||
logger.info(f"{self.log_prefix}[Planner] 连续回复 1 次,40% 概率移除 text_reply (触发)")
|
logger.info(f"{self.log_prefix}[Planner] 连续回复 1 次,40% 概率移除 text_reply (触发)")
|
||||||
@@ -847,7 +851,9 @@ class HeartFChatting:
|
|||||||
# --- 新增:应用临时动作移除 ---
|
# --- 新增:应用临时动作移除 ---
|
||||||
if actions_to_remove_temporarily:
|
if actions_to_remove_temporarily:
|
||||||
self.action_manager.temporarily_remove_actions(actions_to_remove_temporarily)
|
self.action_manager.temporarily_remove_actions(actions_to_remove_temporarily)
|
||||||
logger.debug(f"{self.log_prefix}[Planner] 临时移除的动作: {actions_to_remove_temporarily}, 当前可用: {list(self.action_manager.get_available_actions().keys())}")
|
logger.debug(
|
||||||
|
f"{self.log_prefix}[Planner] 临时移除的动作: {actions_to_remove_temporarily}, 当前可用: {list(self.action_manager.get_available_actions().keys())}"
|
||||||
|
)
|
||||||
|
|
||||||
# --- 构建提示词 ---
|
# --- 构建提示词 ---
|
||||||
replan_prompt_str = ""
|
replan_prompt_str = ""
|
||||||
@@ -917,7 +923,9 @@ class HeartFChatting:
|
|||||||
llm_error = False # 视为逻辑修正而非 LLM 错误
|
llm_error = False # 视为逻辑修正而非 LLM 错误
|
||||||
# --- 检查 'no_reply' 是否也恰好被移除了 (极端情况) ---
|
# --- 检查 'no_reply' 是否也恰好被移除了 (极端情况) ---
|
||||||
if "no_reply" not in self.action_manager.get_available_actions():
|
if "no_reply" not in self.action_manager.get_available_actions():
|
||||||
logger.error(f"{self.log_prefix}[Planner] 严重错误:'no_reply' 动作也不可用!无法执行任何动作。")
|
logger.error(
|
||||||
|
f"{self.log_prefix}[Planner] 严重错误:'no_reply' 动作也不可用!无法执行任何动作。"
|
||||||
|
)
|
||||||
action = "error" # 回退到错误状态
|
action = "error" # 回退到错误状态
|
||||||
reasoning = "无法执行任何有效动作,包括 no_reply"
|
reasoning = "无法执行任何有效动作,包括 no_reply"
|
||||||
llm_error = True
|
llm_error = True
|
||||||
@@ -944,7 +952,9 @@ class HeartFChatting:
|
|||||||
# 如果没有有效的工具调用,我们需要检查 'no_reply' 是否是当前唯一可用的动作
|
# 如果没有有效的工具调用,我们需要检查 'no_reply' 是否是当前唯一可用的动作
|
||||||
available_actions = list(self.action_manager.get_available_actions().keys())
|
available_actions = list(self.action_manager.get_available_actions().keys())
|
||||||
if available_actions == ["no_reply"]:
|
if available_actions == ["no_reply"]:
|
||||||
logger.info(f"{self.log_prefix}[Planner] LLM未返回工具调用,但当前唯一可用动作是 'no_reply',将执行 'no_reply'")
|
logger.info(
|
||||||
|
f"{self.log_prefix}[Planner] LLM未返回工具调用,但当前唯一可用动作是 'no_reply',将执行 'no_reply'"
|
||||||
|
)
|
||||||
action = "no_reply"
|
action = "no_reply"
|
||||||
reasoning = "LLM未返回工具调用,且当前仅 'no_reply' 可用"
|
reasoning = "LLM未返回工具调用,且当前仅 'no_reply' 可用"
|
||||||
emoji_query = ""
|
emoji_query = ""
|
||||||
@@ -965,7 +975,9 @@ class HeartFChatting:
|
|||||||
finally:
|
finally:
|
||||||
if actions_to_remove_temporarily: # 只有当确实移除了动作时才需要恢复
|
if actions_to_remove_temporarily: # 只有当确实移除了动作时才需要恢复
|
||||||
self.action_manager.restore_actions()
|
self.action_manager.restore_actions()
|
||||||
logger.debug(f"{self.log_prefix}[Planner] 恢复了原始动作集, 当前可用: {list(self.action_manager.get_available_actions().keys())}")
|
logger.debug(
|
||||||
|
f"{self.log_prefix}[Planner] 恢复了原始动作集, 当前可用: {list(self.action_manager.get_available_actions().keys())}"
|
||||||
|
)
|
||||||
# --- 结束:确保动作恢复 ---
|
# --- 结束:确保动作恢复 ---
|
||||||
# --- 结束 LLM 决策 --- #
|
# --- 结束 LLM 决策 --- #
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user