This commit is contained in:
Windpicker-owo
2025-07-26 21:44:12 +08:00
3 changed files with 45 additions and 28 deletions

View File

@@ -1425,3 +1425,4 @@ def main():
if __name__ == "__main__":
main()

View File

@@ -261,6 +261,9 @@ class HeartFChatting:
message_data = {}
action_type = "no_action"
reply_text = "" # 初始化reply_text变量避免UnboundLocalError
gen_task = None # 初始化gen_task变量避免UnboundLocalError
reply_to_str = "" # 初始化reply_to_str变量
# 创建新的循环信息
cycle_timers, thinking_id = self.start_cycle()
@@ -312,10 +315,9 @@ class HeartFChatting:
"action_prompt": "",
}
target_message = message_data
# 如果normal开始一个回复生成进程先准备好回复其实是和planer同时进行的
gen_task = None
reply_to_str = ""
if self.loop_mode == ChatMode.NORMAL:
# 如果normal模式且不跳过规划器开始一个回复生成进程先准备好回复其实是和planer同时进行的
if not skip_planner:
reply_to_str = await self.build_reply_to_str(message_data)
gen_task = asyncio.create_task(self._generate_response(message_data, available_actions, reply_to_str, "chat.replyer.normal"))
@@ -341,6 +343,8 @@ class HeartFChatting:
f"{self.log_prefix}{global_config.bot.nickname} 决定进行回复, 同时执行{action_type}动作"
)
else:
# 只有在gen_task存在时才进行相关操作
if gen_task is not None:
if not gen_task.done():
gen_task.cancel()
logger.debug(f"{self.log_prefix} 已取消预生成的回复任务")
@@ -359,6 +363,8 @@ class HeartFChatting:
if action_type == "reply" or is_parallel:
# 等待回复生成完毕
if self.loop_mode == ChatMode.NORMAL:
# 只有在gen_task存在时才等待
if gen_task is not None:
gather_timeout = global_config.chat.thinking_timeout
try:
response_set = await asyncio.wait_for(gen_task, timeout=gather_timeout)
@@ -371,6 +377,17 @@ class HeartFChatting:
logger.warning(f"{self.log_prefix}模型未生成回复内容")
return False
else:
# 如果没有预生成任务,直接生成回复
if not reply_to_str:
reply_to_str = await self.build_reply_to_str(action_message)
with Timer("回复生成", cycle_timers):
response_set = await self._generate_response(action_message, available_actions, reply_to_str, "chat.replyer.normal")
if not response_set:
logger.warning(f"{self.log_prefix}模型未生成回复内容")
return False
else:
logger.info(f"{self.log_prefix}{global_config.bot.nickname} 决定进行回复 (focus模式)")
# 构建reply_to字符串

View File

@@ -8,9 +8,8 @@
from typing import List, Tuple, Type
# 导入新插件系统
from src.plugin_system import BasePlugin, register_plugin, ComponentInfo, ActionActivationType
from src.plugin_system import BasePlugin, register_plugin, ComponentInfo
from src.plugin_system.base.config_types import ConfigField
from src.config.config import global_config
# 导入依赖的系统组件
from src.common.logger import get_logger