feat(chat): refactor logging and integrate no_reply system action
将日志前缀管理集中到context,新增willing_manager依赖,并把no_reply提升为系统级可用动作 - CycleProcessor 统一改从 context 获取 log_prefix - HeartFChatting 引入 willing_manager - ResponseHandler _send_response -> send_response 去下划线统一对外接口 - ActionPlanner 将 no_reply 添加至 current_available_actions
This commit is contained in:
@@ -31,8 +31,6 @@ class CycleProcessor:
|
|||||||
response_handler: 响应处理器,负责生成和发送回复
|
response_handler: 响应处理器,负责生成和发送回复
|
||||||
cycle_tracker: 循环跟踪器,负责记录和管理每次思考循环的信息
|
cycle_tracker: 循环跟踪器,负责记录和管理每次思考循环的信息
|
||||||
"""
|
"""
|
||||||
self.log_prefix = f"[{get_chat_manager().get_stream_name(self.stream_id) or self.stream_id}]"
|
|
||||||
|
|
||||||
self.context = context
|
self.context = context
|
||||||
self.response_handler = response_handler
|
self.response_handler = response_handler
|
||||||
self.cycle_tracker = cycle_tracker
|
self.cycle_tracker = cycle_tracker
|
||||||
@@ -41,6 +39,8 @@ class CycleProcessor:
|
|||||||
action_manager=self.context.action_manager, chat_id=self.context.stream_id
|
action_manager=self.context.action_manager, chat_id=self.context.stream_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.log_prefix = self.context.log_prefix
|
||||||
|
|
||||||
async def _send_and_store_reply(
|
async def _send_and_store_reply(
|
||||||
self,
|
self,
|
||||||
response_set,
|
response_set,
|
||||||
@@ -52,7 +52,7 @@ class CycleProcessor:
|
|||||||
plan_result,
|
plan_result,
|
||||||
) -> Tuple[Dict[str, Any], str, Dict[str, float]]:
|
) -> Tuple[Dict[str, Any], str, Dict[str, float]]:
|
||||||
with Timer("回复发送", cycle_timers):
|
with Timer("回复发送", cycle_timers):
|
||||||
reply_text = await self._send_response(response_set, reply_to_str, loop_start_time, action_message)
|
reply_text = await self.response_handler.send_response(response_set, reply_to_str, loop_start_time, action_message)
|
||||||
|
|
||||||
# 存储reply action信息
|
# 存储reply action信息
|
||||||
person_info_manager = get_person_info_manager()
|
person_info_manager = get_person_info_manager()
|
||||||
@@ -64,7 +64,7 @@ class CycleProcessor:
|
|||||||
action_prompt_display = f"你对{person_name}进行了回复:{reply_text}"
|
action_prompt_display = f"你对{person_name}进行了回复:{reply_text}"
|
||||||
|
|
||||||
await database_api.store_action_info(
|
await database_api.store_action_info(
|
||||||
chat_stream=self.chat_stream,
|
chat_stream=self.context.chat_stream,
|
||||||
action_build_into_prompt=False,
|
action_build_into_prompt=False,
|
||||||
action_prompt_display=action_prompt_display,
|
action_prompt_display=action_prompt_display,
|
||||||
action_done=True,
|
action_done=True,
|
||||||
@@ -248,7 +248,7 @@ class CycleProcessor:
|
|||||||
gather_timeout = global_config.chat.thinking_timeout
|
gather_timeout = global_config.chat.thinking_timeout
|
||||||
try:
|
try:
|
||||||
response_set = await asyncio.wait_for(
|
response_set = await asyncio.wait_for(
|
||||||
self.response_handler._generate_response(
|
self.response_handler.generate_response(
|
||||||
message_data=action_info["action_message"],
|
message_data=action_info["action_message"],
|
||||||
available_actions=action_info["available_actions"],
|
available_actions=action_info["available_actions"],
|
||||||
reply_to=reply_to_str,
|
reply_to=reply_to_str,
|
||||||
@@ -284,7 +284,6 @@ class CycleProcessor:
|
|||||||
"loop_info": None
|
"loop_info": None
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: Where is my fucking _send_and_store_reply?
|
|
||||||
loop_info, reply_text, cycle_timers_reply = await self._send_and_store_reply(
|
loop_info, reply_text, cycle_timers_reply = await self._send_and_store_reply(
|
||||||
response_set,
|
response_set,
|
||||||
reply_to_str,
|
reply_to_str,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from src.chat.express.expression_learner import expression_learner_manager
|
|||||||
from src.plugin_system.base.component_types import ChatMode
|
from src.plugin_system.base.component_types import ChatMode
|
||||||
from src.schedule.schedule_manager import schedule_manager, SleepState
|
from src.schedule.schedule_manager import schedule_manager, SleepState
|
||||||
from src.plugin_system.apis import message_api
|
from src.plugin_system.apis import message_api
|
||||||
|
from src.chat.willing.willing_manager import get_willing_manager
|
||||||
|
|
||||||
from .hfc_context import HfcContext
|
from .hfc_context import HfcContext
|
||||||
from .energy_manager import EnergyManager
|
from .energy_manager import EnergyManager
|
||||||
@@ -59,7 +60,7 @@ class HeartFChatting:
|
|||||||
|
|
||||||
# 记录最近3次的兴趣度
|
# 记录最近3次的兴趣度
|
||||||
self.recent_interest_records: deque = deque(maxlen=3)
|
self.recent_interest_records: deque = deque(maxlen=3)
|
||||||
|
self.willing_manager = get_willing_manager()
|
||||||
self._initialize_chat_mode()
|
self._initialize_chat_mode()
|
||||||
logger.info(f"{self.context.log_prefix} HeartFChatting 初始化完成")
|
logger.info(f"{self.context.log_prefix} HeartFChatting 初始化完成")
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class ResponseHandler:
|
|||||||
- 构建并返回完整的循环信息
|
- 构建并返回完整的循环信息
|
||||||
- 用于上级方法的状态跟踪
|
- 用于上级方法的状态跟踪
|
||||||
"""
|
"""
|
||||||
reply_text = await self._send_response(response_set, reply_to_str, loop_start_time, action_message)
|
reply_text = await self.send_response(response_set, reply_to_str, loop_start_time, action_message)
|
||||||
|
|
||||||
person_info_manager = get_person_info_manager()
|
person_info_manager = get_person_info_manager()
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ class ResponseHandler:
|
|||||||
|
|
||||||
return loop_info, reply_text, cycle_timers
|
return loop_info, reply_text, cycle_timers
|
||||||
|
|
||||||
async def _send_response(self, reply_set, reply_to, thinking_start_time, message_data) -> str:
|
async def send_response(self, reply_set, reply_to, thinking_start_time, message_data) -> str:
|
||||||
"""
|
"""
|
||||||
发送回复内容的具体实现
|
发送回复内容的具体实现
|
||||||
|
|
||||||
|
|||||||
@@ -590,6 +590,20 @@ class ActionPlanner:
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"{self.log_prefix}使用中的动作 {action_name} 未在已注册动作中找到")
|
logger.warning(f"{self.log_prefix}使用中的动作 {action_name} 未在已注册动作中找到")
|
||||||
|
|
||||||
|
# 将no_reply作为系统级特殊动作添加到可用动作中
|
||||||
|
# no_reply虽然是系统级决策,但需要让规划器认为它是可用的
|
||||||
|
no_reply_info = ActionInfo(
|
||||||
|
name="no_reply",
|
||||||
|
component_type=ComponentType.ACTION,
|
||||||
|
description="系统级动作:选择不回复消息的决策",
|
||||||
|
action_parameters={},
|
||||||
|
activation_keywords=[],
|
||||||
|
plugin_name="SYSTEM",
|
||||||
|
enabled=True, # 始终启用
|
||||||
|
parallel_action=False,
|
||||||
|
)
|
||||||
|
current_available_actions["no_reply"] = no_reply_info
|
||||||
|
|
||||||
return is_group_chat, chat_target_info, current_available_actions
|
return is_group_chat, chat_target_info, current_available_actions
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user