diff --git a/src/chat/message_receive/message_sender.py b/src/chat/message_receive/message_sender.py index 5ee87c2e8..8134817bb 100644 --- a/src/chat/message_receive/message_sender.py +++ b/src/chat/message_receive/message_sender.py @@ -225,9 +225,9 @@ class MessageManager: if ( # message.apply_set_reply_logic # 检查标记 # and message.is_head - message.is_head - and (thinking_messages_count > 3 or thinking_messages_length > 200) - and not message.is_private_message() + # message.is_head + # and (thinking_messages_count > 3 or thinking_messages_length > 200) and + not message.is_private_message() ): logger.debug( f"[{message.chat_stream.stream_id}] 应用 set_reply 逻辑: {message.processed_plain_text[:20]}..." diff --git a/src/chat/normal_chat/normal_chat.py b/src/chat/normal_chat/normal_chat.py index 8b5541b23..dd8f60049 100644 --- a/src/chat/normal_chat/normal_chat.py +++ b/src/chat/normal_chat/normal_chat.py @@ -165,8 +165,9 @@ class NormalChat: if not items_to_process: continue - # 处理每条兴趣消息 - for msg_id, (message, interest_value, is_mentioned) in items_to_process: + # 并行处理兴趣消息 + async def process_single_message(msg_id, message, interest_value, is_mentioned): + """处理单个兴趣消息""" try: # 处理消息 if time.time() - self.start_time > 300: @@ -184,6 +185,24 @@ class NormalChat: finally: self.interest_dict.pop(msg_id, None) + # 创建并行任务列表 + tasks = [] + for msg_id, (message, interest_value, is_mentioned) in items_to_process: + task = process_single_message(msg_id, message, interest_value, is_mentioned) + tasks.append(task) + + # 并行执行所有任务,限制并发数量避免资源过度消耗 + if tasks: + # 使用信号量控制并发数,最多同时处理5个消息 + semaphore = asyncio.Semaphore(5) + + async def limited_process(task): + async with semaphore: + await task + + limited_tasks = [limited_process(task) for task in tasks] + await asyncio.gather(*limited_tasks, return_exceptions=True) + # 改为实例方法, 移除 chat 参数 async def normal_response(self, message: MessageRecv, is_mentioned: bool, interested_rate: float) -> None: # 新增:如果已停用,直接返回 diff --git a/src/plugins/built_in/tts_plugin/config.toml b/src/plugins/built_in/tts_plugin/config.toml index dd2dd103b..151718e0f 100644 --- a/src/plugins/built_in/tts_plugin/config.toml +++ b/src/plugins/built_in/tts_plugin/config.toml @@ -8,7 +8,7 @@ description = "文字转语音插件" # 组件启用控制 [components] -enable_tarots = true +enable_tts = true # 日志配置 [logging] diff --git a/src/plugins/built_in/tts_plugin/plugin.py b/src/plugins/built_in/tts_plugin/plugin.py index e1ef47994..2b6c90185 100644 --- a/src/plugins/built_in/tts_plugin/plugin.py +++ b/src/plugins/built_in/tts_plugin/plugin.py @@ -110,13 +110,11 @@ class TTSPlugin(BasePlugin): # 从配置获取组件启用状态 enable_tts = self.get_config("components.enable_tts", True) - components = [] - - # 添加Action组件 + components = [] # 添加Action组件 if enable_tts: components.append( ( - TTSAction.get_action_info(name="tarots_action", description="文字转语音插件"), + TTSAction.get_action_info(name="tts_action", description="文字转语音插件"), TTSAction, ) ) diff --git a/src/plugins/built_in/vtb_action/__init__.py b/src/plugins/built_in/vtb_action/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/plugins/built_in/vtb_action/actions/__init__.py b/src/plugins/built_in/vtb_action/actions/__init__.py deleted file mode 100644 index 7a85b034b..000000000 --- a/src/plugins/built_in/vtb_action/actions/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import vtb_action # noqa diff --git a/src/plugins/built_in/vtb_plugin/config.toml b/src/plugins/built_in/vtb_plugin/config.toml new file mode 100644 index 000000000..0e4d3a482 --- /dev/null +++ b/src/plugins/built_in/vtb_plugin/config.toml @@ -0,0 +1,26 @@ +# 虚拟主播情感表达插件配置文件 + +[plugin] +name = "vtb_plugin" +version = "0.1.0" +enabled = true +description = "虚拟主播情感表达插件" + +# 组件启用控制 +[components] +enable_vtb = true + +# VTB动作配置 +[vtb_action] +# 情感表达增强选项 +enable_emotion_enhancement = true +max_text_length = 100 +default_emotion = "平静" + +# 激活概率控制(Normal模式) +random_activation_probability = 0.08 + +# 日志配置 +[logging] +level = "INFO" +prefix = "[VTB]" diff --git a/src/plugins/built_in/vtb_action/actions/vtb_action.py b/src/plugins/built_in/vtb_plugin/plugin.py similarity index 62% rename from src/plugins/built_in/vtb_action/actions/vtb_action.py rename to src/plugins/built_in/vtb_plugin/plugin.py index ea63f1059..e05853ec1 100644 --- a/src/plugins/built_in/vtb_action/actions/vtb_action.py +++ b/src/plugins/built_in/vtb_plugin/plugin.py @@ -1,13 +1,13 @@ +from src.plugin_system.base.base_plugin import BasePlugin, register_plugin +from src.plugin_system.base.component_types import ComponentInfo from src.common.logger import get_logger -from src.plugin_system.base.base_action import BaseAction as PluginAction, ActionActivationType -from src.plugin_system.base.base_action import register_action -from typing import Tuple +from src.plugin_system.base.base_action import BaseAction, ActionActivationType, ChatMode +from typing import Tuple, List, Type -logger = get_logger("vtb_action") +logger = get_logger("vtb") -@register_action -class VTBAction(PluginAction): +class VTBAction(BaseAction): """VTB虚拟主播动作处理类""" action_name = "vtb_action" @@ -24,9 +24,13 @@ class VTBAction(PluginAction): enable_plugin = True # 启用插件 associated_types = ["vtb_text"] + # 模式和并行控制 + mode_enable = ChatMode.ALL + parallel_action = True # VTB动作可以与回复并行执行,增强表达效果 + # 激活类型设置 focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定,精确识别情感表达需求 - normal_activation_type = ActionActivationType.RANDOM # Normal模式使用随机激活,增加趣味性 + normal_activation_type = ActionActivationType.ALWAYS # Normal模式使用随机激活,增加趣味性 # LLM判定提示词(用于Focus模式) llm_judge_prompt = """ @@ -35,18 +39,13 @@ class VTBAction(PluginAction): 2. 用户询问或讨论情感相关话题 3. 场景需要生动的情感回应 4. 当前回复内容可以通过VTB动作增强表达效果 - -不需要使用的情况: -1. 纯粹的信息查询 -2. 技术性问题讨论 -3. 不涉及情感的日常对话 4. 已经有足够的情感表达 """ # Random激活概率(用于Normal模式) random_activation_probability = 0.08 # 较低概率,避免过度使用 - async def process(self) -> Tuple[bool, str]: + async def execute(self) -> Tuple[bool, str]: """处理VTB虚拟主播动作""" logger.info(f"{self.log_prefix} 执行VTB动作: {self.reasoning}") @@ -61,8 +60,8 @@ class VTBAction(PluginAction): processed_text = self._process_text_for_vtb(text) try: - # 发送VTB动作消息 - await self.send_message(type="vtb_text", data=processed_text) + # 发送VTB动作消息 - 使用新版本的send_type方法 + await self.send_type(type="vtb_text", text=processed_text) logger.info(f"{self.log_prefix} VTB动作执行成功,文本内容: {processed_text}") return True, "VTB动作执行成功" @@ -95,3 +94,39 @@ class VTBAction(PluginAction): processed_text = "平静" return processed_text + + +@register_plugin +class VTBPlugin(BasePlugin): + """VTB虚拟主播插件 + - 这是虚拟主播情感表达插件 + - Normal模式下依靠随机触发增加趣味性 + - Focus模式下由LLM判断触发,精确识别情感表达需求 + - 具有情感文本处理和优化能力 + """ + + # 插件基本信息 + plugin_name = "vtb_plugin" + plugin_description = "虚拟主播情感表达插件" + plugin_version = "0.1.0" + plugin_author = "MaiBot开发团队" + enable_plugin = True + config_file_name = "config.toml" + + def get_plugin_components(self) -> List[Tuple[ComponentInfo, Type]]: + """返回插件包含的组件列表""" + + # 从配置获取组件启用状态 + enable_vtb = self.get_config("components.enable_vtb", True) + components = [] + + # 添加Action组件 + if enable_vtb: + components.append( + ( + VTBAction.get_action_info(name="vtb_action", description="虚拟主播情感表达插件"), + VTBAction, + ) + ) + + return components