Commit 79bd78998d25dda9ab7f308c7ca8e9ee67912eed
1 parent
2734e54b
【增加】增加模型头像
Showing
5 changed files
with
57 additions
and
2 deletions
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; |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | + | |
| 6 | 8 | @Schema(description = "管理后台 - AI 聊天消息 Response VO") |
| 7 | 9 | @Data |
| 8 | 10 | public class AiChatMessageRespVO { |
| ... | ... | @@ -19,6 +21,9 @@ public class AiChatMessageRespVO { |
| 19 | 21 | @Schema(description = "用户编号", example = "4096") |
| 20 | 22 | private Long userId; // 仅当 user 发送时非空 |
| 21 | 23 | |
| 24 | + @Schema(description = "用户头像", example = "http://xxx") | |
| 25 | + private Long avatarUrl; // 仅当 user 发送时非空 | |
| 26 | + | |
| 22 | 27 | @Schema(description = "角色编号", example = "888") |
| 23 | 28 | private Long roleId; // 仅当 assistant 回复时非空 |
| 24 | 29 | |
| ... | ... | @@ -28,10 +33,15 @@ public class AiChatMessageRespVO { |
| 28 | 33 | @Schema(description = "模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") |
| 29 | 34 | private Long modelId; |
| 30 | 35 | |
| 36 | + @Schema(description = "模型图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") | |
| 37 | + private String modelImage; | |
| 38 | + | |
| 31 | 39 | @Schema(description = "聊天内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "你好,你好啊") |
| 32 | 40 | private String content; |
| 33 | 41 | |
| 34 | 42 | @Schema(description = "消耗 Token 数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80") |
| 35 | 43 | private Integer tokens; |
| 36 | 44 | |
| 45 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-05-12 12:51") | |
| 46 | + private LocalDateTime createTime; | |
| 37 | 47 | } | ... | ... |
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; |
| 9 | 9 | import org.apache.ibatis.annotations.Mapper; |
| 10 | 10 | import org.springframework.stereotype.Repository; |
| 11 | 11 | |
| 12 | +import java.util.Collection; | |
| 13 | +import java.util.List; | |
| 14 | +import java.util.Set; | |
| 15 | + | |
| 12 | 16 | /** |
| 13 | 17 | * chat modal |
| 14 | 18 | * |
| ... | ... | @@ -36,5 +40,11 @@ public interface AiChatModelMapper extends BaseMapperX<AiChatModelDO> { |
| 36 | 40 | return pageResult.getList().get(0); |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | - | |
| 43 | + /** | |
| 44 | + * 查询 - 根据 ids | |
| 45 | + * | |
| 46 | + * @param modalIds | |
| 47 | + * @return | |
| 48 | + */ | |
| 49 | + List<AiChatModelDO> selectByIds(Collection<Long> modalIds); | |
| 40 | 50 | } | ... | ... |
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; |
| 4 | 4 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.*; |
| 5 | 5 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 6 | 6 | |
| 7 | +import java.util.List; | |
| 8 | +import java.util.Set; | |
| 9 | + | |
| 7 | 10 | /** |
| 8 | 11 | * ai modal |
| 9 | 12 | * |
| ... | ... | @@ -64,4 +67,13 @@ public interface AiChatModelService { |
| 64 | 67 | * @param chatModal |
| 65 | 68 | */ |
| 66 | 69 | void validateAvailable(AiChatModalRespVO chatModal); |
| 70 | + | |
| 71 | + /** | |
| 72 | + * 获取 - 根据 ids 批量获取 | |
| 73 | + * | |
| 74 | + * @param modalIds | |
| 75 | + * @return | |
| 76 | + */ | |
| 77 | + List<AiChatModelDO> getModalByIds(Set<Long> modalIds); | |
| 78 | + | |
| 67 | 79 | } | ... | ... |
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; |
| 17 | 17 | import jakarta.validation.ConstraintViolation; |
| 18 | 18 | import lombok.AllArgsConstructor; |
| 19 | 19 | import lombok.extern.slf4j.Slf4j; |
| 20 | +import org.mybatis.spring.annotation.MapperScannerRegistrar; | |
| 20 | 21 | import org.springframework.stereotype.Service; |
| 21 | 22 | |
| 22 | 23 | import java.util.List; |
| ... | ... | @@ -35,6 +36,7 @@ import java.util.Set; |
| 35 | 36 | public class AiChatModalServiceImpl implements AiChatModelService { |
| 36 | 37 | |
| 37 | 38 | private final AiChatModelMapper aiChatModelMapper; |
| 39 | + private final MapperScannerRegistrar mapperScannerRegistrar; | |
| 38 | 40 | |
| 39 | 41 | @Override |
| 40 | 42 | public PageResult<AiChatModelListRespVO> list(AiChatModelListReqVO req) { |
| ... | ... | @@ -102,6 +104,11 @@ public class AiChatModalServiceImpl implements AiChatModelService { |
| 102 | 104 | } |
| 103 | 105 | } |
| 104 | 106 | |
| 107 | + @Override | |
| 108 | + public List<AiChatModelDO> getModalByIds(Set<Long> modalIds) { | |
| 109 | + return aiChatModelMapper.selectByIds(modalIds); | |
| 110 | + } | |
| 111 | + | |
| 105 | 112 | public AiChatModelDO validateExists(Long id) { |
| 106 | 113 | AiChatModelDO aiChatModalDO = aiChatModelMapper.selectById(id); |
| 107 | 114 | if (aiChatModalDO == null) { | ... | ... |
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 |
| 15 | 15 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRespVO; |
| 16 | 16 | import cn.iocoder.yudao.module.ai.convert.AiChatMessageConvert; |
| 17 | 17 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; |
| 18 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; | |
| 18 | 19 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; |
| 19 | 20 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatConversationMapper; |
| 20 | 21 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatMessageMapper; |
| ... | ... | @@ -29,8 +30,11 @@ import org.springframework.transaction.annotation.Transactional; |
| 29 | 30 | import reactor.core.publisher.Flux; |
| 30 | 31 | |
| 31 | 32 | import java.util.List; |
| 33 | +import java.util.Map; | |
| 34 | +import java.util.Set; | |
| 32 | 35 | import java.util.concurrent.atomic.AtomicInteger; |
| 33 | 36 | import java.util.function.Consumer; |
| 37 | +import java.util.stream.Collectors; | |
| 34 | 38 | |
| 35 | 39 | /** |
| 36 | 40 | * 聊天 service |
| ... | ... | @@ -188,8 +192,20 @@ public class AiChatServiceImpl implements AiChatService { |
| 188 | 192 | chatConversationService.validateExists(conversationId); |
| 189 | 193 | // 获取对话所有 message |
| 190 | 194 | List<AiChatMessageDO> aiChatMessageDOList = aiChatMessageMapper.selectByConversationId(conversationId); |
| 195 | + // 获取模型信息 | |
| 196 | + Set<Long> modalIds = aiChatMessageDOList.stream().map(AiChatMessageDO::getModelId).collect(Collectors.toSet()); | |
| 197 | + List<AiChatModelDO> modalList = aiChatModalService.getModalByIds(modalIds); | |
| 198 | + Map<Long, AiChatModelDO> modalIdMap = modalList.stream().collect(Collectors.toMap(AiChatModelDO::getId, o -> o)); | |
| 191 | 199 | // 转换 AiChatMessageRespVO |
| 192 | - return AiChatMessageConvert.INSTANCE.convertAiChatMessageRespVOList(aiChatMessageDOList); | |
| 200 | + List<AiChatMessageRespVO> aiChatMessageRespList = AiChatMessageConvert.INSTANCE.convertAiChatMessageRespVOList(aiChatMessageDOList); | |
| 201 | + // 设置用户头像 和 模型头像 todo @芋艿 这里需要转换 用户头像、模型头像 | |
| 202 | + return aiChatMessageRespList.stream().map(item -> { | |
| 203 | + if (modalIdMap.containsKey(item.getModelId())) { | |
| 204 | +// modalIdMap.get(item.getModelId()); | |
| 205 | +// item.setModelImage() | |
| 206 | + } | |
| 207 | + return item; | |
| 208 | + }).collect(Collectors.toList()); | |
| 193 | 209 | } |
| 194 | 210 | |
| 195 | 211 | @Override | ... | ... |