【调整】根据api调整ai角色,删除对modal关联 和 modal topK 相关设置。简单改为只是一个角色的预设

This commit is contained in:
cherishsince 2024-05-06 17:11:30 +08:00
parent 3d7c994bf9
commit 2b7e7763bf
12 changed files with 45 additions and 172 deletions

View File

@ -12,10 +12,10 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum AiChatRoleVisibilityEnum { public enum AiChatRoleEnableEnum {
PUBLIC("public", "公开"), OPEN("open", "公开"),
PRIVATE("private", "私有的"), CLOSE("close", "关闭"),
; ;
@ -24,8 +24,8 @@ public enum AiChatRoleVisibilityEnum {
private String name; private String name;
public static AiChatRoleVisibilityEnum valueOfType(String type) { public static AiChatRoleEnableEnum valueOfType(String type) {
for (AiChatRoleVisibilityEnum itemEnum : AiChatRoleVisibilityEnum.values()) { for (AiChatRoleEnableEnum itemEnum : AiChatRoleEnableEnum.values()) {
if (itemEnum.getType().equals(type)) { if (itemEnum.getType().equals(type)) {
return itemEnum; return itemEnum;
} }

View File

@ -1,36 +0,0 @@
package cn.iocoder.yudao.module.ai.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* chat角色 source
*
* @author fansili
* @time 2024/4/24 16:37
* @since 1.0
*/
@AllArgsConstructor
@Getter
public enum AiChatRoleSourceEnum {
SYSTEM("system", "系统"),
CUSTOMER("customer", "用户自定义"),
;
private String type;
private String name;
public static AiChatRoleSourceEnum valueOfType(String type) {
for (AiChatRoleSourceEnum itemEnum : AiChatRoleSourceEnum.values()) {
if (itemEnum.getType().equals(type)) {
return itemEnum;
}
}
throw new IllegalArgumentException("Invalid MessageType value: " + type);
}
}

View File

@ -48,10 +48,10 @@ public class AiChatRoleController {
} }
@Operation(summary = "chat角色 - 修改可见性") @Operation(summary = "chat角色 - 修改可见性")
@PostMapping("/role/{id}/update-visibility") @PostMapping("/role/{id}/update-enable")
public CommonResult<Void> updateVisibility(@PathVariable("id") Long id, public CommonResult<Void> updateEnable(@PathVariable("id") Long id,
@Validated @RequestBody AiChatRoleUpdateVisibilityReq req) { @Validated @RequestBody AiChatRoleUpdateVisibilityReq req) {
chatRoleService.updateVisibility(id, req); chatRoleService.updateEnable(id, req);
return CommonResult.success(null); return CommonResult.success(null);
} }

View File

@ -28,25 +28,15 @@ public class AiChatRoleDO extends BaseDO {
*/ */
private Long userId; private Long userId;
/**
* 模型编号关联到角色使用的特定模型
*/
private String modelId;
/** /**
* 角色名角色的显示名称 * 角色名角色的显示名称
*/ */
private String roleName; private String name;
/** /**
* 角色介绍详细描述角色的功能或用途 * 角色介绍详细描述角色的功能或用途
*/ */
private String roleIntroduce; private String introduce;
/**
* 角色来源 system系统预置customer用户自定义
*/
private String roleSource;
/** /**
* 分类角色所属的类别如娱乐创作等 * 分类角色所属的类别如娱乐创作等
@ -54,24 +44,9 @@ public class AiChatRoleDO extends BaseDO {
private String classify; private String classify;
/** /**
* 发布状态private 表示仅自己可见public表示公开disable表示禁用 * 是否开启 openclose
*/ */
private String visibility; private String enable;
/**
* 生成时的Top-K采样候选集大小
*/
private Double topK;
/**
* 生成时使用的核采样方法的概率阈值
*/
private Double topP;
/**
* 用于控制随机性和多样性的温度参数
*/
private Double temperature;
/** /**
* 角色的使用次数统计 * 角色的使用次数统计

View File

@ -42,7 +42,7 @@ public interface AiChatRoleService {
* @param id * @param id
* @param req * @param req
*/ */
void updateVisibility(Long id, AiChatRoleUpdateVisibilityReq req); void updateEnable(Long id, AiChatRoleUpdateVisibilityReq req);
/** /**
* chat角色 - 删除 * chat角色 - 删除

View File

@ -65,7 +65,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService
AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(req.getChatRoleId()); AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(req.getChatRoleId());
// 创建新的 Conversation // 创建新的 Conversation
AiChatConversationDO insertConversation = saveConversation(req.getTitle(), loginUserId, AiChatConversationDO insertConversation = saveConversation(req.getTitle(), loginUserId,
req.getChatRoleId(), aiChatRoleDO.getRoleName(), AiChatConversationTypeEnum.ROLE_CHAT); req.getChatRoleId(), aiChatRoleDO.getName(), AiChatConversationTypeEnum.ROLE_CHAT);
// 转换 res // 转换 res
return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation); return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation);
} }

View File

@ -9,8 +9,7 @@ import cn.iocoder.yudao.module.ai.ErrorCodeConstants;
import cn.iocoder.yudao.module.ai.convert.AiChatRoleConvert; import cn.iocoder.yudao.module.ai.convert.AiChatRoleConvert;
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO;
import cn.iocoder.yudao.module.ai.enums.AiChatRoleClassifyEnum; import cn.iocoder.yudao.module.ai.enums.AiChatRoleClassifyEnum;
import cn.iocoder.yudao.module.ai.enums.AiChatRoleSourceEnum; import cn.iocoder.yudao.module.ai.enums.AiChatRoleEnableEnum;
import cn.iocoder.yudao.module.ai.enums.AiChatRoleVisibilityEnum;
import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper; import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper;
import cn.iocoder.yudao.module.ai.service.AiChatRoleService; import cn.iocoder.yudao.module.ai.service.AiChatRoleService;
import cn.iocoder.yudao.module.ai.vo.*; import cn.iocoder.yudao.module.ai.vo.*;
@ -39,7 +38,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
LambdaQueryWrapperX<AiChatRoleDO> queryWrapperX = new LambdaQueryWrapperX<>(); LambdaQueryWrapperX<AiChatRoleDO> queryWrapperX = new LambdaQueryWrapperX<>();
// search 查询 // search 查询
if (!StrUtil.isBlank(req.getSearch())) { if (!StrUtil.isBlank(req.getSearch())) {
queryWrapperX.eq(AiChatRoleDO::getRoleName, req.getSearch()); queryWrapperX.eq(AiChatRoleDO::getName, req.getSearch());
} }
// 默认排序id desc // 默认排序id desc
queryWrapperX.orderByDesc(AiChatRoleDO::getId); queryWrapperX.orderByDesc(AiChatRoleDO::getId);
@ -56,8 +55,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
public void add(AiChatRoleAddReq req) { public void add(AiChatRoleAddReq req) {
// 转换enum并校验enum // 转换enum并校验enum
AiChatRoleClassifyEnum.valueOfClassify(req.getClassify()); AiChatRoleClassifyEnum.valueOfClassify(req.getClassify());
AiChatRoleVisibilityEnum.valueOfType(req.getVisibility()); AiChatRoleEnableEnum.valueOfType(req.getEnable());
AiChatRoleSourceEnum.valueOfType(req.getRoleSource());
// 转换do // 转换do
AiChatRoleDO insertAiChatRoleDO = AiChatRoleConvert.INSTANCE.convertAiChatRoleDO(req); AiChatRoleDO insertAiChatRoleDO = AiChatRoleConvert.INSTANCE.convertAiChatRoleDO(req);
insertAiChatRoleDO.setUserId(SecurityFrameworkUtils.getLoginUserId()); insertAiChatRoleDO.setUserId(SecurityFrameworkUtils.getLoginUserId());
@ -70,8 +68,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
public void update(Long id, AiChatRoleUpdateReq req) { public void update(Long id, AiChatRoleUpdateReq req) {
// 转换enum并校验enum // 转换enum并校验enum
AiChatRoleClassifyEnum.valueOfClassify(req.getClassify()); AiChatRoleClassifyEnum.valueOfClassify(req.getClassify());
AiChatRoleVisibilityEnum.valueOfType(req.getVisibility()); AiChatRoleEnableEnum.valueOfType(req.getEnable());
AiChatRoleSourceEnum.valueOfType(req.getRoleSource());
// 检查角色是否存在 // 检查角色是否存在
validateChatRoleExists(id); validateChatRoleExists(id);
// 转换do // 转换do
@ -82,15 +79,15 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
@Override @Override
public void updateVisibility(Long id, AiChatRoleUpdateVisibilityReq req) { public void updateEnable(Long id, AiChatRoleUpdateVisibilityReq req) {
// 转换enum并校验enum // 转换enum并校验enum
AiChatRoleVisibilityEnum.valueOfType(req.getVisibility()); AiChatRoleEnableEnum.valueOfType(req.getEnable());
// 检查角色是否存在 // 检查角色是否存在
validateChatRoleExists(id); validateChatRoleExists(id);
// 更新 // 更新
aiChatRoleMapper.updateById(new AiChatRoleDO() aiChatRoleMapper.updateById(new AiChatRoleDO()
.setId(id) .setId(id)
.setVisibility(req.getVisibility()) .setEnable(req.getEnable())
); );
} }

View File

@ -16,39 +16,19 @@ import lombok.experimental.Accessors;
@Accessors(chain = true) @Accessors(chain = true)
public class AiChatRoleAddReq extends PageParam { public class AiChatRoleAddReq extends PageParam {
@NotNull
@Schema(description = "模型编号,关联到角色使用的特定模型")
private String modelId;
@NotNull @NotNull
@Schema(description = "角色名,角色的显示名称") @Schema(description = "角色名,角色的显示名称")
private String roleName; private String name;
@NotNull @NotNull
@Schema(description = "角色介绍,详细描述角色的功能或用途") @Schema(description = "角色介绍,详细描述角色的功能或用途")
private String roleIntroduce; private String introduce;
@NotNull
@Schema(description = "角色来源,如 system系统预置、customer用户自定义")
private String roleSource;
@NotNull @NotNull
@Schema(description = "分类,角色所属的类别,如娱乐、创作等") @Schema(description = "分类,角色所属的类别,如娱乐、创作等")
private String classify; private String classify;
@NotNull @NotNull
@Schema(description = "发布状态private 表示仅自己可见public表示公开disable表示禁用\n") @Schema(description = "开启状态 open、close")
private String visibility; private String enable;
@NotNull
@Schema(description = "生成时的Top-K采样候选集大小")
private Double topK;
@NotNull
@Schema(description = "生成时使用的核采样方法的概率阈值")
private Double topP;
@NotNull
@Schema(description = "用于控制随机性和多样性的温度参数")
private Double temperature;
} }

View File

@ -20,32 +20,17 @@ public class AiChatRoleListRes {
@Schema(description = "用户id") @Schema(description = "用户id")
private Long userId; private Long userId;
@Schema(description = "模型id")
private String modelId;
@Schema(description = "角色名字") @Schema(description = "角色名字")
private String roleName; private String name;
@Schema(description = "角色介绍,详细描述角色的功能或用途") @Schema(description = "角色介绍,详细描述角色的功能或用途")
private String roleIntroduce; private String introduce;
@Schema(description = "角色来源,如 system系统预置、customer用户自定义")
private String roleSource;
@Schema(description = "分类,角色所属的类别,如娱乐、创作等") @Schema(description = "分类,角色所属的类别,如娱乐、创作等")
private String classify; private String classify;
@Schema(description = "发布状态0表示仅自己可见1表示公开2表示禁用") @Schema(description = "状态 open、close")
private String visibility; private String enable;
@Schema(description = "生成时的Top-K采样候选集大小")
private Double topK;
@Schema(description = "生成时使用的核采样方法的概率阈值")
private Double topP;
@Schema(description = "用于控制随机性和多样性的温度参数")
private Double temperature;
@Schema(description = "角色的使用次数统计") @Schema(description = "角色的使用次数统计")
private Integer useCount; private Integer useCount;

View File

@ -16,39 +16,19 @@ import lombok.experimental.Accessors;
@Accessors(chain = true) @Accessors(chain = true)
public class AiChatRoleUpdateReq extends PageParam { public class AiChatRoleUpdateReq extends PageParam {
@NotNull
@Schema(description = "模型编号,关联到角色使用的特定模型")
private String modelId;
@NotNull @NotNull
@Schema(description = "角色名,角色的显示名称") @Schema(description = "角色名,角色的显示名称")
private String roleName; private String name;
@NotNull @NotNull
@Schema(description = "角色介绍,详细描述角色的功能或用途") @Schema(description = "角色介绍,详细描述角色的功能或用途")
private String roleIntroduce; private String introduce;
@NotNull
@Schema(description = "角色来源,如 system系统预置、customer用户自定义")
private String roleSource;
@NotNull @NotNull
@Schema(description = "分类,角色所属的类别,如娱乐、创作等") @Schema(description = "分类,角色所属的类别,如娱乐、创作等")
private String classify; private String classify;
@NotNull @NotNull
@Schema(description = "发布状态0表示仅自己可见1表示公开2表示禁用") @Schema(description = "开启状态 open、close")
private String visibility; private String enable;
@NotNull
@Schema(description = "生成时的Top-K采样候选集大小")
private Double topK;
@NotNull
@Schema(description = "生成时使用的核采样方法的概率阈值")
private Double topP;
@NotNull
@Schema(description = "用于控制随机性和多样性的温度参数")
private Double temperature;
} }

View File

@ -17,6 +17,6 @@ import lombok.experimental.Accessors;
public class AiChatRoleUpdateVisibilityReq extends PageParam { public class AiChatRoleUpdateVisibilityReq extends PageParam {
@NotNull @NotNull
@Schema(description = "发布状态0表示仅自己可见1表示公开2表示禁用") @Schema(description = "开启状态 open、close")
private String visibility; private String enable;
} }

View File

@ -11,41 +11,33 @@ Authorization: {{token}}
{ {
"modelId": 1, "modelId": 1,
"roleName": "小红书写作v1", "name": "小红书写作v1",
"roleIntroduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。", "introduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。",
"roleSource": "system",
"classify": "writing", "classify": "writing",
"visibility": "public", "enable": "open"
"topK": 0.2,
"topP": 0.4,
"temperature": 0.7
} }
### chat update ### chat update
POST {{baseUrl}}/ai/chat/role/1 POST {{baseUrl}}/ai/chat/role/6
Content-Type: application/json Content-Type: application/json
Authorization: {{token}} Authorization: {{token}}
{ {
"modelId": 1, "modelId": 1,
"roleName": "小红书写作v1---hh😄", "name": "小红书写作v1---hh😄",
"roleIntroduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。", "introduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。",
"roleSource": "system",
"classify": "writing", "classify": "writing",
"visibility": "public", "enable": "close"
"topK": 0.2,
"topP": 0.4,
"temperature": 0.7
} }
### chat update ### chat update
POST {{baseUrl}}/ai/chat/role/1/update-visibility POST {{baseUrl}}/ai/chat/role/6/update-visibility
Content-Type: application/json Content-Type: application/json
Authorization: {{token}} Authorization: {{token}}
{ {
"visibility": "private" "enable": "open"
} }