From c235b2eed47af54053cf8b081164c00be28cafb3 Mon Sep 17 00:00:00 2001 From: Liuyang <2746366019@qq.com> Date: Tue, 11 Mar 2025 17:06:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(llm):=20=E4=BC=98=E5=8C=96=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E5=BA=93=E4=B8=BA=E7=A9=BA=E6=97=B6=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在知识库内容为空时,添加特定的处理逻辑 - 返回明确的提示信息,提高用户体验 -保持代码风格和命名规范 --- .../llm/service/conversation/ConversationServiceImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/conversation/ConversationServiceImpl.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/conversation/ConversationServiceImpl.java index d252472e2..9a08b7c0b 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/conversation/ConversationServiceImpl.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/conversation/ConversationServiceImpl.java @@ -396,7 +396,8 @@ public class ConversationServiceImpl implements ConversationService { "\n" + "屏蔽知识库外的任何数据引用\n" + "禁止添加解释性语句或背景补充\n" + - "拦截包含\"假设\"/\"如果\"等假设性词汇的问题"; + "拦截包含\"假设\"/\"如果\"等假设性词汇的问题" + + "7. 如果存在 <知识库内容> 这个标签,但是内容为空,返回 “抱歉,我无法回答这个问题,因为相关信息不在知识库中”,"; /** * 公共模型聊天流式处理方法 * @@ -466,6 +467,11 @@ public class ConversationServiceImpl implements ConversationService { if (chatReqVO.getKnowledge() != null) { StringBuilder knowledgeBase = getKnowledgeBase(chatReqVO); knowledgeBaseString = knowledgeBase.toString(); + + if (org.apache.commons.lang3.StringUtils.isBlank(knowledgeBaseString)){ + knowledgeBaseString="<知识库内容> ,内容为空"; + } + // 处理 systemPrompt systemPrompt = StringUtils.isBlank(chatReqVO.getSystemPrompt()) ? PROMPT