From ee9f0b88df313d441b1677777d81fe0b31996bea Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 23 Jun 2025 17:10:12 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/focus_chat/heartFC_chat.py | 25 ++++++++++++++----- src/chat/focus_chat/hfc_performance_logger.py | 13 +++++----- src/chat/utils/statistic.py | 18 +++++++------ src/plugins/built_in/core_actions/plugin.py | 10 ++++---- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/chat/focus_chat/heartFC_chat.py b/src/chat/focus_chat/heartFC_chat.py index 584aa4087..9bbb3e67e 100644 --- a/src/chat/focus_chat/heartFC_chat.py +++ b/src/chat/focus_chat/heartFC_chat.py @@ -466,7 +466,9 @@ class HeartFChatting: formatted_ptime = f"{ptime * 1000:.2f}毫秒" if ptime < 1 else f"{ptime:.2f}秒" post_processor_time_strings.append(f"{pname}: {formatted_ptime}") post_processor_time_log = ( - ("\n后处理器耗时: " + "; ".join(post_processor_time_strings)) if post_processor_time_strings else "" + ("\n后处理器耗时: " + "; ".join(post_processor_time_strings)) + if post_processor_time_strings + else "" ) logger.info( @@ -769,7 +771,9 @@ class HeartFChatting: return updated_action_data - async def _process_post_planning_processors_with_timing(self, observations: List[Observation], action_data: dict) -> tuple[dict, dict]: + async def _process_post_planning_processors_with_timing( + self, observations: List[Observation], action_data: dict + ) -> tuple[dict, dict]: """ 处理后期处理器(规划后执行的处理器)并收集详细时间统计 包括:关系处理器、表达选择器、记忆激活器 @@ -883,7 +887,9 @@ class HeartFChatting: ) elif task_type == "memory": post_processor_time_costs["MemoryActivator"] = elapsed_time - logger.warning(f"{self.log_prefix} 记忆激活器超时(>{MEMORY_ACTIVATION_TIMEOUT}s),已跳过,耗时: {elapsed_time:.3f}秒") + logger.warning( + f"{self.log_prefix} 记忆激活器超时(>{MEMORY_ACTIVATION_TIMEOUT}s),已跳过,耗时: {elapsed_time:.3f}秒" + ) running_memorys = [] except Exception as e: # 对于异常任务,记录已用时间 @@ -896,7 +902,10 @@ class HeartFChatting: ) elif task_type == "memory": post_processor_time_costs["MemoryActivator"] = elapsed_time - logger.error(f"{self.log_prefix} 记忆激活器执行失败,耗时: {elapsed_time:.3f}秒. 错误: {e}", exc_info=True) + logger.error( + f"{self.log_prefix} 记忆激活器执行失败,耗时: {elapsed_time:.3f}秒. 错误: {e}", + exc_info=True, + ) running_memorys = [] # 将后期处理器的结果整合到 action_data 中 @@ -938,7 +947,9 @@ class HeartFChatting: # 输出详细统计信息 if post_processor_time_costs: - stats_str = ", ".join([f"{name}: {time_cost:.3f}s" for name, time_cost in post_processor_time_costs.items()]) + stats_str = ", ".join( + [f"{name}: {time_cost:.3f}s" for name, time_cost in post_processor_time_costs.items()] + ) logger.info(f"{self.log_prefix} 后期处理器详细耗时统计: {stats_str}") return updated_action_data, post_processor_time_costs @@ -1048,7 +1059,9 @@ class HeartFChatting: logger.debug(f"{self.log_prefix} 执行后期处理器(动作类型: {action_type})") # 记录详细的后处理器时间 post_start_time = time.time() - action_data, post_processor_time_costs = await self._process_post_planning_processors_with_timing(self.observations, action_data) + action_data, post_processor_time_costs = await self._process_post_planning_processors_with_timing( + self.observations, action_data + ) post_end_time = time.time() logger.info(f"{self.log_prefix} 后期处理器总耗时: {post_end_time - post_start_time:.3f}秒") else: diff --git a/src/chat/focus_chat/hfc_performance_logger.py b/src/chat/focus_chat/hfc_performance_logger.py index 4d7e0561b..2b7f44070 100644 --- a/src/chat/focus_chat/hfc_performance_logger.py +++ b/src/chat/focus_chat/hfc_performance_logger.py @@ -57,15 +57,14 @@ class HFCPerformanceLogger: log_parts = [ f"cycle_id={record['cycle_id']}", f"action={record['action_type']}", - f"time={record['total_time']:.2f}s" + f"time={record['total_time']:.2f}s", ] - + # 添加后处理器时间信息到日志 - if record['post_processor_time_costs']: - post_processor_stats = ", ".join([ - f"{name}: {time_cost:.3f}s" - for name, time_cost in record['post_processor_time_costs'].items() - ]) + if record["post_processor_time_costs"]: + post_processor_stats = ", ".join( + [f"{name}: {time_cost:.3f}s" for name, time_cost in record["post_processor_time_costs"].items()] + ) log_parts.append(f"post_processors=({post_processor_stats})") logger.debug(f"记录HFC循环数据: {', '.join(log_parts)}") diff --git a/src/chat/utils/statistic.py b/src/chat/utils/statistic.py index 59c7dc164..68b1d68d1 100644 --- a/src/chat/utils/statistic.py +++ b/src/chat/utils/statistic.py @@ -60,7 +60,7 @@ FOCUS_AVG_TIMES_BY_VERSION = "focus_avg_times_by_version" # 新增: 后处理器统计数据的键 FOCUS_POST_PROCESSOR_TIMES = "focus_post_processor_times" -FOCUS_POST_PROCESSOR_COUNT = "focus_post_processor_count" +FOCUS_POST_PROCESSOR_COUNT = "focus_post_processor_count" FOCUS_POST_PROCESSOR_SUCCESS_RATE = "focus_post_processor_success_rate" FOCUS_PROCESSOR_TIMES = "focus_processor_times" # 前处理器统计 @@ -566,7 +566,7 @@ class StatisticOutputTask(AsyncTask): total_time = cycle_data.get("total_time", 0.0) step_times = cycle_data.get("step_times", {}) version = cycle_data.get("version", "unknown") - + # 新增:获取前处理器和后处理器时间 processor_time_costs = cycle_data.get("processor_time_costs", {}) post_processor_time_costs = cycle_data.get("post_processor_time_costs", {}) @@ -930,7 +930,7 @@ class StatisticOutputTask(AsyncTask): # format总在线时间 # 按模型分类统计 - model_rows = "\n".join( + "\n".join( [ f"" f"{model_name}" @@ -944,7 +944,7 @@ class StatisticOutputTask(AsyncTask): ] ) # 按请求类型分类统计 - type_rows = "\n".join( + "\n".join( [ f"" f"{req_type}" @@ -958,7 +958,7 @@ class StatisticOutputTask(AsyncTask): ] ) # 按模块分类统计 - module_rows = "\n".join( + "\n".join( [ f"" f"{module_name}" @@ -973,7 +973,7 @@ class StatisticOutputTask(AsyncTask): ) # 聊天消息统计 - chat_rows = "\n".join( + "\n".join( [ f"{self.name_mapping[chat_id][0]}{count}" for chat_id, count in sorted(stat_data[MSG_CNT_BY_CHAT].items()) @@ -1028,7 +1028,7 @@ class StatisticOutputTask(AsyncTask): basic_stages = ["观察", "并行调整动作、处理", "规划器", "后期处理器", "动作执行"] existing_basic_stages = [] for stage in basic_stages: - # 检查是否有任何聊天流在这个阶段有数据 + # 检查是否有任何聊天流在这个阶段有数据 stage_exists = False for _chat_id, stage_times in stat_data[FOCUS_AVG_TIMES_BY_CHAT_ACTION].items(): if stage in stage_times: @@ -1275,7 +1275,9 @@ class StatisticOutputTask(AsyncTask): for processor_name in sorted(stat_data[FOCUS_POST_PROCESSOR_TIMES].keys()): avg_time = stat_data[FOCUS_POST_PROCESSOR_TIMES][processor_name] count = stat_data[FOCUS_POST_PROCESSOR_COUNT].get(processor_name, 0) - post_processor_rows.append(f"{processor_name}{avg_time:.3f}秒{count}") + post_processor_rows.append( + f"{processor_name}{avg_time:.3f}秒{count}" + ) focus_post_processor_rows = "\n".join(post_processor_rows) # 计算时间范围 diff --git a/src/plugins/built_in/core_actions/plugin.py b/src/plugins/built_in/core_actions/plugin.py index e263c59b1..ac30477f8 100644 --- a/src/plugins/built_in/core_actions/plugin.py +++ b/src/plugins/built_in/core_actions/plugin.py @@ -233,10 +233,10 @@ class NoReplyAction(BaseAction): # 判定条件:累计3条消息或等待超过5秒且有新消息 time_since_last_judge = current_time - last_judge_time should_judge = ( - new_message_count >= 3 or # 累计3条消息 - (new_message_count > 0 and time_since_last_judge >= 5.0) # 等待超过5秒且有新消息 + new_message_count >= 3 # 累计3条消息 + or (new_message_count > 0 and time_since_last_judge >= 5.0) # 等待超过5秒且有新消息 ) - + if should_judge and time_since_last_judge >= min_judge_interval: # 判断触发原因 trigger_reason = "" @@ -244,7 +244,7 @@ class NoReplyAction(BaseAction): trigger_reason = f"累计{new_message_count}条消息" elif time_since_last_judge >= 5.0: trigger_reason = f"等待{time_since_last_judge:.1f}秒且有{new_message_count}条新消息" - + logger.info(f"{self.log_prefix} 触发判定({trigger_reason}),进行智能判断...") # 获取最近的消息内容用于判断 @@ -326,7 +326,7 @@ class NoReplyAction(BaseAction): if self._skip_judge_when_tired and random.random() < skip_probability: should_skip_llm_judge = True logger.info( - f"{self.log_prefix} 发言过多(超过{over_count}条),随机决定跳过此次LLM判断(概率{skip_probability*100:.0f}%)" + f"{self.log_prefix} 发言过多(超过{over_count}条),随机决定跳过此次LLM判断(概率{skip_probability * 100:.0f}%)" ) logger.info(