refactor(module-llm):优化知识库字符串处理逻辑

- 移除了不必要的空字符串赋值操作
- 添加了对 knowledgeBase
This commit is contained in:
Liuyang 2025-03-11 17:55:19 +08:00
parent 254ea1c477
commit 42cf973145

View File

@ -434,19 +434,19 @@ public class ConversationServiceImpl implements ConversationService {
String knowledgeBaseString="";
if (chatReqVO.getKnowledge() != null) {
StringBuilder knowledgeBase = getKnowledgeBase(chatReqVO);
knowledgeBaseString = knowledgeBase.toString();
knowledgeBaseString = knowledgeBase.toString();
if (org.apache.commons.lang3.StringUtils.isBlank(knowledgeBaseString)){
knowledgeBaseString="";
}
// 处理 knowledgeBaseString
if (StringUtils.isNotBlank(knowledgeBaseString)) {
knowledgeBaseString = "<context>" + knowledgeBaseString + "</context>";
}
// 处理 systemPrompt
systemPrompt = StringUtils.isBlank(chatReqVO.getSystemPrompt())
systemPrompt = StringUtils.isBlank(chatReqVO.getSystemPrompt())
? PROMPT
: chatReqVO.getSystemPrompt() + "\n" + PROMPT;
}
String mess = systemPrompt + "<content>"+knowledgeBaseString+"</content>";
String mess = systemPrompt + knowledgeBaseString;
// 查询历史记录消息并将查询出来的知识信息放入到 role = system 的消息中
List<String> messageHistoryList = stringRedisTemplate.opsForList().range(CHAT_HIStORY_REDIS_KEY + ":" + chatReqVO.getUuid(), 0, -1);