Commit 8de98a15bb9314ada5ea1e47fbd2ddcce7a06baf
1 parent
42421006
【调整】调整AI聊天,message列表、删除message
Showing
8 changed files
with
74 additions
and
13 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatConversationController.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.ai.controller.admin.chat; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.ai.controller.admin.chat; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationCreateReqVO; | 4 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationCreateReqVO; |
| 5 | -import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationListReqVO; | ||
| 6 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; | 5 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; |
| 7 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationUpdateReqVO; | 6 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationUpdateReqVO; |
| 8 | import cn.iocoder.yudao.module.ai.service.AiChatConversationService; | 7 | import cn.iocoder.yudao.module.ai.service.AiChatConversationService; |
| @@ -47,8 +46,8 @@ public class AiChatConversationController { | @@ -47,8 +46,8 @@ public class AiChatConversationController { | ||
| 47 | // TODO done @fan:实现一下 | 46 | // TODO done @fan:实现一下 |
| 48 | @GetMapping("/list") | 47 | @GetMapping("/list") |
| 49 | @Operation(summary = "获得聊天会话列表") | 48 | @Operation(summary = "获得聊天会话列表") |
| 50 | - public CommonResult<List<AiChatConversationRespVO>> getConversationList(@ModelAttribute AiChatConversationListReqVO listReqVO) { | ||
| 51 | - return success(aiChatConversationService.listConversation(listReqVO)); | 49 | + public CommonResult<List<AiChatConversationRespVO>> getConversationList() { |
| 50 | + return success(aiChatConversationService.listConversation()); | ||
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | // TODO @fan:实现一下 | 53 | // TODO @fan:实现一下 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java
| @@ -31,7 +31,7 @@ public class AiChatMessageController { | @@ -31,7 +31,7 @@ public class AiChatMessageController { | ||
| 31 | @Operation(summary = "发送消息(段式)", description = "一次性返回,响应较慢") | 31 | @Operation(summary = "发送消息(段式)", description = "一次性返回,响应较慢") |
| 32 | @PostMapping("/send") | 32 | @PostMapping("/send") |
| 33 | public CommonResult<AiChatMessageRespVO> sendMessage(@Validated @ModelAttribute AiChatMessageSendReqVO sendReqVO) { | 33 | public CommonResult<AiChatMessageRespVO> sendMessage(@Validated @ModelAttribute AiChatMessageSendReqVO sendReqVO) { |
| 34 | - // TODO @fan:使用 static import;这样就 success 就行了; | 34 | + // TODO done @fan:使用 static import;这样就 success 就行了; |
| 35 | return success(chatService.chat(sendReqVO)); | 35 | return success(chatService.chat(sendReqVO)); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| @@ -49,14 +49,14 @@ public class AiChatMessageController { | @@ -49,14 +49,14 @@ public class AiChatMessageController { | ||
| 49 | @GetMapping("/list-by-conversation-id") | 49 | @GetMapping("/list-by-conversation-id") |
| 50 | @Parameter(name = "conversationId", required = true, description = "会话编号", example = "1024") | 50 | @Parameter(name = "conversationId", required = true, description = "会话编号", example = "1024") |
| 51 | public CommonResult<List<AiChatMessageRespVO>> getMessageListByConversationId(@RequestParam("conversationId") Long conversationId) { | 51 | public CommonResult<List<AiChatMessageRespVO>> getMessageListByConversationId(@RequestParam("conversationId") Long conversationId) { |
| 52 | - return success(null); | 52 | + return success(chatService.getMessageListByConversationId(conversationId)); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | @Operation(summary = "删除消息") | 55 | @Operation(summary = "删除消息") |
| 56 | @DeleteMapping("/delete") | 56 | @DeleteMapping("/delete") |
| 57 | @Parameter(name = "id", required = true, description = "消息编号", example = "1024") | 57 | @Parameter(name = "id", required = true, description = "消息编号", example = "1024") |
| 58 | - public CommonResult<Boolean> delete(@RequestParam("id") Long id) { | ||
| 59 | - return success(null); | 58 | + public CommonResult<Boolean> deleteMessage(@RequestParam("id") Long id) { |
| 59 | + return success(chatService.deleteMessage(id)); | ||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | } | 62 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java
| @@ -20,10 +20,18 @@ public interface AiChatMessageConvert { | @@ -20,10 +20,18 @@ public interface AiChatMessageConvert { | ||
| 20 | AiChatMessageConvert INSTANCE = Mappers.getMapper(AiChatMessageConvert.class); | 20 | AiChatMessageConvert INSTANCE = Mappers.getMapper(AiChatMessageConvert.class); |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | - * 转换 ChatMessageListRes | 23 | + * 转换 ChatMessageListRes |
| 24 | * | 24 | * |
| 25 | * @param list | 25 | * @param list |
| 26 | * @return | 26 | * @return |
| 27 | */ | 27 | */ |
| 28 | List<AiChatMessageRespVO> convert(List<AiChatMessageDO> list); | 28 | List<AiChatMessageRespVO> convert(List<AiChatMessageDO> list); |
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 转换 AiChatMessageRespVO | ||
| 32 | + * | ||
| 33 | + * @param aiChatMessageDOList | ||
| 34 | + * @return | ||
| 35 | + */ | ||
| 36 | + List<AiChatMessageRespVO> convertAiChatMessageRespVOList(List<AiChatMessageDO> aiChatMessageDOList); | ||
| 29 | } | 37 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatMessageMapper.java
| @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; | @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; | ||
| 6 | import org.apache.ibatis.annotations.Mapper; | 6 | import org.apache.ibatis.annotations.Mapper; |
| 7 | import org.springframework.stereotype.Repository; | 7 | import org.springframework.stereotype.Repository; |
| 8 | 8 | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 9 | /** | 11 | /** |
| 10 | * message mapper | 12 | * message mapper |
| 11 | * | 13 | * |
| @@ -29,4 +31,12 @@ public interface AiChatMessageMapper extends BaseMapperX<AiChatMessageDO> { | @@ -29,4 +31,12 @@ public interface AiChatMessageMapper extends BaseMapperX<AiChatMessageDO> { | ||
| 29 | ); | 31 | ); |
| 30 | } | 32 | } |
| 31 | 33 | ||
| 34 | + /** | ||
| 35 | + * 查询 - 根据 对话id查询 | ||
| 36 | + * | ||
| 37 | + * @param conversationId | ||
| 38 | + */ | ||
| 39 | + default List<AiChatMessageDO> selectByConversationId(Long conversationId) { | ||
| 40 | + return selectList() | ||
| 41 | + } | ||
| 32 | } | 42 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatConversationService.java
| @@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatCo | @@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatCo | ||
| 4 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationListReqVO; | 4 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationListReqVO; |
| 5 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; | 5 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; |
| 6 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationUpdateReqVO; | 6 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationUpdateReqVO; |
| 7 | +import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatConversationDO; | ||
| 8 | +import org.jetbrains.annotations.NotNull; | ||
| 7 | 9 | ||
| 8 | import java.util.List; | 10 | import java.util.List; |
| 9 | 11 | ||
| @@ -34,10 +36,9 @@ public interface AiChatConversationService { | @@ -34,10 +36,9 @@ public interface AiChatConversationService { | ||
| 34 | /** | 36 | /** |
| 35 | * 获取 - 对话列表 | 37 | * 获取 - 对话列表 |
| 36 | * | 38 | * |
| 37 | - * @param req | ||
| 38 | * @return | 39 | * @return |
| 39 | */ | 40 | */ |
| 40 | - List<AiChatConversationRespVO> listConversation(AiChatConversationListReqVO req); | 41 | + List<AiChatConversationRespVO> listConversation(); |
| 41 | 42 | ||
| 42 | /** | 43 | /** |
| 43 | * 获取 - 对话 | 44 | * 获取 - 对话 |
| @@ -54,4 +55,11 @@ public interface AiChatConversationService { | @@ -54,4 +55,11 @@ public interface AiChatConversationService { | ||
| 54 | */ | 55 | */ |
| 55 | Boolean deleteConversation(Long id); | 56 | Boolean deleteConversation(Long id); |
| 56 | 57 | ||
| 58 | + /** | ||
| 59 | + * 校验 - 是否存在 | ||
| 60 | + * | ||
| 61 | + * @param id | ||
| 62 | + * @return | ||
| 63 | + */ | ||
| 64 | + AiChatConversationDO validateExists(Long id); | ||
| 57 | } | 65 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java
| @@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.ai.controller.Utf8SseEmitter; | @@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.ai.controller.Utf8SseEmitter; | ||
| 4 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; | 4 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; |
| 5 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; | 5 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; |
| 6 | 6 | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 7 | /** | 9 | /** |
| 8 | * 聊天 chat | 10 | * 聊天 chat |
| 9 | * | 11 | * |
| @@ -29,4 +31,21 @@ public interface AiChatService { | @@ -29,4 +31,21 @@ public interface AiChatService { | ||
| 29 | * @return | 31 | * @return |
| 30 | */ | 32 | */ |
| 31 | void chatStream(AiChatMessageSendReqVO req, Utf8SseEmitter sseEmitter); | 33 | void chatStream(AiChatMessageSendReqVO req, Utf8SseEmitter sseEmitter); |
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 获取 - 获取对话 message list | ||
| 37 | + * | ||
| 38 | + * @param conversationId | ||
| 39 | + * @return | ||
| 40 | + */ | ||
| 41 | + List<AiChatMessageRespVO> getMessageListByConversationId(Long conversationId); | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 删除 - 删除message | ||
| 45 | + * | ||
| 46 | + * @param id | ||
| 47 | + * @return | ||
| 48 | + */ | ||
| 49 | + Boolean deleteMessage(Long id); | ||
| 50 | + | ||
| 32 | } | 51 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatConversationServiceImpl.java
| @@ -98,12 +98,12 @@ public class AiChatConversationServiceImpl implements AiChatConversationService | @@ -98,12 +98,12 @@ public class AiChatConversationServiceImpl implements AiChatConversationService | ||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | @Override | 100 | @Override |
| 101 | - public List<AiChatConversationRespVO> listConversation(AiChatConversationListReqVO listReqVO) { | 101 | + public List<AiChatConversationRespVO> listConversation() { |
| 102 | // 获取用户id | 102 | // 获取用户id |
| 103 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); | 103 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| 104 | // 查询前100对话 | 104 | // 查询前100对话 |
| 105 | List<AiChatConversationDO> top100Conversation | 105 | List<AiChatConversationDO> top100Conversation |
| 106 | - = aiChatConversationMapper.selectTop100Conversation(loginUserId, listReqVO.getTitle()); | 106 | + = aiChatConversationMapper.selectTop100Conversation(loginUserId, null); |
| 107 | return AiChatConversationConvert.INSTANCE.covnertChatConversationResList(top100Conversation); | 107 | return AiChatConversationConvert.INSTANCE.covnertChatConversationResList(top100Conversation); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| @@ -118,7 +118,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService | @@ -118,7 +118,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService | ||
| 118 | return aiChatConversationMapper.deleteById(id) > 0; | 118 | return aiChatConversationMapper.deleteById(id) > 0; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | - private @NotNull AiChatConversationDO validateExists(Long id) { | 121 | + public @NotNull AiChatConversationDO validateExists(Long id) { |
| 122 | AiChatConversationDO aiChatConversationDO = aiChatConversationMapper.selectById(id); | 122 | AiChatConversationDO aiChatConversationDO = aiChatConversationMapper.selectById(id); |
| 123 | if (aiChatConversationDO == null) { | 123 | if (aiChatConversationDO == null) { |
| 124 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_CONVERSATION_NOT_EXISTS); | 124 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_CONVERSATION_NOT_EXISTS); |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java
| @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatCo | @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatCo | ||
| 14 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; | 14 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; |
| 15 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; | 15 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; |
| 16 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; | 16 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; |
| 17 | +import cn.iocoder.yudao.module.ai.convert.AiChatMessageConvert; | ||
| 17 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; | 18 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; |
| 18 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; | 19 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; |
| 19 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatConversationMapper; | 20 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatConversationMapper; |
| @@ -31,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional; | @@ -31,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional; | ||
| 31 | import reactor.core.publisher.Flux; | 32 | import reactor.core.publisher.Flux; |
| 32 | 33 | ||
| 33 | import java.io.IOException; | 34 | import java.io.IOException; |
| 35 | +import java.util.List; | ||
| 34 | import java.util.function.Consumer; | 36 | import java.util.function.Consumer; |
| 35 | 37 | ||
| 36 | /** | 38 | /** |
| @@ -187,4 +189,19 @@ public class AiChatServiceImpl implements AiChatService { | @@ -187,4 +189,19 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 187 | } | 189 | } |
| 188 | ); | 190 | ); |
| 189 | } | 191 | } |
| 192 | + | ||
| 193 | + @Override | ||
| 194 | + public List<AiChatMessageRespVO> getMessageListByConversationId(Long conversationId) { | ||
| 195 | + // 校验对话是否存在 | ||
| 196 | + chatConversationService.validateExists(conversationId); | ||
| 197 | + // 获取对话所有 message | ||
| 198 | + List<AiChatMessageDO> aiChatMessageDOList = aiChatMessageMapper.selectByConversationId(conversationId); | ||
| 199 | + // 转换 AiChatMessageRespVO | ||
| 200 | + return AiChatMessageConvert.INSTANCE.convertAiChatMessageRespVOList(aiChatMessageDOList); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + @Override | ||
| 204 | + public Boolean deleteMessage(Long id) { | ||
| 205 | + return aiChatMessageMapper.deleteById(id) > 0; | ||
| 206 | + } | ||
| 190 | } | 207 | } |