fix:修复枚举类型转换错误
This commit is contained in:
@@ -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")
|
||||
|
||||
# 检查动作是否在当前模式下启用
|
||||
|
||||
@@ -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},跳过处理")
|
||||
|
||||
@@ -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},跳过处理")
|
||||
|
||||
Reference in New Issue
Block a user