增加LLM返回空内容拦截并提示总结失败
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user