diff --git a/yuthon_ai_agent/models/ai_agent.py b/yuthon_ai_agent/models/ai_agent.py index ff92c358f..1ea1974ef 100644 --- a/yuthon_ai_agent/models/ai_agent.py +++ b/yuthon_ai_agent/models/ai_agent.py @@ -598,28 +598,35 @@ class AiConversation(models.Model): # 主入口 # --------------------------------------------------------- def _check_hallucinated_url(self, content): - """检测 LLM 响应中是否编造了报表链接。 + """检测并移除 LLM 响应中编造的报表链接。 真正的报表链接由 generate_report 工具返回,格式为 https://域名/yuthon/report/<12位hex>。 LLM 有时会跳过工具调用,直接在文本中编造一个链接, - 典型模式:/ai/report/、/report/ 等。 + 典型模式:/ai/report/<任意>、/report/ 等。 + 检测到后移除伪造链接并用提示文本替换,避免用户点击无效链接。 """ if not content: - return + return content import re - # 匹配 URL 中包含 /report/ 但不是 /yuthon/report/ 的模式 + # 匹配伪造的报表链接模式 hallucinated = re.findall( - r'(https?://[^\s]*?/(?:ai[-_]?)?report/[^\s]+|' - r'(?