fix:规范化描述定义
This commit is contained in:
@@ -61,7 +61,7 @@ class BaseAction(ABC):
|
|||||||
self.log_prefix = log_prefix
|
self.log_prefix = log_prefix
|
||||||
self.shutting_down = shutting_down
|
self.shutting_down = shutting_down
|
||||||
|
|
||||||
# 设置动作基本信息实例属性(兼容旧系统)
|
# 设置动作基本信息实例属性
|
||||||
self.action_name: str = getattr(self, "action_name", self.__class__.__name__.lower().replace("action", ""))
|
self.action_name: str = getattr(self, "action_name", self.__class__.__name__.lower().replace("action", ""))
|
||||||
self.action_description: str = getattr(self, "action_description", self.__doc__ or "Action组件")
|
self.action_description: str = getattr(self, "action_description", self.__doc__ or "Action组件")
|
||||||
self.action_parameters: dict = getattr(self.__class__, "action_parameters", {}).copy()
|
self.action_parameters: dict = getattr(self.__class__, "action_parameters", {}).copy()
|
||||||
@@ -364,25 +364,23 @@ class BaseAction(ABC):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_action_info(cls, name: str = None, description: str = None) -> "ActionInfo":
|
def get_action_info(cls) -> "ActionInfo":
|
||||||
"""从类属性生成ActionInfo
|
"""从类属性生成ActionInfo
|
||||||
|
|
||||||
Args:
|
所有信息都从类属性中读取,确保一致性和完整性。
|
||||||
name: Action名称,如果不提供则使用类名
|
Action类必须定义所有必要的类属性。
|
||||||
description: Action描述,如果不提供则使用类文档字符串
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
ActionInfo: 生成的Action信息对象
|
ActionInfo: 生成的Action信息对象
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 优先使用类属性,然后自动生成
|
# 从类属性读取名称,如果没有定义则使用类名自动生成
|
||||||
if name is None:
|
|
||||||
name = getattr(cls, "action_name", cls.__name__.lower().replace("action", ""))
|
name = getattr(cls, "action_name", cls.__name__.lower().replace("action", ""))
|
||||||
if description is None:
|
|
||||||
|
# 从类属性读取描述,如果没有定义则使用文档字符串的第一行
|
||||||
description = getattr(cls, "action_description", None)
|
description = getattr(cls, "action_description", None)
|
||||||
if description is None:
|
if description is None:
|
||||||
description = cls.__doc__ or f"{cls.__name__} Action组件"
|
description = "Action动作"
|
||||||
description = description.strip().split("\n")[0] # 取第一行作为描述
|
|
||||||
|
|
||||||
# 安全获取激活类型值
|
# 安全获取激活类型值
|
||||||
def get_enum_value(attr_name, default):
|
def get_enum_value(attr_name, default):
|
||||||
|
|||||||
@@ -32,12 +32,16 @@ class ReplyAction(BaseAction):
|
|||||||
mode_enable = ChatMode.FOCUS
|
mode_enable = ChatMode.FOCUS
|
||||||
parallel_action = False
|
parallel_action = False
|
||||||
|
|
||||||
# 动作参数定义(旧系统格式)
|
# 动作基本信息
|
||||||
|
action_name = "reply"
|
||||||
|
action_description = "参与聊天回复,处理文本和表情的发送"
|
||||||
|
|
||||||
|
# 动作参数定义
|
||||||
action_parameters = {
|
action_parameters = {
|
||||||
"reply_to": "如果是明确回复某个人的发言,请在reply_to参数中指定,格式:(用户名:发言内容),如果不是,reply_to的值设为none"
|
"reply_to": "如果是明确回复某个人的发言,请在reply_to参数中指定,格式:(用户名:发言内容),如果不是,reply_to的值设为none"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 动作使用场景(旧系统字段名)
|
# 动作使用场景
|
||||||
action_require = ["你想要闲聊或者随便附和", "有人提到你", "如果你刚刚进行了回复,不要对同一个话题重复回应"]
|
action_require = ["你想要闲聊或者随便附和", "有人提到你", "如果你刚刚进行了回复,不要对同一个话题重复回应"]
|
||||||
|
|
||||||
# 关联类型
|
# 关联类型
|
||||||
@@ -143,6 +147,10 @@ class NoReplyAction(BaseAction):
|
|||||||
mode_enable = ChatMode.FOCUS
|
mode_enable = ChatMode.FOCUS
|
||||||
parallel_action = False
|
parallel_action = False
|
||||||
|
|
||||||
|
# 动作基本信息
|
||||||
|
action_name = "no_reply"
|
||||||
|
action_description = "暂时不回复消息,等待新消息或超时"
|
||||||
|
|
||||||
# 默认超时时间,将由插件在注册时设置
|
# 默认超时时间,将由插件在注册时设置
|
||||||
waiting_timeout = 1200
|
waiting_timeout = 1200
|
||||||
|
|
||||||
@@ -211,6 +219,10 @@ class EmojiAction(BaseAction):
|
|||||||
parallel_action = True
|
parallel_action = True
|
||||||
random_activation_probability = 0.1 # 默认值,可通过配置覆盖
|
random_activation_probability = 0.1 # 默认值,可通过配置覆盖
|
||||||
|
|
||||||
|
# 动作基本信息
|
||||||
|
action_name = "emoji"
|
||||||
|
action_description = "发送表情包辅助表达情绪"
|
||||||
|
|
||||||
# LLM判断提示词
|
# LLM判断提示词
|
||||||
llm_judge_prompt = """
|
llm_judge_prompt = """
|
||||||
判定是否需要使用表情动作的条件:
|
判定是否需要使用表情动作的条件:
|
||||||
@@ -294,6 +306,10 @@ class ChangeToFocusChatAction(BaseAction):
|
|||||||
mode_enable = ChatMode.NORMAL
|
mode_enable = ChatMode.NORMAL
|
||||||
parallel_action = False
|
parallel_action = False
|
||||||
|
|
||||||
|
# 动作基本信息
|
||||||
|
action_name = "change_to_focus_chat"
|
||||||
|
action_description = "切换到专注聊天,从普通模式切换到专注模式"
|
||||||
|
|
||||||
# 动作参数定义
|
# 动作参数定义
|
||||||
action_parameters = {}
|
action_parameters = {}
|
||||||
|
|
||||||
@@ -326,6 +342,10 @@ class ExitFocusChatAction(BaseAction):
|
|||||||
mode_enable = ChatMode.FOCUS
|
mode_enable = ChatMode.FOCUS
|
||||||
parallel_action = False
|
parallel_action = False
|
||||||
|
|
||||||
|
# 动作基本信息
|
||||||
|
action_name = "exit_focus_chat"
|
||||||
|
action_description = "退出专注聊天,从专注模式切换到普通模式"
|
||||||
|
|
||||||
# LLM判断提示词
|
# LLM判断提示词
|
||||||
llm_judge_prompt = """
|
llm_judge_prompt = """
|
||||||
判定是否需要退出专注聊天的条件:
|
判定是否需要退出专注聊天的条件:
|
||||||
@@ -408,29 +428,16 @@ class CoreActionsPlugin(BasePlugin):
|
|||||||
NoReplyAction.waiting_timeout = no_reply_timeout
|
NoReplyAction.waiting_timeout = no_reply_timeout
|
||||||
|
|
||||||
return [
|
return [
|
||||||
# 回复动作
|
# 回复动作 - 使用类中定义的所有属性
|
||||||
(ReplyAction.get_action_info(name="reply", description="参与聊天回复,处理文本和表情的发送"), ReplyAction),
|
(ReplyAction.get_action_info(), ReplyAction),
|
||||||
# 不回复动作
|
# 不回复动作 - 使用类中定义的所有属性
|
||||||
(
|
(NoReplyAction.get_action_info(), NoReplyAction),
|
||||||
NoReplyAction.get_action_info(name="no_reply", description="暂时不回复消息,等待新消息或超时"),
|
# 表情动作 - 使用类中定义的所有属性
|
||||||
NoReplyAction,
|
(EmojiAction.get_action_info(), EmojiAction),
|
||||||
),
|
# 退出专注聊天动作 - 使用类中定义的所有属性
|
||||||
# 表情动作
|
(ExitFocusChatAction.get_action_info(), ExitFocusChatAction),
|
||||||
(EmojiAction.get_action_info(name="emoji", description="发送表情包辅助表达情绪"), EmojiAction),
|
# 切换到专注聊天动作 - 使用类中定义的所有属性
|
||||||
# 退出专注聊天动作
|
(ChangeToFocusChatAction.get_action_info(), ChangeToFocusChatAction),
|
||||||
(
|
|
||||||
ExitFocusChatAction.get_action_info(
|
|
||||||
name="exit_focus_chat", description="退出专注聊天,从专注模式切换到普通模式"
|
|
||||||
),
|
|
||||||
ExitFocusChatAction,
|
|
||||||
),
|
|
||||||
# 切换到专注聊天动作
|
|
||||||
(
|
|
||||||
ChangeToFocusChatAction.get_action_info(
|
|
||||||
name="change_to_focus_chat", description="切换到专注聊天,从普通模式切换到专注模式"
|
|
||||||
),
|
|
||||||
ChangeToFocusChatAction,
|
|
||||||
),
|
|
||||||
# 示例Command - Ping命令
|
# 示例Command - Ping命令
|
||||||
(PingCommand.get_command_info(name="ping", description="测试机器人响应,拦截后续处理"), PingCommand),
|
(PingCommand.get_command_info(name="ping", description="测试机器人响应,拦截后续处理"), PingCommand),
|
||||||
# 示例Command - Log命令
|
# 示例Command - Log命令
|
||||||
|
|||||||
@@ -39,16 +39,18 @@ logger = get_logger("doubao_pic_plugin")
|
|||||||
class DoubaoImageGenerationAction(BaseAction):
|
class DoubaoImageGenerationAction(BaseAction):
|
||||||
"""豆包图片生成Action - 根据描述使用火山引擎API生成图片"""
|
"""豆包图片生成Action - 根据描述使用火山引擎API生成图片"""
|
||||||
|
|
||||||
# Action基本信息
|
# 激活设置
|
||||||
|
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定,精确理解需求
|
||||||
|
normal_activation_type = ActionActivationType.KEYWORD # Normal模式使用关键词激活,快速响应
|
||||||
|
mode_enable = ChatMode.ALL
|
||||||
|
parallel_action = True
|
||||||
|
|
||||||
|
# 动作基本信息
|
||||||
action_name = "doubao_image_generation"
|
action_name = "doubao_image_generation"
|
||||||
action_description = (
|
action_description = (
|
||||||
"可以根据特定的描述,生成并发送一张图片,如果没提供描述,就根据聊天内容生成,你可以立刻画好,不用等待"
|
"可以根据特定的描述,生成并发送一张图片,如果没提供描述,就根据聊天内容生成,你可以立刻画好,不用等待"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 激活设置
|
|
||||||
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定,精确理解需求
|
|
||||||
normal_activation_type = ActionActivationType.KEYWORD # Normal模式使用关键词激活,快速响应
|
|
||||||
|
|
||||||
# 关键词设置(用于Normal模式)
|
# 关键词设置(用于Normal模式)
|
||||||
activation_keywords = ["画", "绘制", "生成图片", "画图", "draw", "paint", "图片生成"]
|
activation_keywords = ["画", "绘制", "生成图片", "画图", "draw", "paint", "图片生成"]
|
||||||
keyword_case_sensitive = False
|
keyword_case_sensitive = False
|
||||||
@@ -75,22 +77,22 @@ class DoubaoImageGenerationAction(BaseAction):
|
|||||||
5. 用户明确表示不需要图片时
|
5. 用户明确表示不需要图片时
|
||||||
"""
|
"""
|
||||||
|
|
||||||
mode_enable = ChatMode.ALL
|
# 动作参数定义
|
||||||
parallel_action = True
|
|
||||||
|
|
||||||
# Action参数定义
|
|
||||||
action_parameters = {
|
action_parameters = {
|
||||||
"description": "图片描述,输入你想要生成并发送的图片的描述,必填",
|
"description": "图片描述,输入你想要生成并发送的图片的描述,必填",
|
||||||
"size": "图片尺寸,例如 '1024x1024' (可选, 默认从配置或 '1024x1024')",
|
"size": "图片尺寸,例如 '1024x1024' (可选, 默认从配置或 '1024x1024')",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Action使用场景
|
# 动作使用场景
|
||||||
action_require = [
|
action_require = [
|
||||||
"当有人让你画东西时使用,你可以立刻画好,不用等待",
|
"当有人让你画东西时使用,你可以立刻画好,不用等待",
|
||||||
"当有人要求你生成并发送一张图片时使用",
|
"当有人要求你生成并发送一张图片时使用",
|
||||||
"当有人让你画一张图时使用",
|
"当有人让你画一张图时使用",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# 关联类型
|
||||||
|
associated_types = ["image", "text"]
|
||||||
|
|
||||||
# 简单的请求缓存,避免短时间内重复请求
|
# 简单的请求缓存,避免短时间内重复请求
|
||||||
_request_cache = {}
|
_request_cache = {}
|
||||||
_cache_max_size = 10
|
_cache_max_size = 10
|
||||||
|
|||||||
@@ -35,13 +35,15 @@ logger = get_logger("mute_plugin")
|
|||||||
class MuteAction(BaseAction):
|
class MuteAction(BaseAction):
|
||||||
"""智能禁言Action - 基于LLM智能判断是否需要禁言"""
|
"""智能禁言Action - 基于LLM智能判断是否需要禁言"""
|
||||||
|
|
||||||
# Action基本信息
|
|
||||||
action_name = "mute"
|
|
||||||
action_description = "智能禁言系统,基于LLM判断是否需要禁言"
|
|
||||||
|
|
||||||
# 激活设置
|
# 激活设置
|
||||||
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定,确保谨慎
|
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定,确保谨慎
|
||||||
normal_activation_type = ActionActivationType.KEYWORD # Normal模式使用关键词激活,快速响应
|
normal_activation_type = ActionActivationType.KEYWORD # Normal模式使用关键词激活,快速响应
|
||||||
|
mode_enable = ChatMode.ALL
|
||||||
|
parallel_action = False
|
||||||
|
|
||||||
|
# 动作基本信息
|
||||||
|
action_name = "mute"
|
||||||
|
action_description = "智能禁言系统,基于LLM判断是否需要禁言"
|
||||||
|
|
||||||
# 关键词设置(用于Normal模式)
|
# 关键词设置(用于Normal模式)
|
||||||
activation_keywords = ["禁言", "mute", "ban", "silence"]
|
activation_keywords = ["禁言", "mute", "ban", "silence"]
|
||||||
@@ -65,17 +67,14 @@ class MuteAction(BaseAction):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
mode_enable = ChatMode.ALL
|
# 动作参数定义
|
||||||
parallel_action = False
|
|
||||||
|
|
||||||
# Action参数定义
|
|
||||||
action_parameters = {
|
action_parameters = {
|
||||||
"target": "禁言对象,必填,输入你要禁言的对象的名字,请仔细思考不要弄错禁言对象",
|
"target": "禁言对象,必填,输入你要禁言的对象的名字,请仔细思考不要弄错禁言对象",
|
||||||
"duration": "禁言时长,必填,输入你要禁言的时长(秒),单位为秒,必须为数字",
|
"duration": "禁言时长,必填,输入你要禁言的时长(秒),单位为秒,必须为数字",
|
||||||
"reason": "禁言理由,可选",
|
"reason": "禁言理由,可选",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Action使用场景
|
# 动作使用场景
|
||||||
action_require = [
|
action_require = [
|
||||||
"当有人违反了公序良俗的内容",
|
"当有人违反了公序良俗的内容",
|
||||||
"当有人刷屏时使用",
|
"当有人刷屏时使用",
|
||||||
@@ -84,6 +83,9 @@ class MuteAction(BaseAction):
|
|||||||
"如果某人已经被禁言了,就不要再次禁言了,除非你想追加时间!!",
|
"如果某人已经被禁言了,就不要再次禁言了,除非你想追加时间!!",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# 关联类型
|
||||||
|
associated_types = ["text","command"]
|
||||||
|
|
||||||
async def execute(self) -> Tuple[bool, Optional[str]]:
|
async def execute(self) -> Tuple[bool, Optional[str]]:
|
||||||
"""执行智能禁言判定"""
|
"""执行智能禁言判定"""
|
||||||
logger.info(f"{self.log_prefix} 执行智能禁言动作")
|
logger.info(f"{self.log_prefix} 执行智能禁言动作")
|
||||||
|
|||||||
@@ -10,34 +10,36 @@ logger = get_logger("tts")
|
|||||||
class TTSAction(BaseAction):
|
class TTSAction(BaseAction):
|
||||||
"""TTS语音转换动作处理类"""
|
"""TTS语音转换动作处理类"""
|
||||||
|
|
||||||
action_name = "tts"
|
# 激活设置
|
||||||
|
focus_activation_type = ActionActivationType.LLM_JUDGE
|
||||||
|
normal_activation_type = ActionActivationType.KEYWORD
|
||||||
|
mode_enable = ChatMode.ALL
|
||||||
|
parallel_action = False
|
||||||
|
|
||||||
|
# 动作基本信息
|
||||||
|
action_name = "tts_action"
|
||||||
action_description = "将文本转换为语音进行播放,适用于需要语音输出的场景"
|
action_description = "将文本转换为语音进行播放,适用于需要语音输出的场景"
|
||||||
|
|
||||||
|
# 关键词配置 - Normal模式下使用关键词触发
|
||||||
|
activation_keywords = ["语音", "tts", "播报", "读出来", "语音播放", "听", "朗读"]
|
||||||
|
keyword_case_sensitive = False
|
||||||
|
|
||||||
|
# 动作参数定义
|
||||||
action_parameters = {
|
action_parameters = {
|
||||||
"text": "需要转换为语音的文本内容,必填,内容应当适合语音播报,语句流畅、清晰",
|
"text": "需要转换为语音的文本内容,必填,内容应当适合语音播报,语句流畅、清晰",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 动作使用场景
|
||||||
action_require = [
|
action_require = [
|
||||||
"当需要发送语音信息时使用",
|
"当需要发送语音信息时使用",
|
||||||
"当用户明确要求使用语音功能时使用",
|
"当用户明确要求使用语音功能时使用",
|
||||||
"当表达内容更适合用语音而不是文字传达时使用",
|
"当表达内容更适合用语音而不是文字传达时使用",
|
||||||
"当用户想听到语音回答而非阅读文本时使用",
|
"当用户想听到语音回答而非阅读文本时使用",
|
||||||
]
|
]
|
||||||
enable_plugin = True # 启用插件
|
|
||||||
|
# 关联类型
|
||||||
associated_types = ["tts_text"]
|
associated_types = ["tts_text"]
|
||||||
|
|
||||||
# 模式和并行控制
|
|
||||||
mode_enable = ChatMode.ALL
|
|
||||||
parallel_action = False
|
|
||||||
|
|
||||||
focus_activation_type = ActionActivationType.LLM_JUDGE
|
|
||||||
normal_activation_type = ActionActivationType.KEYWORD
|
|
||||||
|
|
||||||
# 关键词配置 - Normal模式下使用关键词触发
|
|
||||||
activation_keywords = ["语音", "tts", "播报", "读出来", "语音播放", "听", "朗读"]
|
|
||||||
keyword_case_sensitive = False
|
|
||||||
|
|
||||||
# 并行执行设置 - TTS可以与回复并行执行,不覆盖回复内容
|
|
||||||
parallel_action = False
|
|
||||||
|
|
||||||
async def execute(self) -> Tuple[bool, str]:
|
async def execute(self) -> Tuple[bool, str]:
|
||||||
"""处理TTS文本转语音动作"""
|
"""处理TTS文本转语音动作"""
|
||||||
logger.info(f"{self.log_prefix} 执行TTS动作: {self.reasoning}")
|
logger.info(f"{self.log_prefix} 执行TTS动作: {self.reasoning}")
|
||||||
@@ -112,11 +114,6 @@ class TTSPlugin(BasePlugin):
|
|||||||
enable_tts = self.get_config("components.enable_tts", True)
|
enable_tts = self.get_config("components.enable_tts", True)
|
||||||
components = [] # 添加Action组件
|
components = [] # 添加Action组件
|
||||||
if enable_tts:
|
if enable_tts:
|
||||||
components.append(
|
components.append((TTSAction.get_action_info(), TTSAction))
|
||||||
(
|
|
||||||
TTSAction.get_action_info(name="tts_action", description="文字转语音插件"),
|
|
||||||
TTSAction,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return components
|
return components
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class VTBPlugin(BasePlugin):
|
|||||||
if enable_vtb:
|
if enable_vtb:
|
||||||
components.append(
|
components.append(
|
||||||
(
|
(
|
||||||
VTBAction.get_action_info(name="vtb_action", description="虚拟主播情感表达插件"),
|
VTBAction.get_action_info(),
|
||||||
VTBAction,
|
VTBAction,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user