From 410893bc2978ddb50976cc8ba3500a1ebf4ecdf0 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Wed, 24 Apr 2024 16:48:14 +0800 Subject: [PATCH] =?UTF-8?q?chat=E8=A7=92=E8=89=B2=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=EF=BC=8C=E8=A7=92=E8=89=B2=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/ai/convert/ChatRoleConvert.java | 29 ++++++++++++++ .../module/ai/service/ChatRoleService.java | 5 ++- .../ai/service/impl/ChatRoleServiceImpl.java | 28 ++++++++++++-- .../yudao/module/ai/vo/ChatRoleAddReq.java | 38 ++++++++++++++++++- .../yudao/module/ai/vo/ChatRoleListRes.java | 37 ++++++++++++++++++ 5 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java new file mode 100644 index 0000000000..de5bece683 --- /dev/null +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.ai.convert; + +import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; +import cn.iocoder.yudao.module.ai.vo.ChatRoleListRes; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 聊天 对话 convert + * + * @author fansili + * @time 2024/4/18 16:39 + * @since 1.0 + */ +@Mapper +public interface ChatRoleConvert { + + ChatRoleConvert INSTANCE = Mappers.getMapper(ChatRoleConvert.class); + + /** + * 转换 - ChatRoleListRes + * + * @param roleList + * @return + */ + List convertChatRoleListRes(List roleList); +} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java index c4c46a5ef3..839e29ad7f 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java @@ -1,8 +1,11 @@ package cn.iocoder.yudao.module.ai.service; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.ai.vo.*; +import java.util.List; + /** * chat 角色 * @@ -17,7 +20,7 @@ public interface ChatRoleService { * @param req * @return */ - CommonResult list(ChatRoleListReq req); + PageResult list(ChatRoleListReq req); /** * chat角色 - 添加 diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java index 310e8f7660..1d46367fbc 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java @@ -1,12 +1,19 @@ package cn.iocoder.yudao.module.ai.service.impl; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.ai.convert.ChatRoleConvert; +import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; +import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper; import cn.iocoder.yudao.module.ai.service.ChatRoleService; import cn.iocoder.yudao.module.ai.vo.*; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.List; + /** * chat 角色 * @@ -18,10 +25,25 @@ import org.springframework.stereotype.Service; @Slf4j public class ChatRoleServiceImpl implements ChatRoleService { + private final AiChatRoleMapper aiChatRoleMapper; @Override - public CommonResult list(ChatRoleListReq req) { - return null; + public PageResult list(ChatRoleListReq req) { + // 查询条件 + LambdaQueryWrapperX queryWrapperX = new LambdaQueryWrapperX<>(); + // search 查询 + if (!StrUtil.isBlank(req.getSearch())) { + queryWrapperX.eq(AiChatRoleDO::getRoleName, req.getSearch()); + } + // 默认排序id desc + queryWrapperX.orderByDesc(AiChatRoleDO::getId); + // + PageResult aiChatRoleDOPageResult = aiChatRoleMapper.selectPage(req, queryWrapperX); + Long total = aiChatRoleDOPageResult.getTotal(); + List roleList = aiChatRoleDOPageResult.getList(); + // 换货res + List chatRoleListResList = ChatRoleConvert.INSTANCE.convertChatRoleListRes(roleList); + return new PageResult<>(chatRoleListResList, total); } @Override diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleAddReq.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleAddReq.java index 2c2dfcbff8..da08f11cbf 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleAddReq.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleAddReq.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.ai.vo; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.experimental.Accessors; @@ -15,6 +16,39 @@ import lombok.experimental.Accessors; @Accessors(chain = true) public class ChatRoleAddReq extends PageParam { - @Schema(description = "查询") - private String search; + @NotNull + @Schema(description = "模型编号,关联到角色使用的特定模型") + private String modelId; + + @NotNull + @Schema(description = "角色名,角色的显示名称") + private String roleName; + + @NotNull + @Schema(description = "角色介绍,详细描述角色的功能或用途") + private String roleIntroduce; + + @NotNull + @Schema(description = "角色来源,如 system(系统预置)、customer(用户自定义)") + private String roleSource; + + @NotNull + @Schema(description = "分类,角色所属的类别,如娱乐、创作等") + private String classify; + + @NotNull + @Schema(description = "发布状态,0表示仅自己可见,1表示公开,2表示禁用") + private String visibility; + + @NotNull + @Schema(description = "生成时的Top-K采样候选集大小") + private Double topK; + + @NotNull + @Schema(description = "生成时使用的核采样方法的概率阈值") + private Double topP; + + @NotNull + @Schema(description = "用于控制随机性和多样性的温度参数") + private Double temperature; } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleListRes.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleListRes.java index 8423c66b9c..5babda544c 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleListRes.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleListRes.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.ai.vo; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.experimental.Accessors; @@ -12,4 +13,40 @@ import lombok.experimental.Accessors; @Data @Accessors(chain = true) public class ChatRoleListRes { + + @Schema(description = "id") + private Long id; + + @Schema(description = "用户id") + private Long userId; + + @Schema(description = "模型id") + private String modelId; + + @Schema(description = "角色名字") + private String roleName; + + @Schema(description = "角色介绍,详细描述角色的功能或用途") + private String roleIntroduce; + + @Schema(description = "角色来源,如 system(系统预置)、customer(用户自定义)") + private String roleSource; + + @Schema(description = "分类,角色所属的类别,如娱乐、创作等") + private String classify; + + @Schema(description = "发布状态,0表示仅自己可见,1表示公开,2表示禁用") + private String visibility; + + @Schema(description = "生成时的Top-K采样候选集大小") + private Double topK; + + @Schema(description = "生成时使用的核采样方法的概率阈值") + private Double topP; + + @Schema(description = "用于控制随机性和多样性的温度参数") + private Double temperature; + + @Schema(description = "角色的使用次数统计") + private Integer useCount; }