feat:允许command设置展示名称,而非指令原文,添加处理器超时,NormalChat转换清理

This commit is contained in:
SengokuCola
2025-05-28 13:49:19 +08:00
parent 7fcd5c9abe
commit 41f97a0bf1
12 changed files with 75 additions and 23 deletions

View File

@@ -373,7 +373,7 @@ class DefaultExpressor:
# --- 发送器 (Sender) --- #
async def send_response_messages(
self, anchor_message: Optional[MessageRecv], response_set: List[Tuple[str, str]], thinking_id: str = ""
self, anchor_message: Optional[MessageRecv], response_set: List[Tuple[str, str]], thinking_id: str = "", display_message: str = ""
) -> Optional[MessageSending]:
"""发送回复消息 (尝试锚定到 anchor_message),使用 HeartFCSender"""
chat = self.chat_stream
@@ -426,6 +426,7 @@ class DefaultExpressor:
anchor_message=anchor_message,
message_id=part_message_id,
message_segment=message_segment,
display_message=display_message,
reply_to=reply_to,
is_emoji=is_emoji,
thinking_id=thinking_id,
@@ -489,6 +490,7 @@ class DefaultExpressor:
is_emoji: bool,
thinking_id: str,
thinking_start_time: float,
display_message: str,
) -> MessageSending:
"""构建单个发送消息"""
@@ -508,6 +510,7 @@ class DefaultExpressor:
is_head=reply_to,
is_emoji=is_emoji,
thinking_start_time=thinking_start_time, # 传递原始思考开始时间
display_message=display_message,
)
return bot_message

View File

@@ -53,6 +53,9 @@ CONSECUTIVE_NO_REPLY_THRESHOLD = 3 # 连续不回复的阈值
logger = get_logger("hfc") # Logger Name Changed
# 设定处理器超时时间(秒)
PROCESSOR_TIMEOUT = 10
async def _handle_cycle_delay(action_taken_this_cycle: bool, cycle_start_time: float, log_prefix: str):
"""处理循环延迟"""
@@ -376,9 +379,13 @@ class HeartFChatting:
for processor in self.processors:
processor_name = processor.__class__.log_prefix
task = asyncio.create_task(
processor.process_info(observations=observations, running_memorys=running_memorys)
)
# 用lambda包裹便于传参
async def run_with_timeout(proc=processor):
return await asyncio.wait_for(
proc.process_info(observations=observations, running_memorys=running_memorys),
timeout=PROCESSOR_TIMEOUT
)
task = asyncio.create_task(run_with_timeout())
processor_tasks.append(task)
task_to_name_map[task] = processor_name
logger.debug(f"{self.log_prefix} 启动处理器任务: {processor_name}")
@@ -404,6 +411,8 @@ class HeartFChatting:
all_plan_info.extend(result_list)
else:
logger.warning(f"{self.log_prefix} 处理器 {processor_name} 返回了 None")
except asyncio.TimeoutError:
logger.error(f"{self.log_prefix} 处理器 {processor_name} 超时(>{PROCESSOR_TIMEOUT}s已跳过")
except Exception as e:
logger.error(
f"{self.log_prefix} 处理器 {processor_name} 执行失败,耗时 (自并行开始): {duration_since_parallel_start:.2f}秒. 错误: {e}",

View File

@@ -137,9 +137,9 @@ class ActionProcessor(BaseProcessor):
# 检查no_reply比例
print(f"no_reply_count: {no_reply_count}, len(recent_cycles): {len(recent_cycles)}")
# print(1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111)
if len(recent_cycles) >= (4 * global_config.focus_chat.exit_focus_threshold) and (
if len(recent_cycles) >= (5 * global_config.focus_chat.exit_focus_threshold) and (
no_reply_count / len(recent_cycles)
) >= (0.6 * global_config.focus_chat.exit_focus_threshold):
) >= (0.8 * global_config.focus_chat.exit_focus_threshold):
if global_config.chat.chat_mode == "auto":
result["add"].append("exit_focus_chat")
result["remove"].append("no_reply")

View File

@@ -111,7 +111,7 @@ class PluginAction(BaseAction):
return platform, user_id
# 提供简化的API方法
async def send_message(self, type: str, data: str, target: Optional[str] = "") -> bool:
async def send_message(self, type: str, data: str, target: Optional[str] = "", display_message: str = "") -> bool:
"""发送消息的简化方法
Args:
@@ -158,6 +158,7 @@ class PluginAction(BaseAction):
success = await expressor.send_response_messages(
anchor_message=anchor_message,
response_set=response_set,
display_message=display_message,
)
return success

View File

@@ -126,6 +126,10 @@ class ActionPlanner:
reasoning = f"之前选择的动作{action}已被移除,原因: {reason}"
# 继续处理其他信息
self_info = ""
current_mind = ""
cycle_info = ""
structured_info = ""
for info in all_plan_info:
if isinstance(info, ObsInfo):
observed_messages = info.get_talking_message()