Commit 747b2ebce529ec0374d7ca05afda455fd3565fb7
1 parent
12d3c0a9
【增加】AI Chat 增加清空消息
Showing
4 changed files
with
34 additions
and
13 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java
| @@ -55,4 +55,10 @@ public class AiChatMessageController { | @@ -55,4 +55,10 @@ public class AiChatMessageController { | ||
| 55 | return success(chatService.deleteMessage(id)); | 55 | return success(chatService.deleteMessage(id)); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | + @Operation(summary = "删除消息-对于对话全部消息") | ||
| 59 | + @DeleteMapping("/delete-by-conversation-id") | ||
| 60 | + @Parameter(name = "id", required = true, description = "消息编号", example = "1024") | ||
| 61 | + public CommonResult<Boolean> deleteByConversationId(@RequestParam("conversationId") Long conversationId) { | ||
| 62 | + return success(chatService.deleteByConversationId(conversationId)); | ||
| 63 | + } | ||
| 58 | } | 64 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatMessageMapper.java
| @@ -32,4 +32,12 @@ public interface AiChatMessageMapper extends BaseMapperX<AiChatMessageDO> { | @@ -32,4 +32,12 @@ public interface AiChatMessageMapper extends BaseMapperX<AiChatMessageDO> { | ||
| 32 | ); | 32 | ); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | + /** | ||
| 36 | + * 删除 - 根据 conversationId | ||
| 37 | + * | ||
| 38 | + * @param conversationId | ||
| 39 | + */ | ||
| 40 | + default int deleteByConversationId(Long conversationId) { | ||
| 41 | + return this.delete(new LambdaQueryWrapperX<AiChatMessageDO>().eq(AiChatMessageDO::getConversationId, conversationId)); | ||
| 42 | + } | ||
| 35 | } | 43 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java
| @@ -47,4 +47,11 @@ public interface AiChatService { | @@ -47,4 +47,11 @@ public interface AiChatService { | ||
| 47 | */ | 47 | */ |
| 48 | Flux<AiChatMessageSendRespVO> sendChatMessageStream(AiChatMessageSendReqVO sendReqVO, Long userId); | 48 | Flux<AiChatMessageSendRespVO> sendChatMessageStream(AiChatMessageSendReqVO sendReqVO, Long userId); |
| 49 | 49 | ||
| 50 | + /** | ||
| 51 | + * 删除消息-对于对话全部消息 | ||
| 52 | + * | ||
| 53 | + * @param conversationId | ||
| 54 | + * @return | ||
| 55 | + */ | ||
| 56 | + Boolean deleteByConversationId(Long conversationId); | ||
| 50 | } | 57 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java
| 1 | package cn.iocoder.yudao.module.ai.service.impl; | 1 | package cn.iocoder.yudao.module.ai.service.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.collection.ListUtil; | ||
| 5 | -import cn.hutool.core.util.ArrayUtil; | ||
| 6 | -import cn.hutool.core.util.BooleanUtil; | ||
| 7 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 8 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 9 | import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; | 6 | import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; |
| 10 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 11 | -import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendRespVO; | ||
| 12 | -import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatConversationDO; | ||
| 13 | -import org.springframework.ai.chat.ChatResponse; | ||
| 14 | -import org.springframework.ai.chat.StreamingChatClient; | ||
| 15 | -import org.springframework.ai.chat.messages.*; | ||
| 16 | -import org.springframework.ai.chat.prompt.ChatOptions; | ||
| 17 | -import org.springframework.ai.chat.prompt.ChatOptionsBuilder; | ||
| 18 | -import org.springframework.ai.chat.prompt.Prompt; | ||
| 19 | import cn.iocoder.yudao.module.ai.config.AiChatClientFactory; | 8 | import cn.iocoder.yudao.module.ai.config.AiChatClientFactory; |
| 20 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; | 9 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; |
| 21 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; | 10 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; |
| 11 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendRespVO; | ||
| 22 | import cn.iocoder.yudao.module.ai.convert.AiChatMessageConvert; | 12 | import cn.iocoder.yudao.module.ai.convert.AiChatMessageConvert; |
| 13 | +import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatConversationDO; | ||
| 23 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; | 14 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; |
| 24 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; | 15 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 25 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatMessageMapper; | 16 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatMessageMapper; |
| 26 | -import cn.iocoder.yudao.module.ai.service.chat.AiChatConversationService; | ||
| 27 | -import cn.iocoder.yudao.module.ai.service.model.AiChatRoleService; | ||
| 28 | import cn.iocoder.yudao.module.ai.service.AiChatService; | 17 | import cn.iocoder.yudao.module.ai.service.AiChatService; |
| 18 | +import cn.iocoder.yudao.module.ai.service.chat.AiChatConversationService; | ||
| 29 | import cn.iocoder.yudao.module.ai.service.model.AiChatModelService; | 19 | import cn.iocoder.yudao.module.ai.service.model.AiChatModelService; |
| 20 | +import cn.iocoder.yudao.module.ai.service.model.AiChatRoleService; | ||
| 30 | import lombok.AllArgsConstructor; | 21 | import lombok.AllArgsConstructor; |
| 31 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
| 23 | +import org.springframework.ai.chat.ChatResponse; | ||
| 24 | +import org.springframework.ai.chat.StreamingChatClient; | ||
| 25 | +import org.springframework.ai.chat.messages.*; | ||
| 26 | +import org.springframework.ai.chat.prompt.Prompt; | ||
| 32 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
| 33 | import org.springframework.transaction.annotation.Transactional; | 28 | import org.springframework.transaction.annotation.Transactional; |
| 34 | import reactor.core.publisher.Flux; | 29 | import reactor.core.publisher.Flux; |
| @@ -143,6 +138,11 @@ public class AiChatServiceImpl implements AiChatService { | @@ -143,6 +138,11 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 143 | }); | 138 | }); |
| 144 | } | 139 | } |
| 145 | 140 | ||
| 141 | + @Override | ||
| 142 | + public Boolean deleteByConversationId(Long conversationId) { | ||
| 143 | + return chatMessageMapper.deleteByConversationId(conversationId) > 0; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | private Prompt buildPrompt(AiChatConversationDO conversation, List<AiChatMessageDO> messages, AiChatMessageSendReqVO sendReqVO) { | 146 | private Prompt buildPrompt(AiChatConversationDO conversation, List<AiChatMessageDO> messages, AiChatMessageSendReqVO sendReqVO) { |
| 147 | // 1. 构建 Prompt Message 列表 | 147 | // 1. 构建 Prompt Message 列表 |
| 148 | List<Message> chatMessages = new ArrayList<>(); | 148 | List<Message> chatMessages = new ArrayList<>(); |