From b24358cc29d3678524ac89bdcd6e3f01bbdcf268 Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 25 Apr 2025 03:39:14 +0800 Subject: [PATCH 01/12] Update Dockerfile and workflows to add MaiMBot-LPMM support Added MaiMBot-LPMM directory in Dockerfile and its repository clone step in the GitHub workflow. Upgraded compiler setup to use build-essential and included a CPU info check in the Dockerfile. --- .github/workflows/docker-image.yml | 3 +++ Dockerfile | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 76636d746..605d838ce 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -24,6 +24,9 @@ jobs: - name: Clone maim_message run: git clone https://github.com/MaiM-with-u/maim_message maim_message + - name: Clone lpmm + run: git clone https://github.com/MaiM-with-u/MaiMBot-LPMM.git MaiMBot-LPMM + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 diff --git a/Dockerfile b/Dockerfile index 074711523..10b6b77fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,13 @@ WORKDIR /MaiMBot COPY requirements.txt . # 同级目录下需要有 maim_message COPY maim_message /maim_message +COPY MaiMBot-LPMM /MaiMBot-LPMM # 编译器 -RUN apt-get update && apt-get install -y g++ +RUN apt-get update && apt-get install -y build-essential + +# test +RUN cat /proc/cpuinfo | grep avx2 # 安装依赖 RUN uv pip install --system --upgrade pip From db7543dd8dcaa5aec721cc826c128205e9485f0c Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 25 Apr 2025 03:40:03 +0800 Subject: [PATCH 02/12] =?UTF-8?q?test:=20test=E6=9F=A5=E7=9C=8Bcpu?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 10b6b77fb..6ef7070da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,7 @@ COPY MaiMBot-LPMM /MaiMBot-LPMM RUN apt-get update && apt-get install -y build-essential # test +RUN cat /proc/cpuinfo RUN cat /proc/cpuinfo | grep avx2 # 安装依赖 From c7aff644acde491e1428929d6980f1f8f8fec18b Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 25 Apr 2025 04:01:57 +0800 Subject: [PATCH 03/12] =?UTF-8?q?test:=20test=E6=9F=A5=E7=9C=8Bcpu?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- test_cpu.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test_cpu.py diff --git a/Dockerfile b/Dockerfile index 6ef7070da..39df23381 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,8 @@ RUN apt-get update && apt-get install -y build-essential # test RUN cat /proc/cpuinfo -RUN cat /proc/cpuinfo | grep avx2 +RUN uv pip install --system py-cpuinfo +RUN python test_cpu.py # 安装依赖 RUN uv pip install --system --upgrade pip diff --git a/test_cpu.py b/test_cpu.py new file mode 100644 index 000000000..befb40ec5 --- /dev/null +++ b/test_cpu.py @@ -0,0 +1,5 @@ +import cpuinfo + +cpu_info = cpuinfo.get_cpu_info() +print(f"当前cpu信息:{cpu_info}") +print(f"当前cpu指令集支持:{cpu_info["flags"]}") \ No newline at end of file From 380888a81a2cae11c0036db0b3c02713c94f7091 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 24 Apr 2025 20:02:19 +0000 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=A0=BC=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 --- test_cpu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_cpu.py b/test_cpu.py index befb40ec5..84b3d2f5d 100644 --- a/test_cpu.py +++ b/test_cpu.py @@ -2,4 +2,4 @@ import cpuinfo cpu_info = cpuinfo.get_cpu_info() print(f"当前cpu信息:{cpu_info}") -print(f"当前cpu指令集支持:{cpu_info["flags"]}") \ No newline at end of file +print(f"当前cpu指令集支持:{cpu_info['flags']}") From 72212ebfe21f424a6eaf32ab7b05add3f51bea83 Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 25 Apr 2025 04:04:34 +0800 Subject: [PATCH 05/12] =?UTF-8?q?test:=20test=E6=9F=A5=E7=9C=8Bcpu?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 39df23381..a9f84ccdc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ COPY requirements.txt . # 同级目录下需要有 maim_message COPY maim_message /maim_message COPY MaiMBot-LPMM /MaiMBot-LPMM +COPY test_cpu.py /test_cpu.py # 编译器 RUN apt-get update && apt-get install -y build-essential @@ -16,7 +17,7 @@ RUN apt-get update && apt-get install -y build-essential # test RUN cat /proc/cpuinfo RUN uv pip install --system py-cpuinfo -RUN python test_cpu.py +RUN python /test_cpu.py # 安装依赖 RUN uv pip install --system --upgrade pip From 4e222afacc321306243226fe97fdd92022f71e56 Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 25 Apr 2025 04:31:50 +0800 Subject: [PATCH 06/12] =?UTF-8?q?test:=20test=E6=9F=A5=E7=9C=8Bcpu?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 2 +- Dockerfile | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 605d838ce..3bd4a21bc 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -25,7 +25,7 @@ jobs: run: git clone https://github.com/MaiM-with-u/maim_message maim_message - name: Clone lpmm - run: git clone https://github.com/MaiM-with-u/MaiMBot-LPMM.git MaiMBot-LPMM + run: git clone https://github.com/infinitycat233/MaiMBot-LPMM.git MaiMBot-LPMM - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 diff --git a/Dockerfile b/Dockerfile index a9f84ccdc..24294125a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,9 @@ RUN apt-get update && apt-get install -y build-essential RUN cat /proc/cpuinfo RUN uv pip install --system py-cpuinfo RUN python /test_cpu.py +RUN cd /MaiMBot-LPMM && uv pip install --system -r requirements.txt +RUN cd /MaiMBot-LPMM/lib/quick_algo && python build_lib.py --cleanup --cythonize --install + # 安装依赖 RUN uv pip install --system --upgrade pip From 5e423a092eb782ed411d08f93970499fb887204f Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 25 Apr 2025 04:34:54 +0800 Subject: [PATCH 07/12] =?UTF-8?q?test:=20test=E6=9F=A5=E7=9C=8Bcpu?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 24294125a..e055bf68f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ RUN apt-get update && apt-get install -y build-essential RUN cat /proc/cpuinfo RUN uv pip install --system py-cpuinfo RUN python /test_cpu.py -RUN cd /MaiMBot-LPMM && uv pip install --system -r requirements.txt +RUN cd /MaiMBot-LPMM && uv pip install --system -r requirements.txt && uv pip install --system Cython py-cpuinfo setuptools RUN cd /MaiMBot-LPMM/lib/quick_algo && python build_lib.py --cleanup --cythonize --install From f1414175f5b00745429b11d452b1f40c19b183da Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 25 Apr 2025 06:33:40 +0800 Subject: [PATCH 08/12] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96dockerfile?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4test=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 15 ++++++--------- test_cpu.py | 5 ----- 2 files changed, 6 insertions(+), 14 deletions(-) delete mode 100644 test_cpu.py diff --git a/Dockerfile b/Dockerfile index e055bf68f..23165a23e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,25 +6,22 @@ WORKDIR /MaiMBot # 复制依赖列表 COPY requirements.txt . -# 同级目录下需要有 maim_message -COPY maim_message /maim_message +# 同级目录下需要有 maim_message MaiMBot-LPMM +#COPY maim_message /maim_message COPY MaiMBot-LPMM /MaiMBot-LPMM -COPY test_cpu.py /test_cpu.py # 编译器 RUN apt-get update && apt-get install -y build-essential -# test -RUN cat /proc/cpuinfo -RUN uv pip install --system py-cpuinfo -RUN python /test_cpu.py -RUN cd /MaiMBot-LPMM && uv pip install --system -r requirements.txt && uv pip install --system Cython py-cpuinfo setuptools +# lpmm编译安装 +RUN cd /MaiMBot-LPMM && uv pip install --system -r requirements.txt +RUN uv pip install --system Cython py-cpuinfo setuptools RUN cd /MaiMBot-LPMM/lib/quick_algo && python build_lib.py --cleanup --cythonize --install # 安装依赖 RUN uv pip install --system --upgrade pip -RUN uv pip install --system -e /maim_message +#RUN uv pip install --system -e /maim_message RUN uv pip install --system -r requirements.txt # 复制项目代码 diff --git a/test_cpu.py b/test_cpu.py deleted file mode 100644 index 84b3d2f5d..000000000 --- a/test_cpu.py +++ /dev/null @@ -1,5 +0,0 @@ -import cpuinfo - -cpu_info = cpuinfo.get_cpu_info() -print(f"当前cpu信息:{cpu_info}") -print(f"当前cpu指令集支持:{cpu_info['flags']}") From b7938f016f22d80e76d338804f12cced63e0178e Mon Sep 17 00:00:00 2001 From: 114514 <2514624910@qq.com> Date: Fri, 25 Apr 2025 12:21:43 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPFC=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E9=87=8D=E8=AF=95=E6=AC=A1=E6=95=B0=EF=BC=8C=E4=BD=BF=E5=85=B6?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=90=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复checker的最大重试次数,使其重新启用(似乎在之前所有版本中从来没有启用过?)达到最大重试次数自动wait,并且加入了更详细的reply_checker报错日志 --- src/plugins/PFC/conversation.py | 118 ++++++++++++++++++------------- src/plugins/PFC/reply_checker.py | 10 +-- 2 files changed, 75 insertions(+), 53 deletions(-) diff --git a/src/plugins/PFC/conversation.py b/src/plugins/PFC/conversation.py index d4888ff79..39ebccc1d 100644 --- a/src/plugins/PFC/conversation.py +++ b/src/plugins/PFC/conversation.py @@ -248,54 +248,70 @@ class Conversation: # --- 根据不同的 action 执行 --- if action == "direct_reply": - # --- 这个 if 块内部的所有代码都需要正确缩进 --- - self.waiter.wait_accumulated_time = 0 # 重置等待时间 - - self.state = ConversationState.GENERATING - # 生成回复 - self.generated_reply = await self.reply_generator.generate(observation_info, conversation_info) - logger.info(f"生成回复: {self.generated_reply}") # 使用 logger - - # --- 调用 ReplyChecker 检查回复 --- - is_suitable = False # 先假定不合适,检查通过再改为 True - check_reason = "检查未执行" # 用不同的变量名存储检查原因 + max_reply_attempts = 3 # 设置最大尝试次数(与 reply_checker.py 中的 max_retries 保持一致或稍大) + reply_attempt_count = 0 + is_suitable = False need_replan = False - try: - # 尝试获取当前主要目标 - current_goal_str = conversation_info.goal_list[0][0] if conversation_info.goal_list else "" + check_reason = "未进行尝试" + final_reply_to_send = "" - # 调用检查器 - is_suitable, check_reason, need_replan = await self.reply_generator.check_reply( - reply=self.generated_reply, - goal=current_goal_str, - chat_history=observation_info.chat_history, # 传入最新的历史记录! - retry_count=0, - ) - logger.info(f"回复检查结果: 合适={is_suitable}, 原因='{check_reason}', 需重新规划={need_replan}") + while reply_attempt_count < max_reply_attempts and not is_suitable: + reply_attempt_count += 1 + logger.info(f"尝试生成回复 (第 {reply_attempt_count}/{max_reply_attempts} 次)...") + self.state = ConversationState.GENERATING - except Exception as check_err: - logger.error(f"调用 ReplyChecker 时出错: {check_err}") - check_reason = f"检查过程出错: {check_err}" # 记录错误原因 - # is_suitable 保持 False + # 1. 生成回复 + self.generated_reply = await self.reply_generator.generate(observation_info, conversation_info) + logger.info(f"第 {reply_attempt_count} 次生成的回复: {self.generated_reply}") - # --- 处理检查结果 --- + # 2. 检查回复 + self.state = ConversationState.CHECKING + try: + current_goal_str = conversation_info.goal_list[0][0] if conversation_info.goal_list else "" + # 注意:这里传递的是 reply_attempt_count - 1 作为 retry_count 给 checker + is_suitable, check_reason, need_replan = await self.reply_generator.check_reply( + reply=self.generated_reply, + goal=current_goal_str, + chat_history=observation_info.chat_history, + retry_count=reply_attempt_count - 1, # 传递当前尝试次数(从0开始计数) + ) + logger.info(f"第 {reply_attempt_count} 次检查结果: 合适={is_suitable}, 原因='{check_reason}', 需重新规划={need_replan}") + + if is_suitable: + final_reply_to_send = self.generated_reply # 保存合适的回复 + break # 回复合适,跳出循环 + + elif need_replan: + logger.warning(f"第 {reply_attempt_count} 次检查建议重新规划,停止尝试。原因: {check_reason}") + break # 如果检查器建议重新规划,也停止尝试 + + # 如果不合适但不需要重新规划,循环会继续进行下一次尝试 + except Exception as check_err: + logger.error(f"第 {reply_attempt_count} 次调用 ReplyChecker 时出错: {check_err}") + check_reason = f"第 {reply_attempt_count} 次检查过程出错: {check_err}" + # 如果检查本身出错,可以选择跳出循环或继续尝试 + # 这里选择跳出循环,避免无限循环在检查错误上 + break + + # 循环结束,处理最终结果 if is_suitable: - # 回复合适,继续执行 - # 检查是否有新消息进来 + # 回复合适且已保存在 final_reply_to_send 中 + # 检查是否有新消息进来 (在所有尝试结束后再检查一次) if self._check_new_messages_after_planning(): - logger.info("检查到新消息,取消发送已生成的回复,重新规划行动") - # 更新 action 状态为 recall + logger.info("生成回复期间收到新消息,取消发送,重新规划行动") conversation_info.done_action[action_index].update( { "status": "recall", - "reason": f"有新消息,取消发送: {self.generated_reply}", # 更新原因 + "final_reason": f"有新消息,取消发送: {final_reply_to_send}", "time": datetime.datetime.now().strftime("%H:%M:%S"), } ) - return None # 退出 _handle_action + # 这里直接返回,不执行后续发送和wait + return - # 发送回复 - await self._send_reply() # 这个函数内部会处理自己的错误 + # 发送合适的回复 + self.generated_reply = final_reply_to_send # 确保 self.generated_reply 是最终要发送的内容 + await self._send_reply() # 更新 action 历史状态为 done conversation_info.done_action[action_index].update( @@ -306,26 +322,30 @@ class Conversation: ) else: - # 回复不合适 - logger.warning(f"生成的回复被 ReplyChecker 拒绝: '{self.generated_reply}'. 原因: {check_reason}") - # 更新 action 状态为 recall (因为没执行发送) + # 循环结束但没有找到合适的回复(达到最大次数或检查出错/建议重规划) + logger.warning(f"经过 {reply_attempt_count} 次尝试,未能生成合适的回复。最终原因: {check_reason}") conversation_info.done_action[action_index].update( { - "status": "recall", - "final_reason": check_reason, + "status": "recall", # 标记为 recall 因为没有成功发送 + "final_reason": f"尝试{reply_attempt_count}次后失败: {check_reason}", "time": datetime.datetime.now().strftime("%H:%M:%S"), } ) - # 如果检查器建议重新规划 - if need_replan: - logger.info("ReplyChecker 建议重新规划目标。") - # 可选:在此处清空目标列表以强制重新规划 - # conversation_info.goal_list = [] - - # 注意:不发送消息,也不执行后面的代码 - - # --- 之前重复的代码块已被删除 --- + # 执行 Wait 操作 + logger.info("由于无法生成合适回复,执行 'wait' 操作...") + self.state = ConversationState.WAITING + # 直接调用 wait 方法 + await self.waiter.wait(self.conversation_info) + # 可以选择添加一条新的 action 记录来表示这个 wait + wait_action_record = { + "action": "wait", + "plan_reason": "因 direct_reply 多次尝试失败而执行的后备等待", + "status": "done", # wait 完成后可以认为是 done + "time": datetime.datetime.now().strftime("%H:%M:%S"), + "final_reason": None, + } + conversation_info.done_action.append(wait_action_record) elif action == "fetch_knowledge": self.waiter.wait_accumulated_time = 0 diff --git a/src/plugins/PFC/reply_checker.py b/src/plugins/PFC/reply_checker.py index 7e43715bf..312387f31 100644 --- a/src/plugins/PFC/reply_checker.py +++ b/src/plugins/PFC/reply_checker.py @@ -15,11 +15,11 @@ class ReplyChecker: def __init__(self, stream_id: str): self.llm = LLMRequest( - model=global_config.llm_PFC_reply_checker, temperature=0.55, max_tokens=1000, request_type="reply_check" + model=global_config.llm_PFC_reply_checker, temperature=0.50, max_tokens=1000, request_type="reply_check" ) self.name = global_config.BOT_NICKNAME self.chat_observer = ChatObserver.get_instance(stream_id) - self.max_retries = 2 # 最大重试次数 + self.max_retries = 3 # 最大重试次数 async def check( self, reply: str, goal: str, chat_history: List[Dict[str, Any]], retry_count: int = 0 @@ -76,8 +76,10 @@ class ReplyChecker: False, ) - except Exception as self_check_err: - logger.error(f"检查自身重复发言时出错: {self_check_err}") + except Exception as e: + import traceback + logger.error(f"检查回复时出错: 类型={type(e)}, 值={e}") + logger.error(traceback.format_exc()) # 打印详细的回溯信息 for msg in chat_history[-20:]: time_str = datetime.datetime.fromtimestamp(msg["time"]).strftime("%H:%M:%S") From a2c94d3e8ef8f3b087360c43443fdc21ea72b69c Mon Sep 17 00:00:00 2001 From: infinitycat Date: Fri, 25 Apr 2025 13:27:35 +0800 Subject: [PATCH 10/12] =?UTF-8?q?perf:=20=E6=9B=B4=E6=96=B0clone=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 3bd4a21bc..605d838ce 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -25,7 +25,7 @@ jobs: run: git clone https://github.com/MaiM-with-u/maim_message maim_message - name: Clone lpmm - run: git clone https://github.com/infinitycat233/MaiMBot-LPMM.git MaiMBot-LPMM + run: git clone https://github.com/MaiM-with-u/MaiMBot-LPMM.git MaiMBot-LPMM - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 From b6b5150f6b1d0f006fe47e5d5898ae75eefaefff Mon Sep 17 00:00:00 2001 From: Cookie987 Date: Fri, 25 Apr 2025 17:30:58 +0800 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20LPMM=E7=9F=A5=E8=AF=86=E5=BA=93?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/run.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/run.sh b/scripts/run.sh index b7ecbc849..9fd3127f6 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -4,7 +4,7 @@ # 适用于Arch/Ubuntu 24.10/Debian 12/CentOS 9 # 请小心使用任何一键脚本! -INSTALLER_VERSION="0.0.3-refactor" +INSTALLER_VERSION="0.0.4-refactor" LANG=C.UTF-8 # 如无法访问GitHub请修改此处镜像地址 @@ -19,10 +19,10 @@ RESET="\e[0m" declare -A REQUIRED_PACKAGES=( ["common"]="git sudo python3 curl gnupg" - ["debian"]="python3-venv python3-pip" - ["ubuntu"]="python3-venv python3-pip" - ["centos"]="python3-pip" - ["arch"]="python-virtualenv python-pip" + ["debian"]="python3-venv python3-pip build-essential" + ["ubuntu"]="python3-venv python3-pip build-essential" + ["centos"]="epel-release python3-pip python3-devel gcc gcc-c++ make" + ["arch"]="python-virtualenv python-pip base-devel" ) # 默认项目目录 From a45b35e74ce899bb2905dd6ecb3fd0cfce8414ad Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 25 Apr 2025 09:40:54 +0000 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=A0=BC=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/plugins/PFC/conversation.py | 22 ++++++++++++---------- src/plugins/PFC/reply_checker.py | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/plugins/PFC/conversation.py b/src/plugins/PFC/conversation.py index 39ebccc1d..5687e4205 100644 --- a/src/plugins/PFC/conversation.py +++ b/src/plugins/PFC/conversation.py @@ -248,7 +248,7 @@ class Conversation: # --- 根据不同的 action 执行 --- if action == "direct_reply": - max_reply_attempts = 3 # 设置最大尝试次数(与 reply_checker.py 中的 max_retries 保持一致或稍大) + max_reply_attempts = 3 # 设置最大尝试次数(与 reply_checker.py 中的 max_retries 保持一致或稍大) reply_attempt_count = 0 is_suitable = False need_replan = False @@ -273,17 +273,19 @@ class Conversation: reply=self.generated_reply, goal=current_goal_str, chat_history=observation_info.chat_history, - retry_count=reply_attempt_count - 1, # 传递当前尝试次数(从0开始计数) + retry_count=reply_attempt_count - 1, # 传递当前尝试次数(从0开始计数) + ) + logger.info( + f"第 {reply_attempt_count} 次检查结果: 合适={is_suitable}, 原因='{check_reason}', 需重新规划={need_replan}" ) - logger.info(f"第 {reply_attempt_count} 次检查结果: 合适={is_suitable}, 原因='{check_reason}', 需重新规划={need_replan}") if is_suitable: - final_reply_to_send = self.generated_reply # 保存合适的回复 - break # 回复合适,跳出循环 + final_reply_to_send = self.generated_reply # 保存合适的回复 + break # 回复合适,跳出循环 elif need_replan: - logger.warning(f"第 {reply_attempt_count} 次检查建议重新规划,停止尝试。原因: {check_reason}") - break # 如果检查器建议重新规划,也停止尝试 + logger.warning(f"第 {reply_attempt_count} 次检查建议重新规划,停止尝试。原因: {check_reason}") + break # 如果检查器建议重新规划,也停止尝试 # 如果不合适但不需要重新规划,循环会继续进行下一次尝试 except Exception as check_err: @@ -310,7 +312,7 @@ class Conversation: return # 发送合适的回复 - self.generated_reply = final_reply_to_send # 确保 self.generated_reply 是最终要发送的内容 + self.generated_reply = final_reply_to_send # 确保 self.generated_reply 是最终要发送的内容 await self._send_reply() # 更新 action 历史状态为 done @@ -326,7 +328,7 @@ class Conversation: logger.warning(f"经过 {reply_attempt_count} 次尝试,未能生成合适的回复。最终原因: {check_reason}") conversation_info.done_action[action_index].update( { - "status": "recall", # 标记为 recall 因为没有成功发送 + "status": "recall", # 标记为 recall 因为没有成功发送 "final_reason": f"尝试{reply_attempt_count}次后失败: {check_reason}", "time": datetime.datetime.now().strftime("%H:%M:%S"), } @@ -341,7 +343,7 @@ class Conversation: wait_action_record = { "action": "wait", "plan_reason": "因 direct_reply 多次尝试失败而执行的后备等待", - "status": "done", # wait 完成后可以认为是 done + "status": "done", # wait 完成后可以认为是 done "time": datetime.datetime.now().strftime("%H:%M:%S"), "final_reason": None, } diff --git a/src/plugins/PFC/reply_checker.py b/src/plugins/PFC/reply_checker.py index 312387f31..949b49a34 100644 --- a/src/plugins/PFC/reply_checker.py +++ b/src/plugins/PFC/reply_checker.py @@ -78,8 +78,9 @@ class ReplyChecker: except Exception as e: import traceback + logger.error(f"检查回复时出错: 类型={type(e)}, 值={e}") - logger.error(traceback.format_exc()) # 打印详细的回溯信息 + logger.error(traceback.format_exc()) # 打印详细的回溯信息 for msg in chat_history[-20:]: time_str = datetime.datetime.fromtimestamp(msg["time"]).strftime("%H:%M:%S")