|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.cloud.kicc.system.service.impl; |
|
|
|
package com.cloud.kicc.system.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
@ -77,12 +78,6 @@ public class ImContentServiceImpl extends ServiceImpl<ImContentMapper, ImContent |
|
|
|
if (StrUtil.isBlank(imContent.getContent())) { |
|
|
|
if (StrUtil.isBlank(imContent.getContent())) { |
|
|
|
throw new CheckedException("提问内容不能为空请检查!"); |
|
|
|
throw new CheckedException("提问内容不能为空请检查!"); |
|
|
|
} |
|
|
|
} |
|
|
|
// 保存用户发送聊天记录
|
|
|
|
|
|
|
|
imContent.setSendUserId(SecurityUtils.getCasUser().getId()); |
|
|
|
|
|
|
|
imContent.setSendTime(LocalDateTime.now()); |
|
|
|
|
|
|
|
imContent.setReceiveUserId(imContent.getReceiveUserId()); |
|
|
|
|
|
|
|
imContent.setReceiveTime(LocalDateTime.now()); |
|
|
|
|
|
|
|
super.save(imContent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询当前历史消息,进行AI上下文消息合并
|
|
|
|
// 查询当前历史消息,进行AI上下文消息合并
|
|
|
|
List<ImContent> imContents = super.list(Wrappers.<ImContent>lambdaQuery().and(i -> |
|
|
|
List<ImContent> imContents = super.list(Wrappers.<ImContent>lambdaQuery().and(i -> |
|
|
@ -101,6 +96,14 @@ public class ImContentServiceImpl extends ServiceImpl<ImContentMapper, ImContent |
|
|
|
chatMessage.setContent(item.getContent()); |
|
|
|
chatMessage.setContent(item.getContent()); |
|
|
|
return chatMessage; |
|
|
|
return chatMessage; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
CollUtil.reverse(historyMessages); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存用户发送聊天记录
|
|
|
|
|
|
|
|
imContent.setSendUserId(SecurityUtils.getCasUser().getId()); |
|
|
|
|
|
|
|
imContent.setSendTime(LocalDateTime.now()); |
|
|
|
|
|
|
|
imContent.setReceiveUserId(imContent.getReceiveUserId()); |
|
|
|
|
|
|
|
imContent.setReceiveTime(LocalDateTime.now()); |
|
|
|
|
|
|
|
super.save(imContent); |
|
|
|
|
|
|
|
|
|
|
|
// Completion消息
|
|
|
|
// Completion消息
|
|
|
|
ChatMessage completionMessage = new ChatMessage(ChatMessageRole.USER.value(), imContent.getContent()); |
|
|
|
ChatMessage completionMessage = new ChatMessage(ChatMessageRole.USER.value(), imContent.getContent()); |
|
|
|