From ddc1fa2dbd37ee8a7a4f21967e2225019e6a378e Mon Sep 17 00:00:00 2001 From: yuance <182865460@qq.com> Date: Tue, 3 Feb 2026 15:31:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B7=A5=E4=BD=9C=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E6=96=87=E4=BB=B6=E7=9C=9F=E5=AE=9E=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AbstractAuditContentService.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gxwebsoft/ai/service/impl/AbstractAuditContentService.java b/src/main/java/com/gxwebsoft/ai/service/impl/AbstractAuditContentService.java index b70f13e..52e2e30 100644 --- a/src/main/java/com/gxwebsoft/ai/service/impl/AbstractAuditContentService.java +++ b/src/main/java/com/gxwebsoft/ai/service/impl/AbstractAuditContentService.java @@ -259,6 +259,13 @@ public abstract class AbstractAuditContentService { */ private List processNodesToResults(List nodes, Map fileUrlMap) { Set results = new LinkedHashSet<>(); + + // 构建可用文件列表 + StringBuilder fileListBuilder = new StringBuilder(); + fileListBuilder.append("\n\n**可用真实文件列表(仅限以下文件,不得虚构其他文件名):**\n"); + + Set processedFiles = new HashSet<>(); // 避免重复 + for (RetrieveResponseBodyDataNodes node : nodes) { try { // 检查文本有效性 @@ -271,27 +278,44 @@ public abstract class AbstractAuditContentService { String docName = extractDocumentName(node); String docId = extractDocumentId(node); String fileUrl = fileUrlMap.get(docId); - if(StrUtil.isBlank(fileUrl)) { - fileUrl = extractDocumentUrl(node); + if (StrUtil.isBlank(fileUrl)) { + fileUrl = extractDocumentUrl(node); } - if(StrUtil.isBlank(fileUrl)) { - fileUrl = "无链接"; + if (StrUtil.isBlank(fileUrl)) { + fileUrl = "无链接"; } - // 处理文件URL为空的情况 -// String url = StrUtil.isNotBlank(fileUrl) ? fileUrl : "无"; - // 格式化结果 -// String formattedText = String.format("《%s》【FileUrl:%s】%s", docName, url, text); + // 添加文件名到列表(去重) + if (StrUtil.isNotBlank(docName) && !processedFiles.contains(docName)) { + processedFiles.add(docName); + fileListBuilder.append("- 《").append(docName).append("》"); + if (!"无链接".equals(fileUrl)) { + fileListBuilder.append(" || ").append(fileUrl); + } + fileListBuilder.append("\n"); + } + + // 格式化为知识库内容 JSONObject json = new JSONObject(); json.put("document_name", docName); json.put("file_url", fileUrl); json.put("content", text); String formattedText = json.toJSONString(); results.add(formattedText); + } catch (Exception e) { log.warn("处理知识库节点失败", e); } } + + // 添加文件列表到结果 + fileListBuilder.append("\n**重要约束:**\n"); + fileListBuilder.append("1. 只能使用上述列表中的文件,不得虚构其他文件名\n"); + fileListBuilder.append("2. 如果某项检查未涉及上述文件,则 workPaperIndex 填写\"[]\"\n"); + fileListBuilder.append("3. 所有文件必须来自提供的知识库内容\n"); + + results.add(fileListBuilder.toString()); + return new ArrayList<>(results); }