fix:修复类属性优先级问题
This commit is contained in:
@@ -243,7 +243,7 @@ class ActionModifier:
|
|||||||
for action_name, action_info in actions_with_info.items():
|
for action_name, action_info in actions_with_info.items():
|
||||||
activation_type = action_info.get("focus_activation_type", "always")
|
activation_type = action_info.get("focus_activation_type", "always")
|
||||||
|
|
||||||
print(f"action_name: {action_name}, activation_type: {activation_type}")
|
# print(f"action_name: {action_name}, activation_type: {activation_type}")
|
||||||
|
|
||||||
# 现在统一是字符串格式的激活类型值
|
# 现在统一是字符串格式的激活类型值
|
||||||
if activation_type == "always":
|
if activation_type == "always":
|
||||||
@@ -264,7 +264,7 @@ class ActionModifier:
|
|||||||
|
|
||||||
# 2. 处理RANDOM类型
|
# 2. 处理RANDOM类型
|
||||||
for action_name, action_info in random_actions.items():
|
for action_name, action_info in random_actions.items():
|
||||||
probability = action_info.get("random_probability", 0.3)
|
probability = action_info.get("random_activation_probability", ActionManager.DEFAULT_RANDOM_PROBABILITY)
|
||||||
should_activate = random.random() < probability
|
should_activate = random.random() < probability
|
||||||
if should_activate:
|
if should_activate:
|
||||||
activated_actions[action_name] = action_info
|
activated_actions[action_name] = action_info
|
||||||
|
|||||||
@@ -26,10 +26,34 @@ install(extra_lines=3)
|
|||||||
|
|
||||||
|
|
||||||
def init_prompt():
|
def init_prompt():
|
||||||
|
# Prompt(
|
||||||
|
# """
|
||||||
|
# {time_block}
|
||||||
|
# {indentify_block}你现在正在参与以下的聊天,以下是具体的聊天内容:
|
||||||
|
|
||||||
|
# {chat_content_block}
|
||||||
|
|
||||||
|
# {self_info_block}
|
||||||
|
# {relation_info_block}
|
||||||
|
|
||||||
|
# {cycle_info_block}
|
||||||
|
|
||||||
|
# {moderation_prompt}
|
||||||
|
# 注意,除了下面动作选项之外,你在群聊里不能做其他任何事情,这是你能力的边界,现在请你选择合适的action:
|
||||||
|
|
||||||
|
# {action_options_text}
|
||||||
|
|
||||||
|
# 请以动作的输出要求,以严格的 JSON 格式输出,且仅包含 JSON 内容。
|
||||||
|
# 请输出你提取的JSON,不要有任何其他文字或解释:
|
||||||
|
|
||||||
|
# """,
|
||||||
|
# "simple_planner_prompt",
|
||||||
|
# )
|
||||||
|
|
||||||
Prompt(
|
Prompt(
|
||||||
"""
|
"""
|
||||||
{time_block}
|
{time_block}
|
||||||
{indentify_block}你现在正在参与以下的聊天,以下是具体的聊天内容:
|
{indentify_block}你现在正在B站进行直播,你是一个虚拟主播,以下是直播间内容和电脑屏幕内容:
|
||||||
|
|
||||||
{chat_content_block}
|
{chat_content_block}
|
||||||
|
|
||||||
@@ -39,7 +63,7 @@ def init_prompt():
|
|||||||
{cycle_info_block}
|
{cycle_info_block}
|
||||||
|
|
||||||
{moderation_prompt}
|
{moderation_prompt}
|
||||||
注意,除了下面动作选项之外,你在群聊里不能做其他任何事情,这是你能力的边界,现在请你选择合适的action:
|
注意,除了下面动作选项之外,你在直播间里不能做其他任何事情,这是你能力的边界,现在请你选择合适的action:
|
||||||
|
|
||||||
{action_options_text}
|
{action_options_text}
|
||||||
|
|
||||||
@@ -99,18 +123,7 @@ class ActionPlanner(BasePlanner):
|
|||||||
# 获取观察信息
|
# 获取观察信息
|
||||||
extra_info: list[str] = []
|
extra_info: list[str] = []
|
||||||
|
|
||||||
# 设置默认值
|
self_info = ""
|
||||||
nickname_str = ""
|
|
||||||
for nicknames in global_config.bot.alias_names:
|
|
||||||
nickname_str += f"{nicknames},"
|
|
||||||
name_block = f"你的名字是{global_config.bot.nickname},你的昵称有{nickname_str},有人也会用这些昵称称呼你。"
|
|
||||||
|
|
||||||
personality_block = get_individuality().get_personality_prompt(x_person=2, level=2)
|
|
||||||
identity_block = get_individuality().get_identity_prompt(x_person=2, level=2)
|
|
||||||
|
|
||||||
self_info = name_block + personality_block + identity_block
|
|
||||||
current_mind = "你思考了很久,没有想清晰要做什么"
|
|
||||||
|
|
||||||
cycle_info = ""
|
cycle_info = ""
|
||||||
structured_info = ""
|
structured_info = ""
|
||||||
extra_info = []
|
extra_info = []
|
||||||
@@ -168,7 +181,6 @@ class ActionPlanner(BasePlanner):
|
|||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"action_result": {"action_type": action, "action_data": action_data, "reasoning": reasoning},
|
"action_result": {"action_type": action, "action_data": action_data, "reasoning": reasoning},
|
||||||
"current_mind": current_mind,
|
|
||||||
"observed_messages": observed_messages,
|
"observed_messages": observed_messages,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,8 +306,6 @@ class ActionPlanner(BasePlanner):
|
|||||||
|
|
||||||
plan_result = {
|
plan_result = {
|
||||||
"action_result": action_result,
|
"action_result": action_result,
|
||||||
# "extra_info_block": extra_info_block,
|
|
||||||
"current_mind": current_mind,
|
|
||||||
"observed_messages": observed_messages,
|
"observed_messages": observed_messages,
|
||||||
"action_prompt": prompt,
|
"action_prompt": prompt,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ class NormalChatActionModifier:
|
|||||||
|
|
||||||
# 2. 处理RANDOM类型(概率激活)
|
# 2. 处理RANDOM类型(概率激活)
|
||||||
for action_name, action_info in random_actions.items():
|
for action_name, action_info in random_actions.items():
|
||||||
probability = action_info.get("random_probability", 0.3)
|
probability = action_info.get("random_activation_probability", ActionManager.DEFAULT_RANDOM_PROBABILITY)
|
||||||
should_activate = random.random() < probability
|
should_activate = random.random() < probability
|
||||||
if should_activate:
|
if should_activate:
|
||||||
activated_actions[action_name] = action_info
|
activated_actions[action_name] = action_info
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ class BaseAction(ABC):
|
|||||||
keyword_case_sensitive=getattr(cls, "keyword_case_sensitive", False),
|
keyword_case_sensitive=getattr(cls, "keyword_case_sensitive", False),
|
||||||
mode_enable=get_mode_value("mode_enable", "all"),
|
mode_enable=get_mode_value("mode_enable", "all"),
|
||||||
parallel_action=getattr(cls, "parallel_action", True),
|
parallel_action=getattr(cls, "parallel_action", True),
|
||||||
random_activation_probability=getattr(cls, "random_activation_probability", 0.0),
|
random_activation_probability=getattr(cls, "random_activation_probability", 0.3),
|
||||||
llm_judge_prompt=getattr(cls, "llm_judge_prompt", ""),
|
llm_judge_prompt=getattr(cls, "llm_judge_prompt", ""),
|
||||||
# 使用正确的字段名
|
# 使用正确的字段名
|
||||||
action_parameters=getattr(cls, "action_parameters", {}).copy(),
|
action_parameters=getattr(cls, "action_parameters", {}).copy(),
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class ActionInfo(ComponentInfo):
|
|||||||
|
|
||||||
focus_activation_type: ActionActivationType = ActionActivationType.ALWAYS
|
focus_activation_type: ActionActivationType = ActionActivationType.ALWAYS
|
||||||
normal_activation_type: ActionActivationType = ActionActivationType.ALWAYS
|
normal_activation_type: ActionActivationType = ActionActivationType.ALWAYS
|
||||||
random_activation_probability: float = 0.3
|
random_activation_probability: float = 0.0
|
||||||
llm_judge_prompt: str = ""
|
llm_judge_prompt: str = ""
|
||||||
activation_keywords: List[str] = None
|
activation_keywords: List[str] = None
|
||||||
keyword_case_sensitive: bool = False
|
keyword_case_sensitive: bool = False
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ logger = get_logger("core_actions")
|
|||||||
WAITING_TIME_THRESHOLD = 1200 # 等待新消息时间阈值,单位秒
|
WAITING_TIME_THRESHOLD = 1200 # 等待新消息时间阈值,单位秒
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ReplyAction(BaseAction):
|
class ReplyAction(BaseAction):
|
||||||
"""回复动作 - 参与聊天回复"""
|
"""回复动作 - 参与聊天回复"""
|
||||||
|
|
||||||
@@ -103,17 +105,19 @@ class ReplyAction(BaseAction):
|
|||||||
return False, f"回复失败: {str(e)}"
|
return False, f"回复失败: {str(e)}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NoReplyAction(BaseAction):
|
class NoReplyAction(BaseAction):
|
||||||
"""不回复动作,继承时会等待新消息或超时"""
|
"""不回复动作,继承时会等待新消息或超时"""
|
||||||
|
|
||||||
focus_activation_type = ActionActivationType.ALWAYS
|
# focus_activation_type = ActionActivationType.ALWAYS
|
||||||
|
focus_activation_type = ActionActivationType.RANDOM
|
||||||
normal_activation_type = ActionActivationType.NEVER
|
normal_activation_type = ActionActivationType.NEVER
|
||||||
mode_enable = ChatMode.FOCUS
|
mode_enable = ChatMode.FOCUS
|
||||||
parallel_action = False
|
parallel_action = False
|
||||||
|
|
||||||
# 动作基本信息
|
# 动作基本信息
|
||||||
action_name = "no_reply"
|
action_name = "no_reply"
|
||||||
action_description = "暂时不回复消息,等待新消息或超时"
|
action_description = "暂时不回复消息"
|
||||||
|
|
||||||
# 默认超时时间,将由插件在注册时设置
|
# 默认超时时间,将由插件在注册时设置
|
||||||
waiting_timeout = 1200
|
waiting_timeout = 1200
|
||||||
@@ -121,6 +125,8 @@ class NoReplyAction(BaseAction):
|
|||||||
# 连续no_reply计数器
|
# 连续no_reply计数器
|
||||||
_consecutive_count = 0
|
_consecutive_count = 0
|
||||||
|
|
||||||
|
random_activation_probability = 0.2
|
||||||
|
|
||||||
# 分级等待时间
|
# 分级等待时间
|
||||||
_waiting_stages = [10, 60, 600] # 第1、2、3次的等待时间
|
_waiting_stages = [10, 60, 600] # 第1、2、3次的等待时间
|
||||||
|
|
||||||
@@ -128,7 +134,7 @@ class NoReplyAction(BaseAction):
|
|||||||
action_parameters = {}
|
action_parameters = {}
|
||||||
|
|
||||||
# 动作使用场景
|
# 动作使用场景
|
||||||
action_require = ["你连续发送了太多消息,且无人回复", "想要暂时不回复"]
|
action_require = ["你发送了消息,目前无人回复"]
|
||||||
|
|
||||||
# 关联类型
|
# 关联类型
|
||||||
associated_types = []
|
associated_types = []
|
||||||
@@ -361,6 +367,7 @@ class CoreActionsPlugin(BasePlugin):
|
|||||||
config_schema = {
|
config_schema = {
|
||||||
"plugin": {
|
"plugin": {
|
||||||
"enabled": ConfigField(type=bool, default=True, description="是否启用插件"),
|
"enabled": ConfigField(type=bool, default=True, description="是否启用插件"),
|
||||||
|
"config_version": ConfigField(type=str, default="0.0.2", description="配置文件版本"),
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"enable_reply": ConfigField(type=bool, default=True, description="是否启用'回复'动作"),
|
"enable_reply": ConfigField(type=bool, default=True, description="是否启用'回复'动作"),
|
||||||
@@ -376,6 +383,9 @@ class CoreActionsPlugin(BasePlugin):
|
|||||||
"stage_1_wait": ConfigField(type=int, default=10, description="第1次连续不回复的等待时间(秒)"),
|
"stage_1_wait": ConfigField(type=int, default=10, description="第1次连续不回复的等待时间(秒)"),
|
||||||
"stage_2_wait": ConfigField(type=int, default=60, description="第2次连续不回复的等待时间(秒)"),
|
"stage_2_wait": ConfigField(type=int, default=60, description="第2次连续不回复的等待时间(秒)"),
|
||||||
"stage_3_wait": ConfigField(type=int, default=600, description="第3次连续不回复的等待时间(秒)"),
|
"stage_3_wait": ConfigField(type=int, default=600, description="第3次连续不回复的等待时间(秒)"),
|
||||||
|
"random_probability": ConfigField(
|
||||||
|
type=float, default=0.8, description="Focus模式下,随机选择不回复的概率(0.0到1.0)", example=0.8
|
||||||
|
),
|
||||||
},
|
},
|
||||||
"emoji": {
|
"emoji": {
|
||||||
"random_probability": ConfigField(
|
"random_probability": ConfigField(
|
||||||
@@ -391,6 +401,9 @@ class CoreActionsPlugin(BasePlugin):
|
|||||||
emoji_chance = self.get_config("emoji.random_probability", 0.1)
|
emoji_chance = self.get_config("emoji.random_probability", 0.1)
|
||||||
EmojiAction.random_activation_probability = emoji_chance
|
EmojiAction.random_activation_probability = emoji_chance
|
||||||
|
|
||||||
|
no_reply_probability = self.get_config("no_reply.random_probability", 0.8)
|
||||||
|
NoReplyAction.random_activation_probability = no_reply_probability
|
||||||
|
|
||||||
no_reply_timeout = self.get_config("no_reply.waiting_timeout", 1200)
|
no_reply_timeout = self.get_config("no_reply.waiting_timeout", 1200)
|
||||||
NoReplyAction.waiting_timeout = no_reply_timeout
|
NoReplyAction.waiting_timeout = no_reply_timeout
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user