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 | 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 | 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 | 47 | */ |
| 48 | 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 | 1 | package cn.iocoder.yudao.module.ai.service.impl; |
| 2 | 2 | |
| 3 | 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 | 4 | import cn.hutool.core.util.ObjUtil; |
| 8 | 5 | import cn.hutool.core.util.StrUtil; |
| 9 | 6 | import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; |
| 10 | 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 | 8 | import cn.iocoder.yudao.module.ai.config.AiChatClientFactory; |
| 20 | 9 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; |
| 21 | 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 | 12 | import cn.iocoder.yudao.module.ai.convert.AiChatMessageConvert; |
| 13 | +import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatConversationDO; | |
| 23 | 14 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; |
| 24 | 15 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 25 | 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 | 17 | import cn.iocoder.yudao.module.ai.service.AiChatService; |
| 18 | +import cn.iocoder.yudao.module.ai.service.chat.AiChatConversationService; | |
| 29 | 19 | import cn.iocoder.yudao.module.ai.service.model.AiChatModelService; |
| 20 | +import cn.iocoder.yudao.module.ai.service.model.AiChatRoleService; | |
| 30 | 21 | import lombok.AllArgsConstructor; |
| 31 | 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 | 27 | import org.springframework.stereotype.Service; |
| 33 | 28 | import org.springframework.transaction.annotation.Transactional; |
| 34 | 29 | import reactor.core.publisher.Flux; |
| ... | ... | @@ -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 | 146 | private Prompt buildPrompt(AiChatConversationDO conversation, List<AiChatMessageDO> messages, AiChatMessageSendReqVO sendReqVO) { |
| 147 | 147 | // 1. 构建 Prompt Message 列表 |
| 148 | 148 | List<Message> chatMessages = new ArrayList<>(); | ... | ... |