feat:动作现在区分focus和normal,并且可选不同的激活策略

This commit is contained in:
SengokuCola
2025-06-09 15:10:38 +08:00
parent 2ce5114b8c
commit 97ffbe5145
25 changed files with 1180 additions and 855 deletions

View File

@@ -6,7 +6,7 @@ import base64 # 新增用于Base64编码
import traceback # 新增:用于打印堆栈跟踪
from typing import Tuple
from src.chat.focus_chat.planners.actions.plugin_action import PluginAction, register_action
from src.chat.focus_chat.planners.actions.base_action import ActionActivationType
from src.chat.focus_chat.planners.actions.base_action import ActionActivationType, ChatMode
from src.common.logger_manager import get_logger
from .generate_pic_config import generate_config
@@ -35,11 +35,18 @@ class PicAction(PluginAction):
"当有人要求你生成并发送一张图片时使用",
"当有人让你画一张图时使用",
]
default = True
enable_plugin = True
action_config_file_name = "pic_action_config.toml"
# 激活类型设置 - 使用LLM判定能更好理解用户意图
action_activation_type = ActionActivationType.LLM_JUDGE
# 激活类型设置
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定精确理解需求
normal_activation_type = ActionActivationType.KEYWORD # Normal模式使用关键词激活快速响应
# 关键词设置用于Normal模式
activation_keywords = ["", "绘制", "生成图片", "画图", "draw", "paint", "图片生成"]
keyword_case_sensitive = False
# LLM判定提示词用于Focus模式
llm_judge_prompt = """
判定是否需要使用图片生成动作的条件:
1. 用户明确要求画图、生成图片或创作图像
@@ -60,11 +67,20 @@ class PicAction(PluginAction):
4. 技术讨论中提到绘图概念但无生成需求
5. 用户明确表示不需要图片时
"""
# Random激活概率备用
random_activation_probability = 0.15 # 适中概率,图片生成比较有趣
# 简单的请求缓存,避免短时间内重复请求
_request_cache = {}
_cache_max_size = 10
# 模式启用设置 - 图片生成在所有模式下可用
mode_enable = ChatMode.ALL
# 并行执行设置 - 图片生成可以与回复并行执行,不覆盖回复内容
parallel_action = False
@classmethod
def _get_cache_key(cls, description: str, model: str, size: str) -> str:
"""生成缓存键"""

View File

@@ -1,5 +1,6 @@
from src.common.logger_manager import get_logger
from src.chat.focus_chat.planners.actions.plugin_action import PluginAction, register_action, ActionActivationType
from src.chat.focus_chat.planners.actions.base_action import ChatMode
from typing import Tuple
logger = get_logger("mute_action")
@@ -22,12 +23,20 @@ class MuteAction(PluginAction):
"当有人发了擦边,或者色情内容时使用",
"当有人要求禁言自己时使用",
]
default = True # 默认动作,是否手动添加到使用集
enable_plugin = True # 启用插件
associated_types = ["command", "text"]
action_config_file_name = "mute_action_config.toml"
# 激活类型设置 - 使用LLM判定因为禁言是严肃的管理动作需要谨慎判断
action_activation_type = ActionActivationType.LLM_JUDGE
# 激活类型设置
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定确保谨慎
normal_activation_type = ActionActivationType.KEYWORD # Normal模式使用关键词激活快速响应
# 关键词设置用于Normal模式
activation_keywords = ["禁言", "mute", "ban", "silence"]
keyword_case_sensitive = False
# LLM判定提示词用于Focus模式
llm_judge_prompt = """
判定是否需要使用禁言动作的严格条件:
@@ -49,6 +58,15 @@ class MuteAction(PluginAction):
注意:禁言是严厉措施,只在明确违规或用户主动要求时使用。
宁可保守也不要误判,保护用户的发言权利。
"""
# Random激活概率备用
random_activation_probability = 0.05 # 设置很低的概率作为兜底
# 模式启用设置 - 禁言功能在所有模式下都可用
mode_enable = ChatMode.ALL
# 并行执行设置 - 禁言动作可以与回复并行执行,不覆盖回复内容
parallel_action = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@@ -1,4 +1,5 @@
from src.common.logger_manager import get_logger
from src.chat.focus_chat.planners.actions.base_action import ActionActivationType
from src.chat.focus_chat.planners.actions.plugin_action import PluginAction, register_action
from typing import Tuple
@@ -20,8 +21,18 @@ class TTSAction(PluginAction):
"当表达内容更适合用语音而不是文字传达时使用",
"当用户想听到语音回答而非阅读文本时使用",
]
default = True # 设为默认动作
enable_plugin = True # 启用插件
associated_types = ["tts_text"]
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 process(self) -> Tuple[bool, str]:
"""处理TTS文本转语音动作"""

View File

@@ -20,11 +20,14 @@ class VTBAction(PluginAction):
"当回应内容需要更生动的情感表达时使用",
"当想要通过预设动作增强互动体验时使用",
]
default = True # 设为默认动作
enable_plugin = True # 启用插件
associated_types = ["vtb_text"]
# 激活类型设置 - 使用LLM判定因为需要根据情感表达需求判断
action_activation_type = ActionActivationType.LLM_JUDGE
# 激活类型设置
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定精确识别情感表达需求
normal_activation_type = ActionActivationType.RANDOM # Normal模式使用随机激活增加趣味性
# LLM判定提示词用于Focus模式
llm_judge_prompt = """
判定是否需要使用VTB虚拟主播动作的条件
1. 当前聊天内容涉及明显的情感表达需求
@@ -38,6 +41,9 @@ class VTBAction(PluginAction):
3. 不涉及情感的日常对话
4. 已经有足够的情感表达
"""
# Random激活概率用于Normal模式
random_activation_probability = 0.08 # 较低概率,避免过度使用
async def process(self) -> Tuple[bool, str]:
"""处理VTB虚拟主播动作"""