From 4dc9907fbd6e409b05f2ece00cafa4004d2cfdff Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Fri, 18 Apr 2025 11:29:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/do_tool/tool_use.py | 8 +++-- src/plugins/chat/utils.py | 2 +- src/plugins/chat/utils_image.py | 2 +- .../chat_module/heartFC_chat/pf_chatting.py | 35 +++++++++---------- .../chat_module/heartFC_chat/pfchating.md | 9 ++++- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/do_tool/tool_use.py b/src/do_tool/tool_use.py index 8aad4dbc6..40dc2916a 100644 --- a/src/do_tool/tool_use.py +++ b/src/do_tool/tool_use.py @@ -26,7 +26,7 @@ class ToolUser: @staticmethod async def _build_tool_prompt( - self, message_txt: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None + message_txt: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None ): """构建工具使用的提示词 @@ -133,7 +133,11 @@ class ToolUser: """ try: # 构建提示词 - prompt = await self._build_tool_prompt(message_txt, chat_stream, sub_heartflow) + prompt = await self._build_tool_prompt( + message_txt=message_txt, + chat_stream=chat_stream, + subheartflow=sub_heartflow, + ) # 定义可用工具 tools = self._define_tools() diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index 4bf488082..eaf61af49 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -340,7 +340,7 @@ def random_remove_punctuation(text: str) -> str: def process_llm_response(text: str) -> List[str]: # 先保护颜文字 protected_text, kaomoji_mapping = protect_kaomoji(text) - logger.debug(f"保护颜文字后的文本: {protected_text}") + logger.trace(f"保护颜文字后的文本: {protected_text}") # 提取被 () 或 [] 包裹的内容 pattern = re.compile(r"[\(\[\(].*?[\)\]\)]") # _extracted_contents = pattern.findall(text) diff --git a/src/plugins/chat/utils_image.py b/src/plugins/chat/utils_image.py index e944fbeaa..acdbab011 100644 --- a/src/plugins/chat/utils_image.py +++ b/src/plugins/chat/utils_image.py @@ -112,7 +112,7 @@ class ImageManager: # 查询缓存的描述 cached_description = self._get_description_from_db(image_hash, "emoji") if cached_description: - logger.debug(f"缓存表情包描述: {cached_description}") + # logger.debug(f"缓存表情包描述: {cached_description}") return f"[表情包:{cached_description}]" # 调用AI获取描述 diff --git a/src/plugins/chat_module/heartFC_chat/pf_chatting.py b/src/plugins/chat_module/heartFC_chat/pf_chatting.py index 84d3271e8..9c4f58a5f 100644 --- a/src/plugins/chat_module/heartFC_chat/pf_chatting.py +++ b/src/plugins/chat_module/heartFC_chat/pf_chatting.py @@ -180,18 +180,18 @@ class PFChatting: def _handle_loop_completion(self, task: asyncio.Task): - """Callback executed when the _run_pf_loop task finishes.""" + """当 _run_pf_loop 任务完成时执行的回调。""" log_prefix = self._get_log_prefix() try: # Check if the task raised an exception exception = task.exception() if exception: - logger.error(f"{log_prefix} PF loop task completed with error: {exception}") + logger.error(f"{log_prefix} PFChatting: 麦麦脱离了聊天(异常)") logger.error(traceback.format_exc()) else: - logger.info(f"{log_prefix} PF loop task completed normally (timer likely expired or cancelled).") + logger.debug(f"{log_prefix} PFChatting: 麦麦脱离了聊天") except asyncio.CancelledError: - logger.info(f"{log_prefix} PF loop task was cancelled.") + logger.info(f"{log_prefix} PFChatting: 麦麦脱离了聊天(异常取消)") finally: # Reset state regardless of how the task finished self._loop_active = False @@ -200,9 +200,8 @@ class PFChatting: self._trigger_count_this_activation = 0 # 重置计数器 # Ensure lock is released if the loop somehow exited while holding it if self._processing_lock.locked(): - logger.warning(f"{log_prefix} Releasing processing lock after loop task completion.") + logger.warning(f"{log_prefix} PFChatting: 锁没有正常释放") self._processing_lock.release() - logger.info(f"{log_prefix} Loop state reset.") async def _run_pf_loop(self): @@ -210,14 +209,14 @@ class PFChatting: 主循环,当计时器>0时持续进行计划并可能回复消息 管理每个循环周期的处理锁 """ - logger.info(f"{self._get_log_prefix()} 开始执行PF循环") + logger.info(f"{self._get_log_prefix()} PFChatting: 麦麦打算好好聊聊") try: while True: # 使用计时器锁安全地检查当前计时器值 async with self._timer_lock: current_timer = self._loop_timer if current_timer <= 0: - logger.info(f"{self._get_log_prefix()} 计时器为零或负数({current_timer:.1f}秒),退出PF循环") + logger.info(f"{self._get_log_prefix()} PFChatting: 聊太久了,麦麦打算休息一下(已经聊了{current_timer:.1f}秒),退出PFChatting") break # 退出条件:计时器到期 # 记录循环开始时间 @@ -230,7 +229,7 @@ class PFChatting: try: await self._processing_lock.acquire() acquired_lock = True - logger.debug(f"{self._get_log_prefix()} 循环获取到处理锁") + # logger.debug(f"{self._get_log_prefix()} PFChatting: 循环获取到处理锁") # --- Planner --- # Planner decides action, reasoning, emoji_query, etc. @@ -243,7 +242,7 @@ class PFChatting: observed_messages = planner_result.get("observed_messages", []) # Planner needs to return this if action == "text_reply": - logger.info(f"{self._get_log_prefix()} 计划循环决定: 回复文本.") + logger.info(f"{self._get_log_prefix()} PFChatting: 麦麦决定回复文本.") action_taken_this_cycle = True # --- 回复器 --- anchor_message = await self._get_anchor_message(observed_messages) @@ -284,7 +283,7 @@ class PFChatting: self._cleanup_thinking_message(thinking_id) # 清理思考消息 elif action == "emoji_reply": - logger.info(f"{self._get_log_prefix()} 计划循环决定: 回复表情 ('{emoji_query}').") + logger.info(f"{self._get_log_prefix()} PFChatting: 麦麦决定回复表情 ('{emoji_query}').") action_taken_this_cycle = True anchor = await self._get_anchor_message(observed_messages) if anchor: @@ -296,15 +295,15 @@ class PFChatting: logger.warning(f"{self._get_log_prefix()} 循环: 无法发送表情, 无法获取锚点.") elif action == "no_reply": - logger.info(f"{self._get_log_prefix()} 计划循环决定: 不回复. 原因: {reasoning}") + logger.info(f"{self._get_log_prefix()} PFChatting: 麦麦决定不回复. 原因: {reasoning}") # Do nothing else, action_taken_this_cycle remains False elif action == "error": - logger.error(f"{self._get_log_prefix()} 计划循环返回错误或失败. 原因: {reasoning}") + logger.error(f"{self._get_log_prefix()} PFChatting: 麦麦回复出错. 原因: {reasoning}") # 视为非操作周期 else: # Unknown action - logger.warning(f"{self._get_log_prefix()} 计划循环返回未知动作: {action}. 视为不回复.") + logger.warning(f"{self._get_log_prefix()} PFChatting: 麦麦做了奇怪的事情. 原因: {reasoning}") # 视为非操作周期 except Exception as e_cycle: @@ -327,7 +326,7 @@ class PFChatting: cycle_duration = time.monotonic() - loop_cycle_start_time async with self._timer_lock: self._loop_timer -= cycle_duration - logger.debug(f"{self._get_log_prefix()} 循环周期耗时 {cycle_duration:.2f}s. 计时器剩余: {self._loop_timer:.1f}s.") + logger.debug(f"{self._get_log_prefix()} PFChatting: 麦麦聊了{cycle_duration:.2f}秒. 还能聊: {self._loop_timer:.1f}s.") # --- Delay --- # Add a small delay, especially if no action was taken, to prevent busy-waiting @@ -342,17 +341,17 @@ class PFChatting: break # Exit loop if cancelled during sleep except asyncio.CancelledError: - logger.info(f"{self._get_log_prefix()} PF loop task received cancellation request.") + logger.info(f"{self._get_log_prefix()} PFChatting: 麦麦的聊天被取消了") except Exception as e_loop_outer: # Catch errors outside the main cycle lock (should be rare) - logger.error(f"{self._get_log_prefix()} PF loop encountered unexpected outer error: {e_loop_outer}") + logger.error(f"{self._get_log_prefix()} PFChatting: 麦麦的聊天出错了: {e_loop_outer}") logger.error(traceback.format_exc()) finally: # Reset trigger count when loop finishes async with self._timer_lock: self._trigger_count_this_activation = 0 logger.debug(f"{self._get_log_prefix()} Trigger count reset to 0 as loop finishes.") - logger.info(f"{self._get_log_prefix()} PF loop finished execution run.") + logger.info(f"{self._get_log_prefix()} PFChatting: 麦麦的聊天结束了") # State reset (_loop_active, _loop_task) is handled by _handle_loop_completion callback async def _planner(self) -> Dict[str, Any]: diff --git a/src/plugins/chat_module/heartFC_chat/pfchating.md b/src/plugins/chat_module/heartFC_chat/pfchating.md index 480e84aff..81aec4558 100644 --- a/src/plugins/chat_module/heartFC_chat/pfchating.md +++ b/src/plugins/chat_module/heartFC_chat/pfchating.md @@ -19,4 +19,11 @@ pfchating有以下几个组成部分: 2.observe_text传入进来是纯str,是不是应该传进来message构成的list?(fix) 3.检查失败的回复应该怎么处理?(先抛弃) 4.如何比较相似度? -5.planner怎么写?(好像可以先不加入这部分) \ No newline at end of file +5.planner怎么写?(好像可以先不加入这部分) + +BUG: +1.第一条激活消息没有被读取,进入pfc聊天委托时应该读取一下之前的上文 +2.复读,可能是planner还未校准好 +3.planner还未个性化,需要加入bot个性信息,且获取的聊天内容有问题 +4.心流好像过短,而且有时候没有等待更新 +5.表情包有可能会发两次 \ No newline at end of file