【增加】增加模型头像
This commit is contained in:
parent
2734e54b0c
commit
79bd78998d
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<AiChatModelDO> {
|
|||
return pageResult.getList().get(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询 - 根据 ids
|
||||
*
|
||||
* @param modalIds
|
||||
* @return
|
||||
*/
|
||||
List<AiChatModelDO> selectByIds(Collection<Long> modalIds);
|
||||
}
|
||||
|
|
|
@ -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<AiChatModelDO> getModalByIds(Set<Long> modalIds);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<AiChatModelListRespVO> list(AiChatModelListReqVO req) {
|
||||
|
@ -102,6 +104,11 @@ public class AiChatModalServiceImpl implements AiChatModelService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AiChatModelDO> getModalByIds(Set<Long> modalIds) {
|
||||
return aiChatModelMapper.selectByIds(modalIds);
|
||||
}
|
||||
|
||||
public AiChatModelDO validateExists(Long id) {
|
||||
AiChatModelDO aiChatModalDO = aiChatModelMapper.selectById(id);
|
||||
if (aiChatModalDO == null) {
|
||||
|
|
|
@ -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<AiChatMessageDO> aiChatMessageDOList = aiChatMessageMapper.selectByConversationId(conversationId);
|
||||
// 获取模型信息
|
||||
Set<Long> modalIds = aiChatMessageDOList.stream().map(AiChatMessageDO::getModelId).collect(Collectors.toSet());
|
||||
List<AiChatModelDO> modalList = aiChatModalService.getModalByIds(modalIds);
|
||||
Map<Long, AiChatModelDO> modalIdMap = modalList.stream().collect(Collectors.toMap(AiChatModelDO::getId, o -> o));
|
||||
// 转换 AiChatMessageRespVO
|
||||
return AiChatMessageConvert.INSTANCE.convertAiChatMessageRespVOList(aiChatMessageDOList);
|
||||
List<AiChatMessageRespVO> 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
|
||||
|
|
Loading…
Reference in New Issue