Skip to content

Commit 6172b96

Browse files
authored
Merge pull request #1041 from tcmofashi/dev
Fix: 修复vtb_plugin
2 parents 229fa9f + 14337b8 commit 6172b96

8 files changed

Lines changed: 103 additions & 26 deletions

File tree

src/chat/message_receive/message_sender.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ async def _handle_sending_message(self, container: MessageContainer, message: Me
225225
if (
226226
# message.apply_set_reply_logic # 检查标记
227227
# and message.is_head
228-
message.is_head
229-
and (thinking_messages_count > 3 or thinking_messages_length > 200)
230-
and not message.is_private_message()
228+
# message.is_head
229+
# and (thinking_messages_count > 3 or thinking_messages_length > 200) and
230+
not message.is_private_message()
231231
):
232232
logger.debug(
233233
f"[{message.chat_stream.stream_id}] 应用 set_reply 逻辑: {message.processed_plain_text[:20]}..."

src/chat/normal_chat/normal_chat.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ async def _reply_interested_message(self) -> None:
165165
if not items_to_process:
166166
continue
167167

168-
# 处理每条兴趣消息
169-
for msg_id, (message, interest_value, is_mentioned) in items_to_process:
168+
# 并行处理兴趣消息
169+
async def process_single_message(msg_id, message, interest_value, is_mentioned):
170+
"""处理单个兴趣消息"""
170171
try:
171172
# 处理消息
172173
if time.time() - self.start_time > 300:
@@ -184,6 +185,24 @@ async def _reply_interested_message(self) -> None:
184185
finally:
185186
self.interest_dict.pop(msg_id, None)
186187

188+
# 创建并行任务列表
189+
tasks = []
190+
for msg_id, (message, interest_value, is_mentioned) in items_to_process:
191+
task = process_single_message(msg_id, message, interest_value, is_mentioned)
192+
tasks.append(task)
193+
194+
# 并行执行所有任务,限制并发数量避免资源过度消耗
195+
if tasks:
196+
# 使用信号量控制并发数,最多同时处理5个消息
197+
semaphore = asyncio.Semaphore(5)
198+
199+
async def limited_process(task):
200+
async with semaphore:
201+
await task
202+
203+
limited_tasks = [limited_process(task) for task in tasks]
204+
await asyncio.gather(*limited_tasks, return_exceptions=True)
205+
187206
# 改为实例方法, 移除 chat 参数
188207
async def normal_response(self, message: MessageRecv, is_mentioned: bool, interested_rate: float) -> None:
189208
# 新增:如果已停用,直接返回

src/plugins/built_in/tts_plugin/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description = "文字转语音插件"
88

99
# 组件启用控制
1010
[components]
11-
enable_tarots = true
11+
enable_tts = true
1212

1313
# 日志配置
1414
[logging]

src/plugins/built_in/tts_plugin/plugin.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@ def get_plugin_components(self) -> List[Tuple[ComponentInfo, Type]]:
110110

111111
# 从配置获取组件启用状态
112112
enable_tts = self.get_config("components.enable_tts", True)
113-
components = []
114-
115-
# 添加Action组件
113+
components = [] # 添加Action组件
116114
if enable_tts:
117115
components.append(
118116
(
119-
TTSAction.get_action_info(name="tarots_action", description="文字转语音插件"),
117+
TTSAction.get_action_info(name="tts_action", description="文字转语音插件"),
120118
TTSAction,
121119
)
122120
)

src/plugins/built_in/vtb_action/__init__.py

Whitespace-only changes.

src/plugins/built_in/vtb_action/actions/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 虚拟主播情感表达插件配置文件
2+
3+
[plugin]
4+
name = "vtb_plugin"
5+
version = "0.1.0"
6+
enabled = true
7+
description = "虚拟主播情感表达插件"
8+
9+
# 组件启用控制
10+
[components]
11+
enable_vtb = true
12+
13+
# VTB动作配置
14+
[vtb_action]
15+
# 情感表达增强选项
16+
enable_emotion_enhancement = true
17+
max_text_length = 100
18+
default_emotion = "平静"
19+
20+
# 激活概率控制(Normal模式)
21+
random_activation_probability = 0.08
22+
23+
# 日志配置
24+
[logging]
25+
level = "INFO"
26+
prefix = "[VTB]"

src/plugins/built_in/vtb_action/actions/vtb_action.py renamed to src/plugins/built_in/vtb_plugin/plugin.py

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
from src.plugin_system.base.base_plugin import BasePlugin, register_plugin
2+
from src.plugin_system.base.component_types import ComponentInfo
13
from src.common.logger import get_logger
2-
from src.plugin_system.base.base_action import BaseAction as PluginAction, ActionActivationType
3-
from src.plugin_system.base.base_action import register_action
4-
from typing import Tuple
4+
from src.plugin_system.base.base_action import BaseAction, ActionActivationType, ChatMode
5+
from typing import Tuple, List, Type
56

6-
logger = get_logger("vtb_action")
7+
logger = get_logger("vtb")
78

89

9-
@register_action
10-
class VTBAction(PluginAction):
10+
class VTBAction(BaseAction):
1111
"""VTB虚拟主播动作处理类"""
1212

1313
action_name = "vtb_action"
@@ -24,9 +24,13 @@ class VTBAction(PluginAction):
2424
enable_plugin = True # 启用插件
2525
associated_types = ["vtb_text"]
2626

27+
# 模式和并行控制
28+
mode_enable = ChatMode.ALL
29+
parallel_action = True # VTB动作可以与回复并行执行,增强表达效果
30+
2731
# 激活类型设置
2832
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定,精确识别情感表达需求
29-
normal_activation_type = ActionActivationType.RANDOM # Normal模式使用随机激活,增加趣味性
33+
normal_activation_type = ActionActivationType.ALWAYS # Normal模式使用随机激活,增加趣味性
3034

3135
# LLM判定提示词(用于Focus模式)
3236
llm_judge_prompt = """
@@ -35,18 +39,13 @@ class VTBAction(PluginAction):
3539
2. 用户询问或讨论情感相关话题
3640
3. 场景需要生动的情感回应
3741
4. 当前回复内容可以通过VTB动作增强表达效果
38-
39-
不需要使用的情况:
40-
1. 纯粹的信息查询
41-
2. 技术性问题讨论
42-
3. 不涉及情感的日常对话
4342
4. 已经有足够的情感表达
4443
"""
4544

4645
# Random激活概率(用于Normal模式)
4746
random_activation_probability = 0.08 # 较低概率,避免过度使用
4847

49-
async def process(self) -> Tuple[bool, str]:
48+
async def execute(self) -> Tuple[bool, str]:
5049
"""处理VTB虚拟主播动作"""
5150
logger.info(f"{self.log_prefix} 执行VTB动作: {self.reasoning}")
5251

@@ -61,8 +60,8 @@ async def process(self) -> Tuple[bool, str]:
6160
processed_text = self._process_text_for_vtb(text)
6261

6362
try:
64-
# 发送VTB动作消息
65-
await self.send_message(type="vtb_text", data=processed_text)
63+
# 发送VTB动作消息 - 使用新版本的send_type方法
64+
await self.send_type(type="vtb_text", text=processed_text)
6665

6766
logger.info(f"{self.log_prefix} VTB动作执行成功,文本内容: {processed_text}")
6867
return True, "VTB动作执行成功"
@@ -95,3 +94,39 @@ def _process_text_for_vtb(self, text: str) -> str:
9594
processed_text = "平静"
9695

9796
return processed_text
97+
98+
99+
@register_plugin
100+
class VTBPlugin(BasePlugin):
101+
"""VTB虚拟主播插件
102+
- 这是虚拟主播情感表达插件
103+
- Normal模式下依靠随机触发增加趣味性
104+
- Focus模式下由LLM判断触发,精确识别情感表达需求
105+
- 具有情感文本处理和优化能力
106+
"""
107+
108+
# 插件基本信息
109+
plugin_name = "vtb_plugin"
110+
plugin_description = "虚拟主播情感表达插件"
111+
plugin_version = "0.1.0"
112+
plugin_author = "MaiBot开发团队"
113+
enable_plugin = True
114+
config_file_name = "config.toml"
115+
116+
def get_plugin_components(self) -> List[Tuple[ComponentInfo, Type]]:
117+
"""返回插件包含的组件列表"""
118+
119+
# 从配置获取组件启用状态
120+
enable_vtb = self.get_config("components.enable_vtb", True)
121+
components = []
122+
123+
# 添加Action组件
124+
if enable_vtb:
125+
components.append(
126+
(
127+
VTBAction.get_action_info(name="vtb_action", description="虚拟主播情感表达插件"),
128+
VTBAction,
129+
)
130+
)
131+
132+
return components

0 commit comments

Comments
 (0)