From 79bd78998d25dda9ab7f308c7ca8e9ee67912eed Mon Sep 17 00:00:00 2001 From: cherishsince Date: Sun, 12 May 2024 14:20:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=A8=A1=E5=9E=8B=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/vo/message/AiChatMessageRespVO.java | 10 ++++++++++ .../module/ai/dal/mysql/AiChatModelMapper.java | 12 +++++++++++- .../module/ai/service/AiChatModelService.java | 12 ++++++++++++ .../service/impl/AiChatModalServiceImpl.java | 7 +++++++ .../ai/service/impl/AiChatServiceImpl.java | 18 +++++++++++++++++- 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java index d5f830d171..f117c67c6b 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import java.time.LocalDateTime; + @Schema(description = "管理后台 - AI 聊天消息 Response VO") @Data public class AiChatMessageRespVO { @@ -19,6 +21,9 @@ public class AiChatMessageRespVO { @Schema(description = "用户编号", example = "4096") private Long userId; // 仅当 user 发送时非空 + @Schema(description = "用户头像", example = "http://xxx") + private Long avatarUrl; // 仅当 user 发送时非空 + @Schema(description = "角色编号", example = "888") private Long roleId; // 仅当 assistant 回复时非空 @@ -28,10 +33,15 @@ public class AiChatMessageRespVO { @Schema(description = "模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") private Long modelId; + @Schema(description = "模型图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") + private String modelImage; + @Schema(description = "聊天内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "你好,你好啊") private String content; @Schema(description = "消耗 Token 数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80") private Integer tokens; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-05-12 12:51") + private LocalDateTime createTime; } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java index 46d66ff5f5..418b25975e 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java @@ -9,6 +9,10 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Repository; +import java.util.Collection; +import java.util.List; +import java.util.Set; + /** * chat modal * @@ -36,5 +40,11 @@ public interface AiChatModelMapper extends BaseMapperX { return pageResult.getList().get(0); } - + /** + * 查询 - 根据 ids + * + * @param modalIds + * @return + */ + List selectByIds(Collection modalIds); } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatModelService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatModelService.java index 07a902dd8d..d133c729e9 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatModelService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatModelService.java @@ -4,6 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.*; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; +import java.util.List; +import java.util.Set; + /** * ai modal * @@ -64,4 +67,13 @@ public interface AiChatModelService { * @param chatModal */ void validateAvailable(AiChatModalRespVO chatModal); + + /** + * 获取 - 根据 ids 批量获取 + * + * @param modalIds + * @return + */ + List getModalByIds(Set modalIds); + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatModalServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatModalServiceImpl.java index 0aec7a94c8..e25110e1f3 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatModalServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatModalServiceImpl.java @@ -17,6 +17,7 @@ import cn.iocoder.yudao.module.ai.service.AiChatModelService; import jakarta.validation.ConstraintViolation; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.mybatis.spring.annotation.MapperScannerRegistrar; import org.springframework.stereotype.Service; import java.util.List; @@ -35,6 +36,7 @@ import java.util.Set; public class AiChatModalServiceImpl implements AiChatModelService { private final AiChatModelMapper aiChatModelMapper; + private final MapperScannerRegistrar mapperScannerRegistrar; @Override public PageResult list(AiChatModelListReqVO req) { @@ -102,6 +104,11 @@ public class AiChatModalServiceImpl implements AiChatModelService { } } + @Override + public List getModalByIds(Set modalIds) { + return aiChatModelMapper.selectByIds(modalIds); + } + public AiChatModelDO validateExists(Long id) { AiChatModelDO aiChatModalDO = aiChatModelMapper.selectById(id); if (aiChatModalDO == null) { diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java index 90649f417d..de33e65e49 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java @@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessage import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRespVO; import cn.iocoder.yudao.module.ai.convert.AiChatMessageConvert; import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; import cn.iocoder.yudao.module.ai.dal.mysql.AiChatConversationMapper; import cn.iocoder.yudao.module.ai.dal.mysql.AiChatMessageMapper; @@ -29,8 +30,11 @@ import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Flux; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * 聊天 service @@ -188,8 +192,20 @@ public class AiChatServiceImpl implements AiChatService { chatConversationService.validateExists(conversationId); // 获取对话所有 message List aiChatMessageDOList = aiChatMessageMapper.selectByConversationId(conversationId); + // 获取模型信息 + Set modalIds = aiChatMessageDOList.stream().map(AiChatMessageDO::getModelId).collect(Collectors.toSet()); + List modalList = aiChatModalService.getModalByIds(modalIds); + Map modalIdMap = modalList.stream().collect(Collectors.toMap(AiChatModelDO::getId, o -> o)); // 转换 AiChatMessageRespVO - return AiChatMessageConvert.INSTANCE.convertAiChatMessageRespVOList(aiChatMessageDOList); + List aiChatMessageRespList = AiChatMessageConvert.INSTANCE.convertAiChatMessageRespVOList(aiChatMessageDOList); + // 设置用户头像 和 模型头像 todo @芋艿 这里需要转换 用户头像、模型头像 + return aiChatMessageRespList.stream().map(item -> { + if (modalIdMap.containsKey(item.getModelId())) { +// modalIdMap.get(item.getModelId()); +// item.setModelImage() + } + return item; + }).collect(Collectors.toList()); } @Override