Commit 2b7e7763bfea8083320425e82fe807949e67356f

Authored by cherishsince
1 parent 3d7c994b

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

yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiChatRoleVisibilityEnum.java renamed to yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiChatRoleEnableEnum.java
... ... @@ -12,10 +12,10 @@ import lombok.Getter;
12 12 */
13 13 @AllArgsConstructor
14 14 @Getter
15   -public enum AiChatRoleVisibilityEnum {
  15 +public enum AiChatRoleEnableEnum {
16 16  
17   - PUBLIC("public", "公开"),
18   - PRIVATE("private", "私有的"),
  17 + OPEN("open", "公开"),
  18 + CLOSE("close", "关闭"),
19 19  
20 20 ;
21 21  
... ... @@ -24,8 +24,8 @@ public enum AiChatRoleVisibilityEnum {
24 24 private String name;
25 25  
26 26  
27   - public static AiChatRoleVisibilityEnum valueOfType(String type) {
28   - for (AiChatRoleVisibilityEnum itemEnum : AiChatRoleVisibilityEnum.values()) {
  27 + public static AiChatRoleEnableEnum valueOfType(String type) {
  28 + for (AiChatRoleEnableEnum itemEnum : AiChatRoleEnableEnum.values()) {
29 29 if (itemEnum.getType().equals(type)) {
30 30 return itemEnum;
31 31 }
... ...
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiChatRoleSourceEnum.java deleted
1   -package cn.iocoder.yudao.module.ai.enums;
2   -
3   -import lombok.AllArgsConstructor;
4   -import lombok.Getter;
5   -
6   -/**
7   - * chat角色 source
8   - *
9   - * @author fansili
10   - * @time 2024/4/24 16:37
11   - * @since 1.0
12   - */
13   -@AllArgsConstructor
14   -@Getter
15   -public enum AiChatRoleSourceEnum {
16   -
17   - SYSTEM("system", "系统"),
18   - CUSTOMER("customer", "用户自定义"),
19   -
20   -
21   - ;
22   -
23   - private String type;
24   -
25   - private String name;
26   -
27   -
28   - public static AiChatRoleSourceEnum valueOfType(String type) {
29   - for (AiChatRoleSourceEnum itemEnum : AiChatRoleSourceEnum.values()) {
30   - if (itemEnum.getType().equals(type)) {
31   - return itemEnum;
32   - }
33   - }
34   - throw new IllegalArgumentException("Invalid MessageType value: " + type);
35   - }
36   -}
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatRoleController.java
... ... @@ -48,10 +48,10 @@ public class AiChatRoleController {
48 48 }
49 49  
50 50 @Operation(summary = "chat角色 - 修改可见性")
51   - @PostMapping("/role/{id}/update-visibility")
52   - public CommonResult<Void> updateVisibility(@PathVariable("id") Long id,
53   - @Validated @RequestBody AiChatRoleUpdateVisibilityReq req) {
54   - chatRoleService.updateVisibility(id, req);
  51 + @PostMapping("/role/{id}/update-enable")
  52 + public CommonResult<Void> updateEnable(@PathVariable("id") Long id,
  53 + @Validated @RequestBody AiChatRoleUpdateVisibilityReq req) {
  54 + chatRoleService.updateEnable(id, req);
55 55 return CommonResult.success(null);
56 56 }
57 57  
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/AiChatRoleDO.java
... ... @@ -29,24 +29,14 @@ public class AiChatRoleDO extends BaseDO {
29 29 private Long userId;
30 30  
31 31 /**
32   - * 模型编号,关联到角色使用的特定模型
33   - */
34   - private String modelId;
35   -
36   - /**
37 32 * 角色名,角色的显示名称
38 33 */
39   - private String roleName;
  34 + private String name;
40 35  
41 36 /**
42 37 * 角色介绍,详细描述角色的功能或用途
43 38 */
44   - private String roleIntroduce;
45   -
46   - /**
47   - * 角色来源,如 system(系统预置)、customer(用户自定义)
48   - */
49   - private String roleSource;
  39 + private String introduce;
50 40  
51 41 /**
52 42 * 分类,角色所属的类别,如娱乐、创作等
... ... @@ -54,24 +44,9 @@ public class AiChatRoleDO extends BaseDO {
54 44 private String classify;
55 45  
56 46 /**
57   - * 发布状态,private 表示仅自己可见,public表示公开,disable表示禁用
58   - */
59   - private String visibility;
60   -
61   - /**
62   - * 生成时的Top-K采样候选集大小
63   - */
64   - private Double topK;
65   -
66   - /**
67   - * 生成时使用的核采样方法的概率阈值
68   - */
69   - private Double topP;
70   -
71   - /**
72   - * 用于控制随机性和多样性的温度参数
  47 + * 是否开启 open、close
73 48 */
74   - private Double temperature;
  49 + private String enable;
75 50  
76 51 /**
77 52 * 角色的使用次数统计
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatRoleService.java
... ... @@ -42,7 +42,7 @@ public interface AiChatRoleService {
42 42 * @param id
43 43 * @param req
44 44 */
45   - void updateVisibility(Long id, AiChatRoleUpdateVisibilityReq req);
  45 + void updateEnable(Long id, AiChatRoleUpdateVisibilityReq req);
46 46  
47 47 /**
48 48 * chat角色 - 删除
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatConversationServiceImpl.java
... ... @@ -65,7 +65,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService
65 65 AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(req.getChatRoleId());
66 66 // 创建新的 Conversation
67 67 AiChatConversationDO insertConversation = saveConversation(req.getTitle(), loginUserId,
68   - req.getChatRoleId(), aiChatRoleDO.getRoleName(), AiChatConversationTypeEnum.ROLE_CHAT);
  68 + req.getChatRoleId(), aiChatRoleDO.getName(), AiChatConversationTypeEnum.ROLE_CHAT);
69 69 // 转换 res
70 70 return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation);
71 71 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatRoleServiceImpl.java
... ... @@ -9,8 +9,7 @@ import cn.iocoder.yudao.module.ai.ErrorCodeConstants;
9 9 import cn.iocoder.yudao.module.ai.convert.AiChatRoleConvert;
10 10 import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO;
11 11 import cn.iocoder.yudao.module.ai.enums.AiChatRoleClassifyEnum;
12   -import cn.iocoder.yudao.module.ai.enums.AiChatRoleSourceEnum;
13   -import cn.iocoder.yudao.module.ai.enums.AiChatRoleVisibilityEnum;
  12 +import cn.iocoder.yudao.module.ai.enums.AiChatRoleEnableEnum;
14 13 import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper;
15 14 import cn.iocoder.yudao.module.ai.service.AiChatRoleService;
16 15 import cn.iocoder.yudao.module.ai.vo.*;
... ... @@ -39,7 +38,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
39 38 LambdaQueryWrapperX<AiChatRoleDO> queryWrapperX = new LambdaQueryWrapperX<>();
40 39 // search 查询
41 40 if (!StrUtil.isBlank(req.getSearch())) {
42   - queryWrapperX.eq(AiChatRoleDO::getRoleName, req.getSearch());
  41 + queryWrapperX.eq(AiChatRoleDO::getName, req.getSearch());
43 42 }
44 43 // 默认排序id desc
45 44 queryWrapperX.orderByDesc(AiChatRoleDO::getId);
... ... @@ -56,8 +55,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
56 55 public void add(AiChatRoleAddReq req) {
57 56 // 转换enum,并校验enum
58 57 AiChatRoleClassifyEnum.valueOfClassify(req.getClassify());
59   - AiChatRoleVisibilityEnum.valueOfType(req.getVisibility());
60   - AiChatRoleSourceEnum.valueOfType(req.getRoleSource());
  58 + AiChatRoleEnableEnum.valueOfType(req.getEnable());
61 59 // 转换do
62 60 AiChatRoleDO insertAiChatRoleDO = AiChatRoleConvert.INSTANCE.convertAiChatRoleDO(req);
63 61 insertAiChatRoleDO.setUserId(SecurityFrameworkUtils.getLoginUserId());
... ... @@ -70,8 +68,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
70 68 public void update(Long id, AiChatRoleUpdateReq req) {
71 69 // 转换enum,并校验enum
72 70 AiChatRoleClassifyEnum.valueOfClassify(req.getClassify());
73   - AiChatRoleVisibilityEnum.valueOfType(req.getVisibility());
74   - AiChatRoleSourceEnum.valueOfType(req.getRoleSource());
  71 + AiChatRoleEnableEnum.valueOfType(req.getEnable());
75 72 // 检查角色是否存在
76 73 validateChatRoleExists(id);
77 74 // 转换do
... ... @@ -82,15 +79,15 @@ public class AiChatRoleServiceImpl implements AiChatRoleService {
82 79  
83 80  
84 81 @Override
85   - public void updateVisibility(Long id, AiChatRoleUpdateVisibilityReq req) {
  82 + public void updateEnable(Long id, AiChatRoleUpdateVisibilityReq req) {
86 83 // 转换enum,并校验enum
87   - AiChatRoleVisibilityEnum.valueOfType(req.getVisibility());
  84 + AiChatRoleEnableEnum.valueOfType(req.getEnable());
88 85 // 检查角色是否存在
89 86 validateChatRoleExists(id);
90 87 // 更新
91 88 aiChatRoleMapper.updateById(new AiChatRoleDO()
92 89 .setId(id)
93   - .setVisibility(req.getVisibility())
  90 + .setEnable(req.getEnable())
94 91 );
95 92 }
96 93  
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatRoleAddReq.java
... ... @@ -17,38 +17,18 @@ import lombok.experimental.Accessors;
17 17 public class AiChatRoleAddReq extends PageParam {
18 18  
19 19 @NotNull
20   - @Schema(description = "模型编号,关联到角色使用的特定模型")
21   - private String modelId;
22   -
23   - @NotNull
24 20 @Schema(description = "角色名,角色的显示名称")
25   - private String roleName;
  21 + private String name;
26 22  
27 23 @NotNull
28 24 @Schema(description = "角色介绍,详细描述角色的功能或用途")
29   - private String roleIntroduce;
30   -
31   - @NotNull
32   - @Schema(description = "角色来源,如 system(系统预置)、customer(用户自定义)")
33   - private String roleSource;
  25 + private String introduce;
34 26  
35 27 @NotNull
36 28 @Schema(description = "分类,角色所属的类别,如娱乐、创作等")
37 29 private String classify;
38 30  
39 31 @NotNull
40   - @Schema(description = "发布状态,private 表示仅自己可见,public表示公开,disable表示禁用\n")
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;
  32 + @Schema(description = "开启状态 open、close")
  33 + private String enable;
54 34 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatRoleListRes.java
... ... @@ -20,32 +20,17 @@ public class AiChatRoleListRes {
20 20 @Schema(description = "用户id")
21 21 private Long userId;
22 22  
23   - @Schema(description = "模型id")
24   - private String modelId;
25   -
26 23 @Schema(description = "角色名字")
27   - private String roleName;
  24 + private String name;
28 25  
29 26 @Schema(description = "角色介绍,详细描述角色的功能或用途")
30   - private String roleIntroduce;
31   -
32   - @Schema(description = "角色来源,如 system(系统预置)、customer(用户自定义)")
33   - private String roleSource;
  27 + private String introduce;
34 28  
35 29 @Schema(description = "分类,角色所属的类别,如娱乐、创作等")
36 30 private String classify;
37 31  
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;
  32 + @Schema(description = "状态 open、close")
  33 + private String enable;
49 34  
50 35 @Schema(description = "角色的使用次数统计")
51 36 private Integer useCount;
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatRoleUpdateReq.java
... ... @@ -17,38 +17,18 @@ import lombok.experimental.Accessors;
17 17 public class AiChatRoleUpdateReq extends PageParam {
18 18  
19 19 @NotNull
20   - @Schema(description = "模型编号,关联到角色使用的特定模型")
21   - private String modelId;
22   -
23   - @NotNull
24 20 @Schema(description = "角色名,角色的显示名称")
25   - private String roleName;
  21 + private String name;
26 22  
27 23 @NotNull
28 24 @Schema(description = "角色介绍,详细描述角色的功能或用途")
29   - private String roleIntroduce;
30   -
31   - @NotNull
32   - @Schema(description = "角色来源,如 system(系统预置)、customer(用户自定义)")
33   - private String roleSource;
  25 + private String introduce;
34 26  
35 27 @NotNull
36 28 @Schema(description = "分类,角色所属的类别,如娱乐、创作等")
37 29 private String classify;
38 30  
39 31 @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;
  32 + @Schema(description = "开启状态 open、close")
  33 + private String enable;
54 34 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatRoleUpdateVisibilityReq.java
... ... @@ -17,6 +17,6 @@ import lombok.experimental.Accessors;
17 17 public class AiChatRoleUpdateVisibilityReq extends PageParam {
18 18  
19 19 @NotNull
20   - @Schema(description = "发布状态,0表示仅自己可见,1表示公开,2表示禁用")
21   - private String visibility;
  20 + @Schema(description = "开启状态 open、close")
  21 + private String enable;
22 22 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/resources/http/chat-role.http
... ... @@ -11,41 +11,33 @@ Authorization: {{token}}
11 11  
12 12 {
13 13 "modelId": 1,
14   - "roleName": "小红书写作v1",
15   - "roleIntroduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。",
16   - "roleSource": "system",
  14 + "name": "小红书写作v1",
  15 + "introduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。",
17 16 "classify": "writing",
18   - "visibility": "public",
19   - "topK": 0.2,
20   - "topP": 0.4,
21   - "temperature": 0.7
  17 + "enable": "open"
22 18 }
23 19  
24 20  
25 21 ### chat update
26   -POST {{baseUrl}}/ai/chat/role/1
  22 +POST {{baseUrl}}/ai/chat/role/6
27 23 Content-Type: application/json
28 24 Authorization: {{token}}
29 25  
30 26 {
31 27 "modelId": 1,
32   - "roleName": "小红书写作v1---hh😄",
33   - "roleIntroduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。",
34   - "roleSource": "system",
  28 + "name": "小红书写作v1---hh😄",
  29 + "introduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。",
35 30 "classify": "writing",
36   - "visibility": "public",
37   - "topK": 0.2,
38   - "topP": 0.4,
39   - "temperature": 0.7
  31 + "enable": "close"
40 32 }
41 33  
42 34 ### chat update
43   -POST {{baseUrl}}/ai/chat/role/1/update-visibility
  35 +POST {{baseUrl}}/ai/chat/role/6/update-visibility
44 36 Content-Type: application/json
45 37 Authorization: {{token}}
46 38  
47 39 {
48   - "visibility": "private"
  40 + "enable": "open"
49 41 }
50 42  
51 43  
... ...