【调整】调整AI角色模块

This commit is contained in:
cherishsince 2024-05-07 11:34:20 +08:00
parent c124681c3a
commit f0a1666e84
10 changed files with 142 additions and 128 deletions

View File

@ -12,7 +12,7 @@ import lombok.Getter;
*/
@AllArgsConstructor
@Getter
public enum AiChatRoleClassifyEnum {
public enum AiChatRoleCategoryEnum {
WRITING("writing", "写作"),
@ -21,17 +21,17 @@ public enum AiChatRoleClassifyEnum {
;
private String classify;
private String category;
private String name;
public static AiChatRoleClassifyEnum valueOfClassify(String classify) {
for (AiChatRoleClassifyEnum itemEnum : AiChatRoleClassifyEnum.values()) {
if (itemEnum.getClassify().equals(classify)) {
public static AiChatRoleCategoryEnum valueOfCategory(String category) {
for (AiChatRoleCategoryEnum itemEnum : AiChatRoleCategoryEnum.values()) {
if (itemEnum.getCategory().equals(category)) {
return itemEnum;
}
}
throw new IllegalArgumentException("Invalid MessageType value: " + classify);
throw new IllegalArgumentException("Invalid MessageType value: " + category);
}
}

View File

@ -1,36 +0,0 @@
package cn.iocoder.yudao.module.ai.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* chat角色 可见范围
*
* @author fansili
* @time 2024/4/24 16:44
* @since 1.0
*/
@AllArgsConstructor
@Getter
public enum AiChatRoleEnableEnum {
OPEN("open", "公开"),
CLOSE("close", "关闭"),
;
private String type;
private String name;
public static AiChatRoleEnableEnum valueOfType(String type) {
for (AiChatRoleEnableEnum itemEnum : AiChatRoleEnableEnum.values()) {
if (itemEnum.getType().equals(type)) {
return itemEnum;
}
}
throw new IllegalArgumentException("Invalid MessageType value: " + type);
}
}

View File

@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.*;
*/
@Tag(name = "A4-chat角色")
@RestController
@RequestMapping("/ai/chat")
@RequestMapping("/ai/chat/role")
@Slf4j
@AllArgsConstructor
public class AiChatRoleController {
@ -28,37 +28,35 @@ public class AiChatRoleController {
private final AiChatRoleService chatRoleService;
@Operation(summary = "chat角色 - 角色列表")
@GetMapping("/role/list")
@GetMapping("/list")
public PageResult<AiChatRoleListRes> list(@Validated @ModelAttribute AiChatRoleListReq req) {
return chatRoleService.list(req);
}
@Operation(summary = "chat角色 - 添加")
@PutMapping("/role")
public CommonResult<Void> add(@Validated @RequestBody AiChatRoleAddReq req) {
@PutMapping("/add")
public CommonResult<Void> add(@Validated @RequestBody AiChatRoleAddReqVO req) {
chatRoleService.add(req);
return CommonResult.success(null);
}
@Operation(summary = "chat角色 - 修改")
@PostMapping("/role/{id}")
public CommonResult<Void> update(@PathVariable("id") Long id,
@Validated @RequestBody AiChatRoleUpdateReq req) {
chatRoleService.update(id, req);
@PostMapping("/update")
public CommonResult<Void> update(@Validated @RequestBody AiChatRoleUpdateReqVO req) {
chatRoleService.update(req);
return CommonResult.success(null);
}
@Operation(summary = "chat角色 - 修改可见性")
@PostMapping("/role/{id}/update-enable")
public CommonResult<Void> updateEnable(@PathVariable("id") Long id,
@Validated @RequestBody AiChatRoleUpdateVisibilityReq req) {
chatRoleService.updateEnable(id, req);
@PostMapping("/update-public-status")
public CommonResult<Void> updatePublicStatus(@Validated @RequestBody AiChatRoleUpdatePublicStatusReqVO req) {
chatRoleService.updatePublicStatus(req);
return CommonResult.success(null);
}
@Operation(summary = "chat角色 - 删除")
@DeleteMapping("/role/{id}")
public CommonResult<Void> delete(@PathVariable("id") Long id) {
@DeleteMapping("/delete")
public CommonResult<Void> delete(@RequestParam("id") Long id) {
chatRoleService.delete(id);
return CommonResult.success(null);
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.ai.controller.admin.model.vo.role;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -14,21 +13,40 @@ import lombok.experimental.Accessors;
*/
@Data
@Accessors(chain = true)
public class AiChatRoleAddReq extends PageParam {
public class AiChatRoleAddReqVO {
@NotNull
@Schema(description = "角色名,角色的显示名称")
private String name;
@NotNull
@Schema(description = "角色介绍,详细描述角色的功能或用途")
private String introduce;
@Schema(description = "头像")
private String avatar;
@NotNull
@Schema(description = "分类,角色所属的类别,如娱乐、创作等")
private String classify;
private String category;
@NotNull
@Schema(description = "角色描述")
private String description;
@Schema(description = "角色欢迎语")
private String welcomeMessage;
@NotNull
@Schema(description = "角色设定(消息)")
private String systemMessage;
@NotNull
@Schema(description = "模型编号")
private Long modelId;
@NotNull
@Schema(description = "开启状态 open、close")
private String enable;
private Boolean publicStatus;
@NotNull
@Schema(description = "排序")
private Integer sort;
}

View File

@ -14,9 +14,14 @@ import lombok.experimental.Accessors;
*/
@Data
@Accessors(chain = true)
public class AiChatRoleUpdateVisibilityReq extends PageParam {
public class AiChatRoleUpdatePublicStatusReqVO extends PageParam {
@NotNull
@NotNull(message = "角色编号不能为空")
@Schema(description = "角色编号")
private Long id;
@NotNull(message = "开启状态不能为空")
@Schema(description = "开启状态 open、close")
private String enable;
private Boolean publicStatus;
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.ai.controller.admin.model.vo.role;
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;
/**
* chat 角色 - 更新
*
* @fansili
* @since v1.0
*/
@Data
@Accessors(chain = true)
public class AiChatRoleUpdateReq extends PageParam {
@NotNull
@Schema(description = "角色名,角色的显示名称")
private String name;
@NotNull
@Schema(description = "角色介绍,详细描述角色的功能或用途")
private String introduce;
@NotNull
@Schema(description = "分类,角色所属的类别,如娱乐、创作等")
private String classify;
@NotNull
@Schema(description = "开启状态 open、close")
private String enable;
}

View File

@ -0,0 +1,62 @@
package cn.iocoder.yudao.module.ai.controller.admin.model.vo.role;
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;
/**
* chat 角色 - 更新
*
* @fansili
* @since v1.0
*/
@Data
@Accessors(chain = true)
public class AiChatRoleUpdateReqVO extends PageParam {
@NotNull(message = "角色编号不能为空")
@Schema(description = "角色编号")
private Long id;
@NotNull
@Schema(description = "角色名,角色的显示名称")
private String name;
@Schema(description = "头像")
private String avatar;
@NotNull
@Schema(description = "分类,角色所属的类别,如娱乐、创作等")
private String category;
@NotNull
@Schema(description = "角色描述")
private String description;
@Schema(description = "角色欢迎语")
private String welcomeMessage;
@NotNull
@Schema(description = "角色设定(消息)")
private String systemMessage;
@NotNull
@Schema(description = "模型编号")
private Long modelId;
@NotNull
@Schema(description = "开启状态 open、close")
private Boolean publicStatus;
@NotNull
@Schema(description = "排序")
private Integer sort;
@NotNull
@Schema(description = "状态")
private Integer status;
}

View File

@ -1,9 +1,9 @@
package cn.iocoder.yudao.module.ai.convert;
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleAddReq;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleAddReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleRes;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleUpdateReq;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleUpdateReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleListRes;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -36,7 +36,7 @@ public interface AiChatRoleConvert {
* @param req
* @return
*/
AiChatRoleDO convertAiChatRoleDO(AiChatRoleAddReq req);
AiChatRoleDO convertAiChatRoleDO(AiChatRoleAddReqVO req);
/**
* 转换 - AiChatRoleDO
@ -44,7 +44,7 @@ public interface AiChatRoleConvert {
* @param req
* @return
*/
AiChatRoleDO convertAiChatRoleDO(AiChatRoleUpdateReq req);
AiChatRoleDO convertAiChatRoleDO(AiChatRoleUpdateReqVO req);
/**
* 转换 - AiChatRoleRes

View File

@ -26,24 +26,22 @@ public interface AiChatRoleService {
* @param req
* @return
*/
void add(AiChatRoleAddReq req);
void add(AiChatRoleAddReqVO req);
/**
* chat角色 - 修改
*
* @param id
* @param req
*/
void update(Long id, AiChatRoleUpdateReq req);
void update(AiChatRoleUpdateReqVO req);
/**
* chat角色 - 修改可见性
*
* @param id
* @param req
*/
void updateEnable(Long id, AiChatRoleUpdateVisibilityReq req);
void updatePublicStatus(AiChatRoleUpdatePublicStatusReqVO req);
/**
* chat角色 - 删除

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.ai.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
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;
@ -9,9 +10,9 @@ import cn.iocoder.yudao.module.ai.ErrorCodeConstants;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.*;
import cn.iocoder.yudao.module.ai.convert.AiChatRoleConvert;
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO;
import cn.iocoder.yudao.module.ai.enums.AiChatRoleClassifyEnum;
import cn.iocoder.yudao.module.ai.enums.AiChatRoleEnableEnum;
import cn.iocoder.yudao.module.ai.dal.mysql.AiChatRoleMapper;
import cn.iocoder.yudao.module.ai.enums.AiChatRoleCategoryEnum;
import cn.iocoder.yudao.module.ai.service.AiChatModalService;
import cn.iocoder.yudao.module.ai.service.AiChatRoleService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -31,6 +32,7 @@ import java.util.List;
public class AiChatRoleServiceImpl implements AiChatRoleService {
private final AiChatRoleMapper aiChatRoleMapper;
private final AiChatModalService aiChatModalService;
@Override
public PageResult<AiChatRoleListRes> list(AiChatRoleListReq req) {
@ -52,42 +54,43 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
}
@Override
public void add(AiChatRoleAddReq req) {
public void add(AiChatRoleAddReqVO req) {
// 转换enum并校验enum
AiChatRoleClassifyEnum.valueOfClassify(req.getClassify());
AiChatRoleEnableEnum.valueOfType(req.getEnable());
AiChatRoleCategoryEnum.valueOfCategory(req.getCategory());
// 校验模型是否存在
aiChatModalService.validateExists(req.getModelId());
// 转换do
AiChatRoleDO insertAiChatRoleDO = AiChatRoleConvert.INSTANCE.convertAiChatRoleDO(req);
insertAiChatRoleDO.setUserId(SecurityFrameworkUtils.getLoginUserId());
insertAiChatRoleDO.setUseCount(0);
insertAiChatRoleDO.setStatus(CommonStatusEnum.ENABLE.getStatus());
// 保存
aiChatRoleMapper.insert(insertAiChatRoleDO);
}
@Override
public void update(Long id, AiChatRoleUpdateReq req) {
// 转换enum并校验enum
AiChatRoleClassifyEnum.valueOfClassify(req.getClassify());
AiChatRoleEnableEnum.valueOfType(req.getEnable());
public void update(AiChatRoleUpdateReqVO req) {
// 检查角色是否存在
validateExists(id);
validateExists(req.getId());
// 转换enum并校验enum
AiChatRoleCategoryEnum.valueOfCategory(req.getCategory());
// 校验模型是否存在
aiChatModalService.validateExists(req.getModelId());
// 转换do
AiChatRoleDO updateChatRole = AiChatRoleConvert.INSTANCE.convertAiChatRoleDO(req);
updateChatRole.setId(id);
updateChatRole.setId(req.getId());
aiChatRoleMapper.updateById(updateChatRole);
}
@Override
public void updateEnable(Long id, AiChatRoleUpdateVisibilityReq req) {
// 转换enum并校验enum
AiChatRoleEnableEnum.valueOfType(req.getEnable());
public void updatePublicStatus(AiChatRoleUpdatePublicStatusReqVO req) {
// 检查角色是否存在
validateExists(id);
validateExists(req.getId());
// 更新
aiChatRoleMapper.updateById(new AiChatRoleDO()
.setId(id)
.setEnable(req.getEnable())
aiChatRoleMapper.updateById(
new AiChatRoleDO()
.setId(req.getId())
.setPublicStatus(req.getPublicStatus())
);
}