From b1f435c8ffad75a4c20349e1ad81005d7fa20a92 Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 23 Apr 2026 11:54:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0LLM=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=A9=BA=E5=86=85=E5=AE=B9=E6=8B=A6=E6=88=AA=E5=B9=B6=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E6=80=BB=E7=BB=93=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/message_summary/main.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/message_summary/main.py b/plugins/message_summary/main.py index 913ebf4..e45d7e1 100644 --- a/plugins/message_summary/main.py +++ b/plugins/message_summary/main.py @@ -333,8 +333,10 @@ class MessageSummaryPlugin(MessagePluginInterface): return True else: # 连文本内容都没有 - client_msg_id, create_time, new_msg_id = await self.bot.send_text_message(group_id, - "❌ 生成总结失败,请稍后再试!") + client_msg_id, create_time, new_msg_id = await self.bot.send_text_message( + group_id, + "❌ LLM总结失败:返回空内容,请稍后重试。", + ) self.revoke.add_message_to_revoke(group_id, client_msg_id, create_time, new_msg_id, 5) return False @@ -1671,6 +1673,12 @@ class MessageSummaryPlugin(MessagePluginInterface): raise RuntimeError(self.llm_client.last_error or "LLM 未返回有效总结内容") answer = self._clean_summary_output(response.get("text", "")) + # 空内容保护: + # 1. 模型可能返回空白、仅分隔符或被清洗后为空; + # 2. 此时不继续走模板/Markdown 渲染,直接视为 LLM 失败并进入重试; + # 3. 重试耗尽后交由上层统一提示“LLM总结失败”,避免发送空消息骚扰群聊。 + if not answer or not answer.strip(): + raise RuntimeError("LLM总结失败:返回空内容") metadata = {"usage": response.get("usage", {}) or {}} spath = "" # 说明: @@ -1716,7 +1724,8 @@ class MessageSummaryPlugin(MessagePluginInterface): self.LOG.warning(f"群总结生成失败,准备重试: attempt={attempt}/{max_retries}, delay={delay}s") await asyncio.sleep(delay) - return "生成总结时出错", None + # 重试耗尽后返回空字符串,外层会识别为空并给出明确失败提示,不再发送无意义文本内容。 + return "", None @staticmethod def _prepend_stats_section(summary: str, message_stats: Dict[str, int]) -> str: