From c44f558e3d3b72911eff02476eb5bdfa66a3ed02 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Wed, 24 Apr 2024 17:16:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/ai/ErrorCodeConstants.java | 1 + .../module/ai/convert/ChatRoleConvert.java | 9 ++++ .../ai/service/impl/ChatRoleServiceImpl.java | 15 ++++++- .../yudao/module/ai/vo/ChatRoleUpdateReq.java | 43 ++++++++++++++++++- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java index e3e1c869d..939de5cb9 100644 --- a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java +++ b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java @@ -22,6 +22,7 @@ public interface ErrorCodeConstants { ErrorCode AI_CHAT_CONTINUE_NOT_EXIST = new ErrorCode(1_022_000_020, "chat对话不存在!");; + ErrorCode AI_CHAT_ROLE_NOT_EXIST = new ErrorCode(1_022_000_020, "chatRole不存在!");; 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 index c3c7cb7f0..d30ea8010 100644 --- 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 @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.ai.convert; import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; import cn.iocoder.yudao.module.ai.vo.ChatRoleAddReq; import cn.iocoder.yudao.module.ai.vo.ChatRoleListRes; +import cn.iocoder.yudao.module.ai.vo.ChatRoleUpdateReq; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -35,4 +36,12 @@ public interface ChatRoleConvert { * @return */ AiChatRoleDO convertAiChatRoleDO(ChatRoleAddReq req); + + /** + * 转换 - AiChatRoleDO + * + * @param req + * @return + */ + AiChatRoleDO convertAiChatRoleDO(ChatRoleUpdateReq req); } 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 3285785ea..da3f83548 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,9 +1,11 @@ package cn.iocoder.yudao.module.ai.service.impl; import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.ai.ErrorCodeConstants; import cn.iocoder.yudao.module.ai.convert.ChatRoleConvert; import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; import cn.iocoder.yudao.module.ai.enums.ChatRoleClassifyEnum; @@ -66,7 +68,18 @@ public class ChatRoleServiceImpl implements ChatRoleService { @Override public void update(ChatRoleUpdateReq req) { - + // 转换enum,并校验enum + ChatRoleClassifyEnum.valueOfClassify(req.getClassify()); + ChatRoleVisibilityEnum.valueOfType(req.getVisibility()); + ChatRoleSourceEnum.valueOfType(req.getRoleSource()); + // 检查角色是否存在 + AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(req.getId()); + if (aiChatRoleDO == null) { + throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_CHAT_ROLE_NOT_EXIST); + } + // 转换do + AiChatRoleDO updateChatRole = ChatRoleConvert.INSTANCE.convertAiChatRoleDO(req); + aiChatRoleMapper.updateById(updateChatRole); } @Override diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateReq.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateReq.java index 2f98e4f79..3187fca43 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateReq.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateReq.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,44 @@ import lombok.experimental.Accessors; @Accessors(chain = true) public class ChatRoleUpdateReq extends PageParam { - @Schema(description = "查询") - private String search; + + @NotNull + @Schema(description = "编号") + private Long id; + + @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; }