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 a744d8c2d..4c4dfdc03 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 @@ -365,32 +365,7 @@ public class ConversationServiceImpl implements ConversationService { && Objects.equals(expectedGroupId, actualGroupId); } - public static final String PROMPT="【系统角色】\n" + - "您是基于限定知识库的问答助手,需严格遵循以下交互规则:\n" + - "\n" + - "角色定义:您被设定为「知识库解析引擎」,仅处理与用户提供的知识库内容直接相关的问题\n" + - "【输入规范】\n" + - "2. 知识库验证:当用户提问时,必须包含用```分隔符包裹的完整知识库内容,格式示例:\n" + - "\n" + - "问题:<用户问题>\n" + - "知识库:\n" + - "<知识库内容>\n" + - "【响应规则】\n" + - "3. 内容匹配:仅当知识库中存在与问题直接相关的明确信息时,方可生成回答。需满足:\n" + - "\n" + - "引用完整性:答案必须包含知识库中的具体数据/案例\n" + - "精确映射:每个回答要点需标注对应知识库段落的引用编号\n" + - "限制处理:若出现以下情况,请回复预设语句:\n" + - "知识库未提供 → \"抱歉,我无法回答这个问题,因为相关信息不在知识库中。\"\n" + - "问题超出知识库范围 → \"该问题超出当前知识库支持范围\"\n" + - "检测到推测请求 → \"根据规则,我无法进行推测或想象\"\n" + - "【安全机制】\n" + - "4. 内容过滤:自动触发以下保护机制:\n" + - "\n" + - "屏蔽知识库外的任何数据引用\n" + - "禁止添加解释性语句或背景补充\n" + - "拦截包含\"假设\"/\"如果\"等假设性词汇的问题" + - "5. 如果存在 [知识库内容] 这个标签,但是 [内容为空] ,返回 “抱歉,我无法回答这个问题,因为相关信息不在知识库中”"; + public static final String PROMPT="Use the following context as your learned knowledge, inside XML tags.\\n\\n\\n{{#context#}}\\n\\n\\nWhen answer to user:\\n- If you don't know, just say that you don't know.\\n- If you don't know when you are not sure, ask for clarification.\\nAvoid mentioning that you obtained the information from the context.\\nAnd answer according to the language of the user's question.\\n\\n"; /** * 公共模型聊天流式处理方法 * @@ -462,7 +437,7 @@ public class ConversationServiceImpl implements ConversationService { knowledgeBaseString = knowledgeBase.toString(); if (org.apache.commons.lang3.StringUtils.isBlank(knowledgeBaseString)){ - knowledgeBaseString="[知识库内容] , [内容为空]"; + knowledgeBaseString=""; } // 处理 systemPrompt @@ -471,7 +446,7 @@ public class ConversationServiceImpl implements ConversationService { : chatReqVO.getSystemPrompt() + "\n" + PROMPT; } - String mess = systemPrompt + knowledgeBaseString; + String mess = systemPrompt + ""+knowledgeBaseString+""; // 查询历史记录消息,并将查询出来的知识信息放入到 role = system 的消息中 List messageHistoryList = stringRedisTemplate.opsForList().range(CHAT_HIStORY_REDIS_KEY + ":" + chatReqVO.getUuid(), 0, -1); @@ -561,6 +536,7 @@ public class ConversationServiceImpl implements ConversationService { if (rateWordVO!=null){ words.add(rateWordVO); } + } if (CollectionUtils.isEmpty(words)){ paragraphHitRateListVO.setWordList(Collections.emptyList());