From 3267bd00c89498f53040732fe832702f1dbe8821 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Thu, 12 Jun 2025 23:38:25 +0800 Subject: [PATCH] =?UTF-8?q?=20fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../focus_chat/planners/action_manager.py | 20 +++++++++++------ .../focus_chat/planners/modify_actions.py | 22 ++++++++++--------- .../normal_chat_action_modifier.py | 9 ++++---- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/chat/focus_chat/planners/action_manager.py b/src/chat/focus_chat/planners/action_manager.py index 7885982ec..17ae4ad2e 100644 --- a/src/chat/focus_chat/planners/action_manager.py +++ b/src/chat/focus_chat/planners/action_manager.py @@ -145,16 +145,22 @@ class ActionManager: is_enabled: bool = getattr(action_class, "enable_plugin", True) # 获取激活类型相关属性 - focus_activation_type: str = getattr(action_class, "focus_activation_type", "always") - normal_activation_type: str = getattr(action_class, "normal_activation_type", "always") + focus_activation_type_attr = getattr(action_class, "focus_activation_type", "always") + normal_activation_type_attr = getattr(action_class, "normal_activation_type", "always") + # 处理枚举值,提取.value + focus_activation_type = focus_activation_type_attr.value if hasattr(focus_activation_type_attr, 'value') else str(focus_activation_type_attr) + normal_activation_type = normal_activation_type_attr.value if hasattr(normal_activation_type_attr, 'value') else str(normal_activation_type_attr) + + # 其他属性 random_probability: float = getattr(action_class, "random_activation_probability", 0.3) llm_judge_prompt: str = getattr(action_class, "llm_judge_prompt", "") activation_keywords: list[str] = getattr(action_class, "activation_keywords", []) keyword_case_sensitive: bool = getattr(action_class, "keyword_case_sensitive", False) - # 获取模式启用属性 - mode_enable: str = getattr(action_class, "mode_enable", "all") + # 处理模式启用属性 + mode_enable_attr = getattr(action_class, "mode_enable", "all") + mode_enable = mode_enable_attr.value if hasattr(mode_enable_attr, 'value') else str(mode_enable_attr) # 获取并行执行属性 parallel_action: bool = getattr(action_class, "parallel_action", False) @@ -442,11 +448,11 @@ class ActionManager: """ filtered_actions = {} - print(self._using_actions) + # print(self._using_actions) for action_name, action_info in self._using_actions.items(): - print(f"action_info: {action_info}") - print(f"action_name: {action_name}") + # print(f"action_info: {action_info}") + # print(f"action_name: {action_name}") action_mode = action_info.get("mode_enable", "all") # 检查动作是否在当前模式下启用 diff --git a/src/chat/focus_chat/planners/modify_actions.py b/src/chat/focus_chat/planners/modify_actions.py index 56b07d6ca..f0a250623 100644 --- a/src/chat/focus_chat/planners/modify_actions.py +++ b/src/chat/focus_chat/planners/modify_actions.py @@ -139,7 +139,7 @@ class ActionModifier: # 获取当前使用的动作集(经过第一阶段处理,且适用于FOCUS模式) current_using_actions = self.action_manager.get_using_actions() - all_registered_actions = self.action_manager.get_using_actions_for_mode("focus") + all_registered_actions = self.action_manager.get_registered_actions() # 构建完整的动作信息 current_actions_with_info = {} @@ -165,14 +165,15 @@ class ActionModifier: # 确定移除原因 if action_name in all_registered_actions: action_info = all_registered_actions[action_name] - activation_type = action_info.get("focus_activation_type", ActionActivationType.ALWAYS) + activation_type = action_info.get("focus_activation_type", "always") - if activation_type == ActionActivationType.RANDOM: + # 处理字符串格式的激活类型值 + if activation_type == "random": probability = action_info.get("random_probability", 0.3) removal_reasons[action_name] = f"RANDOM类型未触发(概率{probability})" - elif activation_type == ActionActivationType.LLM_JUDGE: + elif activation_type == "llm_judge": removal_reasons[action_name] = "LLM判定未激活" - elif activation_type == ActionActivationType.KEYWORD: + elif activation_type == "keyword": keywords = action_info.get("activation_keywords", []) removal_reasons[action_name] = f"关键词未匹配(关键词: {keywords})" else: @@ -215,15 +216,16 @@ class ActionModifier: keyword_actions = {} for action_name, action_info in actions_with_info.items(): - activation_type = action_info.get("focus_activation_type", ActionActivationType.ALWAYS) + activation_type = action_info.get("focus_activation_type", "always") - if activation_type == ActionActivationType.ALWAYS: + # 现在统一是字符串格式的激活类型值 + if activation_type == "always": always_actions[action_name] = action_info - elif activation_type == ActionActivationType.RANDOM: + elif activation_type == "random": random_actions[action_name] = action_info - elif activation_type == ActionActivationType.LLM_JUDGE: + elif activation_type == "llm_judge": llm_judge_actions[action_name] = action_info - elif activation_type == ActionActivationType.KEYWORD: + elif activation_type == "keyword": keyword_actions[action_name] = action_info else: logger.warning(f"{self.log_prefix}未知的激活类型: {activation_type},跳过处理") diff --git a/src/chat/normal_chat/normal_chat_action_modifier.py b/src/chat/normal_chat/normal_chat_action_modifier.py index 7feda150d..b53edc20a 100644 --- a/src/chat/normal_chat/normal_chat_action_modifier.py +++ b/src/chat/normal_chat/normal_chat_action_modifier.py @@ -184,13 +184,14 @@ class NormalChatActionModifier: for action_name, action_info in actions_with_info.items(): # 使用normal_activation_type - activation_type = action_info.get("normal_activation_type", ActionActivationType.ALWAYS) + activation_type = action_info.get("normal_activation_type", "always") - if activation_type == ActionActivationType.ALWAYS: + # 现在统一是字符串格式的激活类型值 + if activation_type == "always": always_actions[action_name] = action_info - elif activation_type == ActionActivationType.RANDOM or activation_type == ActionActivationType.LLM_JUDGE: + elif activation_type == "random" or activation_type == "llm_judge": random_actions[action_name] = action_info - elif activation_type == ActionActivationType.KEYWORD: + elif activation_type == "keyword": keyword_actions[action_name] = action_info else: logger.warning(f"{self.log_prefix}未知的激活类型: {activation_type},跳过处理")