Commit 410893bc2978ddb50976cc8ba3500a1ebf4ecdf0
1 parent
c75e415b
chat角色增加,角色列表
Showing
5 changed files
with
131 additions
and
6 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.convert; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; | |
| 4 | +import cn.iocoder.yudao.module.ai.vo.ChatRoleListRes; | |
| 5 | +import org.mapstruct.Mapper; | |
| 6 | +import org.mapstruct.factory.Mappers; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 聊天 对话 convert | |
| 12 | + * | |
| 13 | + * @author fansili | |
| 14 | + * @time 2024/4/18 16:39 | |
| 15 | + * @since 1.0 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface ChatRoleConvert { | |
| 19 | + | |
| 20 | + ChatRoleConvert INSTANCE = Mappers.getMapper(ChatRoleConvert.class); | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 转换 - ChatRoleListRes | |
| 24 | + * | |
| 25 | + * @param roleList | |
| 26 | + * @return | |
| 27 | + */ | |
| 28 | + List<ChatRoleListRes> convertChatRoleListRes(List<AiChatRoleDO> roleList); | |
| 29 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.service; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | 5 | import cn.iocoder.yudao.module.ai.vo.*; |
| 5 | 6 | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 6 | 9 | /** |
| 7 | 10 | * chat 角色 |
| 8 | 11 | * |
| ... | ... | @@ -17,7 +20,7 @@ public interface ChatRoleService { |
| 17 | 20 | * @param req |
| 18 | 21 | * @return |
| 19 | 22 | */ |
| 20 | - CommonResult<ChatRoleListRes> list(ChatRoleListReq req); | |
| 23 | + PageResult<ChatRoleListRes> list(ChatRoleListReq req); | |
| 21 | 24 | |
| 22 | 25 | /** |
| 23 | 26 | * chat角色 - 添加 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.service.impl; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 3 | +import cn.hutool.core.util.StrUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.ai.convert.ChatRoleConvert; | |
| 7 | +import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; | |
| 8 | +import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper; | |
| 4 | 9 | import cn.iocoder.yudao.module.ai.service.ChatRoleService; |
| 5 | 10 | import cn.iocoder.yudao.module.ai.vo.*; |
| 6 | 11 | import lombok.AllArgsConstructor; |
| 7 | 12 | import lombok.extern.slf4j.Slf4j; |
| 8 | 13 | import org.springframework.stereotype.Service; |
| 9 | 14 | |
| 15 | +import java.util.List; | |
| 16 | + | |
| 10 | 17 | /** |
| 11 | 18 | * chat 角色 |
| 12 | 19 | * |
| ... | ... | @@ -18,10 +25,25 @@ import org.springframework.stereotype.Service; |
| 18 | 25 | @Slf4j |
| 19 | 26 | public class ChatRoleServiceImpl implements ChatRoleService { |
| 20 | 27 | |
| 28 | + private final AiChatRoleMapper aiChatRoleMapper; | |
| 21 | 29 | |
| 22 | 30 | @Override |
| 23 | - public CommonResult<ChatRoleListRes> list(ChatRoleListReq req) { | |
| 24 | - return null; | |
| 31 | + public PageResult<ChatRoleListRes> list(ChatRoleListReq req) { | |
| 32 | + // 查询条件 | |
| 33 | + LambdaQueryWrapperX<AiChatRoleDO> queryWrapperX = new LambdaQueryWrapperX<>(); | |
| 34 | + // search 查询 | |
| 35 | + if (!StrUtil.isBlank(req.getSearch())) { | |
| 36 | + queryWrapperX.eq(AiChatRoleDO::getRoleName, req.getSearch()); | |
| 37 | + } | |
| 38 | + // 默认排序id desc | |
| 39 | + queryWrapperX.orderByDesc(AiChatRoleDO::getId); | |
| 40 | + // | |
| 41 | + PageResult<AiChatRoleDO> aiChatRoleDOPageResult = aiChatRoleMapper.selectPage(req, queryWrapperX); | |
| 42 | + Long total = aiChatRoleDOPageResult.getTotal(); | |
| 43 | + List<AiChatRoleDO> roleList = aiChatRoleDOPageResult.getList(); | |
| 44 | + // 换货res | |
| 45 | + List<ChatRoleListRes> chatRoleListResList = ChatRoleConvert.INSTANCE.convertChatRoleListRes(roleList); | |
| 46 | + return new PageResult<>(chatRoleListResList, total); | |
| 25 | 47 | } |
| 26 | 48 | |
| 27 | 49 | @Override | ... | ... |
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; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | +import jakarta.validation.constraints.NotNull; | |
| 5 | 6 | import lombok.Data; |
| 6 | 7 | import lombok.experimental.Accessors; |
| 7 | 8 | |
| ... | ... | @@ -15,6 +16,39 @@ import lombok.experimental.Accessors; |
| 15 | 16 | @Accessors(chain = true) |
| 16 | 17 | public class ChatRoleAddReq extends PageParam { |
| 17 | 18 | |
| 18 | - @Schema(description = "查询") | |
| 19 | - private String search; | |
| 19 | + @NotNull | |
| 20 | + @Schema(description = "模型编号,关联到角色使用的特定模型") | |
| 21 | + private String modelId; | |
| 22 | + | |
| 23 | + @NotNull | |
| 24 | + @Schema(description = "角色名,角色的显示名称") | |
| 25 | + private String roleName; | |
| 26 | + | |
| 27 | + @NotNull | |
| 28 | + @Schema(description = "角色介绍,详细描述角色的功能或用途") | |
| 29 | + private String roleIntroduce; | |
| 30 | + | |
| 31 | + @NotNull | |
| 32 | + @Schema(description = "角色来源,如 system(系统预置)、customer(用户自定义)") | |
| 33 | + private String roleSource; | |
| 34 | + | |
| 35 | + @NotNull | |
| 36 | + @Schema(description = "分类,角色所属的类别,如娱乐、创作等") | |
| 37 | + private String classify; | |
| 38 | + | |
| 39 | + @NotNull | |
| 40 | + @Schema(description = "发布状态,0表示仅自己可见,1表示公开,2表示禁用") | |
| 41 | + private String visibility; | |
| 42 | + | |
| 43 | + @NotNull | |
| 44 | + @Schema(description = "生成时的Top-K采样候选集大小") | |
| 45 | + private Double topK; | |
| 46 | + | |
| 47 | + @NotNull | |
| 48 | + @Schema(description = "生成时使用的核采样方法的概率阈值") | |
| 49 | + private Double topP; | |
| 50 | + | |
| 51 | + @NotNull | |
| 52 | + @Schema(description = "用于控制随机性和多样性的温度参数") | |
| 53 | + private Double temperature; | |
| 20 | 54 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleListRes.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.vo; |
| 2 | 2 | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 3 | 4 | import lombok.Data; |
| 4 | 5 | import lombok.experimental.Accessors; |
| 5 | 6 | |
| ... | ... | @@ -12,4 +13,40 @@ import lombok.experimental.Accessors; |
| 12 | 13 | @Data |
| 13 | 14 | @Accessors(chain = true) |
| 14 | 15 | public class ChatRoleListRes { |
| 16 | + | |
| 17 | + @Schema(description = "id") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "用户id") | |
| 21 | + private Long userId; | |
| 22 | + | |
| 23 | + @Schema(description = "模型id") | |
| 24 | + private String modelId; | |
| 25 | + | |
| 26 | + @Schema(description = "角色名字") | |
| 27 | + private String roleName; | |
| 28 | + | |
| 29 | + @Schema(description = "角色介绍,详细描述角色的功能或用途") | |
| 30 | + private String roleIntroduce; | |
| 31 | + | |
| 32 | + @Schema(description = "角色来源,如 system(系统预置)、customer(用户自定义)") | |
| 33 | + private String roleSource; | |
| 34 | + | |
| 35 | + @Schema(description = "分类,角色所属的类别,如娱乐、创作等") | |
| 36 | + private String classify; | |
| 37 | + | |
| 38 | + @Schema(description = "发布状态,0表示仅自己可见,1表示公开,2表示禁用") | |
| 39 | + private String visibility; | |
| 40 | + | |
| 41 | + @Schema(description = "生成时的Top-K采样候选集大小") | |
| 42 | + private Double topK; | |
| 43 | + | |
| 44 | + @Schema(description = "生成时使用的核采样方法的概率阈值") | |
| 45 | + private Double topP; | |
| 46 | + | |
| 47 | + @Schema(description = "用于控制随机性和多样性的温度参数") | |
| 48 | + private Double temperature; | |
| 49 | + | |
| 50 | + @Schema(description = "角色的使用次数统计") | |
| 51 | + private Integer useCount; | |
| 15 | 52 | } | ... | ... |