Commit c0470dcabb7ec3cd25dc0eabde7774081f73cac3
1 parent
2b7e7763
【调整】根据api设计调整部分字段,和业务逻辑
Showing
19 changed files
with
266 additions
and
33 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java
| ... | ... | @@ -33,5 +33,6 @@ public interface ErrorCodeConstants { |
| 33 | 33 | ErrorCode AI_MODAL_CONFIG_PARAMS_INCORRECT = new ErrorCode(1_022_000_081, "AI 模型 config 参数不正确! {} "); |
| 34 | 34 | ErrorCode AI_MODAL_NOT_SUPPORTED_MODAL = new ErrorCode(1_022_000_082, "AI 模型不支持的 modal! {} "); |
| 35 | 35 | ErrorCode AI_MODAL_PLATFORM_PARAMS_INCORRECT = new ErrorCode(1_022_000_083, "AI 平台参数不正确! {} "); |
| 36 | + ErrorCode AI_MODAL_DISABLE_NOT_USED = new ErrorCode(1_022_000_084, "AI 模型禁用不能使用!"); | |
| 36 | 37 | |
| 37 | 38 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatConversationController.java
| ... | ... | @@ -32,13 +32,13 @@ public class AiChatConversationController { |
| 32 | 32 | private final AiChatConversationService chatConversationService; |
| 33 | 33 | |
| 34 | 34 | @Operation(summary = "创建 - 对话普通对话") |
| 35 | - @PostMapping("/createConversation") | |
| 35 | + @PutMapping("/createConversation") | |
| 36 | 36 | public CommonResult<AiChatConversationRes> createConversation(@RequestBody @Validated AiChatConversationCreateUserReq req) { |
| 37 | 37 | return CommonResult.success(chatConversationService.createConversation(req)); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | @Operation(summary = "创建 - 对话角色对话") |
| 41 | - @PostMapping("/createRoleConversation") | |
| 41 | + @PutMapping("/createRoleConversation") | |
| 42 | 42 | public CommonResult<AiChatConversationRes> createRoleConversation(@RequestBody @Validated AiChatConversationCreateRoleReq req) { |
| 43 | 43 | return CommonResult.success(chatConversationService.createRoleConversation(req)); |
| 44 | 44 | } |
| ... | ... | @@ -55,6 +55,14 @@ public class AiChatConversationController { |
| 55 | 55 | return CommonResult.success(chatConversationService.listConversation(req)); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | + @Operation(summary = "更新 - 更新模型") | |
| 59 | + @PostMapping("/{id}/modal") | |
| 60 | + public CommonResult<Void> updateModal(@PathVariable("id") Long id, | |
| 61 | + @RequestParam("modalId") Long modalId) { | |
| 62 | + chatConversationService.updateModal(id, modalId); | |
| 63 | + return CommonResult.success(null); | |
| 64 | + } | |
| 65 | + | |
| 58 | 66 | @Operation(summary = "删除") |
| 59 | 67 | @DeleteMapping("/{id}") |
| 60 | 68 | public CommonResult<Void> delete(@PathVariable("id") Long id) { | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatModalConvert.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.ai.convert; |
| 3 | 3 | import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatModalDO; |
| 4 | 4 | import cn.iocoder.yudao.module.ai.vo.AiChatModalAddReq; |
| 5 | 5 | import cn.iocoder.yudao.module.ai.vo.AiChatModalListRes; |
| 6 | +import cn.iocoder.yudao.module.ai.vo.AiChatModalRes; | |
| 6 | 7 | import org.mapstruct.Mapper; |
| 7 | 8 | import org.mapstruct.Mapping; |
| 8 | 9 | import org.mapstruct.Mappings; |
| ... | ... | @@ -40,4 +41,14 @@ public interface AiChatModalConvert { |
| 40 | 41 | @Mapping(target = "config", ignore = true) |
| 41 | 42 | }) |
| 42 | 43 | AiChatModalDO convertAiChatModalDO(AiChatModalAddReq req); |
| 44 | + | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 转换 - AiChatModalRes | |
| 48 | + * | |
| 49 | + * @param aiChatModalDO | |
| 50 | + * @return | |
| 51 | + */ | |
| 52 | + AiChatModalRes convertAiChatModalRes(AiChatModalDO aiChatModalDO); | |
| 53 | + | |
| 43 | 54 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatRoleConvert.java
| ... | ... | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.ai.convert; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; |
| 4 | 4 | import cn.iocoder.yudao.module.ai.vo.AiChatRoleAddReq; |
| 5 | +import cn.iocoder.yudao.module.ai.vo.AiChatRoleRes; | |
| 5 | 6 | import cn.iocoder.yudao.module.ai.vo.AiChatRoleUpdateReq; |
| 6 | 7 | import cn.iocoder.yudao.module.ai.vo.AiChatRoleListRes; |
| 7 | 8 | import org.mapstruct.Mapper; |
| ... | ... | @@ -44,4 +45,12 @@ public interface AiChatRoleConvert { |
| 44 | 45 | * @return |
| 45 | 46 | */ |
| 46 | 47 | AiChatRoleDO convertAiChatRoleDO(AiChatRoleUpdateReq req); |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 转换 - AiChatRoleRes | |
| 51 | + * | |
| 52 | + * @param aiChatRoleDO | |
| 53 | + * @return | |
| 54 | + */ | |
| 55 | + AiChatRoleRes convertAiChatRoleRes(AiChatRoleDO aiChatRoleDO); | |
| 47 | 56 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/AiChatConversationDO.java
| ... | ... | @@ -25,12 +25,18 @@ public class AiChatConversationDO extends BaseDO { |
| 25 | 25 | private Long userId; |
| 26 | 26 | |
| 27 | 27 | @Schema(description = "chat角色Id") |
| 28 | - private Long chatRoleId; | |
| 28 | + private Long roleId; | |
| 29 | 29 | |
| 30 | 30 | @Schema(description = "chat角色名称") |
| 31 | - private String chatRoleName; | |
| 31 | + private String roleName; | |
| 32 | 32 | |
| 33 | - @Schema(description = "标题(有程序自动生成)") | |
| 33 | + @Schema(description = "模型id") | |
| 34 | + private Long modalId; | |
| 35 | + | |
| 36 | + @Schema(description = "使用的模型") | |
| 37 | + private String modal; | |
| 38 | + | |
| 39 | + @Schema(description = "标题") | |
| 34 | 40 | private String title; |
| 35 | 41 | |
| 36 | 42 | @Schema(description = "对话类型(roleChat、userChat)") | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/mapper/AiChatModalMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.mapper; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 3 | 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 4 | 8 | import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatModalDO; |
| 5 | 9 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 10 | import org.springframework.stereotype.Repository; |
| ... | ... | @@ -15,4 +19,22 @@ import org.springframework.stereotype.Repository; |
| 15 | 19 | @Repository |
| 16 | 20 | @Mapper |
| 17 | 21 | public interface AiChatModalMapper extends BaseMapperX<AiChatModalDO> { |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 查询 - 第一个modal | |
| 25 | + * | |
| 26 | + * @return | |
| 27 | + */ | |
| 28 | + default AiChatModalDO selectFirstModal() { | |
| 29 | + PageResult<AiChatModalDO> pageResult = selectPage(new PageParam().setPageNo(1).setPageSize(1), | |
| 30 | + new LambdaQueryWrapperX<AiChatModalDO>() | |
| 31 | + .orderByAsc(AiChatModalDO::getSort) | |
| 32 | + ); | |
| 33 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 34 | + return null; | |
| 35 | + } | |
| 36 | + return pageResult.getList().get(0); | |
| 37 | + } | |
| 38 | + | |
| 39 | + | |
| 18 | 40 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatConversationService.java
| ... | ... | @@ -49,6 +49,15 @@ public interface AiChatConversationService { |
| 49 | 49 | List<AiChatConversationRes> listConversation(AiChatConversationListReq req); |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | + * 更新 - 更新模型 | |
| 53 | + * | |
| 54 | + * @param id | |
| 55 | + * @param modalId | |
| 56 | + * @return | |
| 57 | + */ | |
| 58 | + void updateModal(Long id, Long modalId); | |
| 59 | + | |
| 60 | + /** | |
| 52 | 61 | * 删除 - 根据id |
| 53 | 62 | * |
| 54 | 63 | * @param id | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatModalService.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.ai.vo.AiChatModalAddReq; |
| 5 | 5 | import cn.iocoder.yudao.module.ai.vo.AiChatModalListReq; |
| 6 | 6 | import cn.iocoder.yudao.module.ai.vo.AiChatModalListRes; |
| 7 | +import cn.iocoder.yudao.module.ai.vo.AiChatModalRes; | |
| 7 | 8 | |
| 8 | 9 | /** |
| 9 | 10 | * ai modal |
| ... | ... | @@ -44,4 +45,11 @@ public interface AiChatModalService { |
| 44 | 45 | */ |
| 45 | 46 | void delete(Long id); |
| 46 | 47 | |
| 48 | + /** | |
| 49 | + * 获取 - 获取 modal | |
| 50 | + * | |
| 51 | + * @param modalId | |
| 52 | + * @return | |
| 53 | + */ | |
| 54 | + AiChatModalRes getChatModal(Long modalId); | |
| 47 | 55 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatRoleService.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatConversationServiceImpl.java
| ... | ... | @@ -5,15 +5,16 @@ import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 5 | 5 | import cn.iocoder.yudao.module.ai.ErrorCodeConstants; |
| 6 | 6 | import cn.iocoder.yudao.module.ai.convert.AiChatConversationConvert; |
| 7 | 7 | import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatConversationDO; |
| 8 | -import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; | |
| 8 | +import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatModalDO; | |
| 9 | 9 | import cn.iocoder.yudao.module.ai.enums.AiChatConversationTypeEnum; |
| 10 | +import cn.iocoder.yudao.module.ai.enums.AiChatModalDisableEnum; | |
| 10 | 11 | import cn.iocoder.yudao.module.ai.mapper.AiChatConversationMapper; |
| 12 | +import cn.iocoder.yudao.module.ai.mapper.AiChatModalMapper; | |
| 11 | 13 | import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper; |
| 12 | 14 | import cn.iocoder.yudao.module.ai.service.AiChatConversationService; |
| 13 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationCreateRoleReq; | |
| 14 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationCreateUserReq; | |
| 15 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationListReq; | |
| 16 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationRes; | |
| 15 | +import cn.iocoder.yudao.module.ai.service.AiChatModalService; | |
| 16 | +import cn.iocoder.yudao.module.ai.service.AiChatRoleService; | |
| 17 | +import cn.iocoder.yudao.module.ai.vo.*; | |
| 17 | 18 | import lombok.AllArgsConstructor; |
| 18 | 19 | import lombok.extern.slf4j.Slf4j; |
| 19 | 20 | import org.jetbrains.annotations.NotNull; |
| ... | ... | @@ -33,7 +34,10 @@ import java.util.List; |
| 33 | 34 | public class AiChatConversationServiceImpl implements AiChatConversationService { |
| 34 | 35 | |
| 35 | 36 | private final AiChatRoleMapper aiChatRoleMapper; |
| 37 | + private final AiChatModalMapper aiChatModalMapper; | |
| 36 | 38 | private final AiChatConversationMapper aiChatConversationMapper; |
| 39 | + private final AiChatModalService aiChatModalService; | |
| 40 | + private final AiChatRoleService aiChatRoleService; | |
| 37 | 41 | |
| 38 | 42 | @Override |
| 39 | 43 | public AiChatConversationRes createConversation(AiChatConversationCreateUserReq req) { |
| ... | ... | @@ -45,9 +49,12 @@ public class AiChatConversationServiceImpl implements AiChatConversationService |
| 45 | 49 | if (latestConversation != null && latestConversation.getChatCount() <= 0) { |
| 46 | 50 | return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(latestConversation); |
| 47 | 51 | } |
| 52 | + // 获取第一个模型 | |
| 53 | + AiChatModalDO aiChatModalDO = aiChatModalMapper.selectFirstModal(); | |
| 48 | 54 | // 创建新的 Conversation |
| 49 | 55 | AiChatConversationDO insertConversation = saveConversation(req.getTitle(), loginUserId, |
| 50 | - null, null, AiChatConversationTypeEnum.USER_CHAT); | |
| 56 | + null, null, AiChatConversationTypeEnum.USER_CHAT, | |
| 57 | + aiChatModalDO.getId(), aiChatModalDO.getModal()); | |
| 51 | 58 | // 转换 res |
| 52 | 59 | return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation); |
| 53 | 60 | } |
| ... | ... | @@ -57,43 +64,56 @@ public class AiChatConversationServiceImpl implements AiChatConversationService |
| 57 | 64 | // 获取用户id |
| 58 | 65 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| 59 | 66 | // 查询最新的对话 |
| 60 | - AiChatConversationDO latestConversation = aiChatConversationMapper.selectLatestConversation(loginUserId); | |
| 61 | - // 如果有对话没有被使用过,那就返回这个 | |
| 62 | - if (latestConversation != null && latestConversation.getChatCount() <= 0) { | |
| 63 | - return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(latestConversation); | |
| 64 | - } | |
| 65 | - AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(req.getChatRoleId()); | |
| 67 | +// AiChatConversationDO latestConversation = aiChatConversationMapper.selectLatestConversation(loginUserId); | |
| 68 | +// // 如果有对话没有被使用过,那就返回这个 | |
| 69 | +// if (latestConversation != null && latestConversation.getChatCount() <= 0) { | |
| 70 | +// return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(latestConversation); | |
| 71 | +// } | |
| 72 | + // 查询角色 | |
| 73 | + AiChatRoleRes chatRoleRes = aiChatRoleService.getChatRole(req.getRoleId()); | |
| 74 | + // 获取第一个模型 | |
| 75 | + AiChatModalDO aiChatModalDO = aiChatModalMapper.selectFirstModal(); | |
| 66 | 76 | // 创建新的 Conversation |
| 67 | 77 | AiChatConversationDO insertConversation = saveConversation(req.getTitle(), loginUserId, |
| 68 | - req.getChatRoleId(), aiChatRoleDO.getName(), AiChatConversationTypeEnum.ROLE_CHAT); | |
| 78 | + req.getRoleId(), chatRoleRes.getName(), AiChatConversationTypeEnum.ROLE_CHAT, | |
| 79 | + aiChatModalDO.getId(), aiChatModalDO.getModal()); | |
| 69 | 80 | // 转换 res |
| 70 | 81 | return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation); |
| 71 | 82 | } |
| 72 | 83 | |
| 73 | 84 | private @NotNull AiChatConversationDO saveConversation(String title, |
| 74 | 85 | Long userId, |
| 75 | - Long chatRoleId, | |
| 76 | - String chatRoleName, | |
| 77 | - AiChatConversationTypeEnum typeEnum) { | |
| 86 | + Long roleId, | |
| 87 | + String roleName, | |
| 88 | + AiChatConversationTypeEnum typeEnum, | |
| 89 | + Long modalId, | |
| 90 | + String modal) { | |
| 78 | 91 | AiChatConversationDO insertConversation = new AiChatConversationDO(); |
| 79 | 92 | insertConversation.setId(null); |
| 80 | 93 | insertConversation.setUserId(userId); |
| 81 | - insertConversation.setChatRoleId(chatRoleId); | |
| 82 | - insertConversation.setChatRoleName(chatRoleName); | |
| 94 | + insertConversation.setRoleId(roleId); | |
| 95 | + insertConversation.setRoleName(roleName); | |
| 83 | 96 | insertConversation.setTitle(title); |
| 84 | 97 | insertConversation.setChatCount(0); |
| 85 | 98 | insertConversation.setType(typeEnum.getType()); |
| 99 | + insertConversation.setModalId(modalId); | |
| 100 | + insertConversation.setModal(modal); | |
| 86 | 101 | aiChatConversationMapper.insert(insertConversation); |
| 87 | 102 | return insertConversation; |
| 88 | 103 | } |
| 89 | 104 | |
| 90 | 105 | @Override |
| 91 | 106 | public AiChatConversationRes getConversation(Long id) { |
| 107 | + AiChatConversationDO aiChatConversationDO = validateExists(id); | |
| 108 | + return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(aiChatConversationDO); | |
| 109 | + } | |
| 110 | + | |
| 111 | + private @NotNull AiChatConversationDO validateExists(Long id) { | |
| 92 | 112 | AiChatConversationDO aiChatConversationDO = aiChatConversationMapper.selectById(id); |
| 93 | 113 | if (aiChatConversationDO == null) { |
| 94 | 114 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_CHAT_CONTINUE_NOT_EXIST); |
| 95 | 115 | } |
| 96 | - return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(aiChatConversationDO); | |
| 116 | + return aiChatConversationDO; | |
| 97 | 117 | } |
| 98 | 118 | |
| 99 | 119 | @Override |
| ... | ... | @@ -107,6 +127,24 @@ public class AiChatConversationServiceImpl implements AiChatConversationService |
| 107 | 127 | } |
| 108 | 128 | |
| 109 | 129 | @Override |
| 130 | + public void updateModal(Long id, Long modalId) { | |
| 131 | + // 校验对话是否存在 | |
| 132 | + validateExists(id); | |
| 133 | + // 获取模型 | |
| 134 | + AiChatModalRes chatModal = aiChatModalService.getChatModal(modalId); | |
| 135 | + // 判断模型是否禁用 | |
| 136 | + if (AiChatModalDisableEnum.YES.getValue().equals(chatModal.getDisable())) { | |
| 137 | + throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_DISABLE_NOT_USED); | |
| 138 | + } | |
| 139 | + // 更新对话 | |
| 140 | + aiChatConversationMapper.updateById(new AiChatConversationDO() | |
| 141 | + .setId(id) | |
| 142 | + .setModalId(chatModal.getId()) | |
| 143 | + .setModal(chatModal.getModal()) | |
| 144 | + ); | |
| 145 | + } | |
| 146 | + | |
| 147 | + @Override | |
| 110 | 148 | public void delete(Long id) { |
| 111 | 149 | aiChatConversationMapper.deleteById(id); |
| 112 | 150 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatModalServiceImpl.java
| ... | ... | @@ -22,6 +22,7 @@ import cn.iocoder.yudao.module.ai.service.AiChatModalService; |
| 22 | 22 | import cn.iocoder.yudao.module.ai.vo.AiChatModalAddReq; |
| 23 | 23 | import cn.iocoder.yudao.module.ai.vo.AiChatModalListReq; |
| 24 | 24 | import cn.iocoder.yudao.module.ai.vo.AiChatModalListRes; |
| 25 | +import cn.iocoder.yudao.module.ai.vo.AiChatModalRes; | |
| 25 | 26 | import jakarta.validation.ConstraintViolation; |
| 26 | 27 | import lombok.AllArgsConstructor; |
| 27 | 28 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -108,11 +109,19 @@ public class AiChatModalServiceImpl implements AiChatModalService { |
| 108 | 109 | aiChatModalMapper.deleteById(id); |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | - private void validateChatModalExists(Long id) { | |
| 112 | + @Override | |
| 113 | + public AiChatModalRes getChatModal(Long modalId) { | |
| 114 | + // 检查 modal 是否存在 | |
| 115 | + AiChatModalDO aiChatModalDO = validateChatModalExists(modalId); | |
| 116 | + return AiChatModalConvert.INSTANCE.convertAiChatModalRes(aiChatModalDO); | |
| 117 | + } | |
| 118 | + | |
| 119 | + private AiChatModalDO validateChatModalExists(Long id) { | |
| 112 | 120 | AiChatModalDO aiChatModalDO = aiChatModalMapper.selectById(id); |
| 113 | 121 | if (aiChatModalDO == null) { |
| 114 | 122 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_NOT_EXIST); |
| 115 | 123 | } |
| 124 | + return aiChatModalDO; | |
| 116 | 125 | } |
| 117 | 126 | |
| 118 | 127 | private void validateModal(String platform, String modal) { | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatRoleServiceImpl.java
| ... | ... | @@ -99,6 +99,13 @@ public class AiChatRoleServiceImpl implements AiChatRoleService { |
| 99 | 99 | aiChatRoleMapper.deleteById(chatRoleId); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | + @Override | |
| 103 | + public AiChatRoleRes getChatRole(Long roleId) { | |
| 104 | + // 检查角色是否存在 | |
| 105 | + AiChatRoleDO aiChatRoleDO = validateChatRoleExists(roleId); | |
| 106 | + return AiChatRoleConvert.INSTANCE.convertAiChatRoleRes(aiChatRoleDO); | |
| 107 | + } | |
| 108 | + | |
| 102 | 109 | private AiChatRoleDO validateChatRoleExists(Long id) { |
| 103 | 110 | AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(id); |
| 104 | 111 | if (aiChatRoleDO == null) { | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatConversationCreateRoleReq.java
| ... | ... | @@ -18,7 +18,7 @@ public class AiChatConversationCreateRoleReq { |
| 18 | 18 | |
| 19 | 19 | @Schema(description = "chat角色Id") |
| 20 | 20 | @NotNull(message = "聊天角色id不能为空!") |
| 21 | - private Long chatRoleId; | |
| 21 | + private Long roleId; | |
| 22 | 22 | |
| 23 | 23 | @Schema(description = "标题(有程序自动生成)") |
| 24 | 24 | @NotNull(message = "标题不能为空!") | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatConversationCreateUserReq.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatConversationRes.java
| ... | ... | @@ -22,10 +22,16 @@ public class AiChatConversationRes { |
| 22 | 22 | private Long userId; |
| 23 | 23 | |
| 24 | 24 | @Schema(description = "chat角色Id") |
| 25 | - private Long chatRoleId; | |
| 25 | + private Long roleId; | |
| 26 | 26 | |
| 27 | 27 | @Schema(description = "chat角色名称") |
| 28 | - private String chatRoleName; | |
| 28 | + private String roleName; | |
| 29 | + | |
| 30 | + @Schema(description = "模型id") | |
| 31 | + private Long modalId; | |
| 32 | + | |
| 33 | + @Schema(description = "使用的模型") | |
| 34 | + private String modal; | |
| 29 | 35 | |
| 30 | 36 | @Schema(description = "标题(有程序自动生成)") |
| 31 | 37 | private String title; |
| ... | ... | @@ -35,4 +41,5 @@ public class AiChatConversationRes { |
| 35 | 41 | |
| 36 | 42 | @Schema(description = "聊天次数(有程序自动生成)") |
| 37 | 43 | private Integer chatCount; |
| 44 | + | |
| 38 | 45 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatModalRes.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.experimental.Accessors; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * modal list | |
| 9 | + * | |
| 10 | + * @author fansili | |
| 11 | + * @time 2024/4/24 19:56 | |
| 12 | + * @since 1.0 | |
| 13 | + */ | |
| 14 | +@Data | |
| 15 | +@Accessors(chain = true) | |
| 16 | +public class AiChatModalRes { | |
| 17 | + | |
| 18 | + @Schema(description = "id") | |
| 19 | + private Long id; | |
| 20 | + | |
| 21 | + @Schema(description = "模型平台 参考 AiPlatformEnum") | |
| 22 | + private String platform; | |
| 23 | + | |
| 24 | + @Schema(description = "模型类型 参考 YiYanChatModel、XingHuoChatModel") | |
| 25 | + private String modal; | |
| 26 | + | |
| 27 | + @Schema(description = "模型名字") | |
| 28 | + private String name; | |
| 29 | + | |
| 30 | + @Schema(description = "模型照片") | |
| 31 | + private String image; | |
| 32 | + | |
| 33 | + @Schema(description = "禁用 0、正常 1、禁用") | |
| 34 | + private Integer disable; | |
| 35 | + | |
| 36 | + @Schema(description = "排序 asc 排序") | |
| 37 | + private Integer sort; | |
| 38 | + | |
| 39 | + @Schema(description = "modal 配置") | |
| 40 | + private String config; | |
| 41 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatRoleRes.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.experimental.Accessors; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * chat 角色 | |
| 9 | + * | |
| 10 | + * @fansili | |
| 11 | + * @since v1.0 | |
| 12 | + */ | |
| 13 | +@Data | |
| 14 | +@Accessors(chain = true) | |
| 15 | +public class AiChatRoleRes { | |
| 16 | + | |
| 17 | + @Schema(description = "id") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "用户id") | |
| 21 | + private Long userId; | |
| 22 | + | |
| 23 | + @Schema(description = "角色名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "角色介绍,详细描述角色的功能或用途") | |
| 27 | + private String introduce; | |
| 28 | + | |
| 29 | + @Schema(description = "分类,角色所属的类别,如娱乐、创作等") | |
| 30 | + private String classify; | |
| 31 | + | |
| 32 | + @Schema(description = "状态 open、close") | |
| 33 | + private String enable; | |
| 34 | + | |
| 35 | + @Schema(description = "角色的使用次数统计") | |
| 36 | + private Integer useCount; | |
| 37 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/resources/http/chat-conversation.http
| ... | ... | @@ -2,15 +2,27 @@ |
| 2 | 2 | ### 登录 详细使用 https://www.jetbrains.com/help/idea/testing-restful-web-services.html、https://www.cnblogs.com/crazymakercircle/p/14317222.html |
| 3 | 3 | |
| 4 | 4 | ### 对话 - 创建对话 |
| 5 | -POST {{baseUrl}}/ai/chat/conversation/create | |
| 5 | +PUT {{baseUrl}}/ai/chat/conversation/createConversation | |
| 6 | 6 | Content-Type: application/json |
| 7 | 7 | Authorization: {{token}} |
| 8 | 8 | |
| 9 | 9 | { |
| 10 | - "chatType": "userChat" | |
| 10 | + "title": "新增对话" | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | |
| 14 | +### 对话 - 创建对话 | |
| 15 | +PUT {{baseUrl}}/ai/chat/conversation/createRoleConversation | |
| 16 | +Content-Type: application/json | |
| 17 | +Authorization: {{token}} | |
| 18 | + | |
| 19 | +{ | |
| 20 | + "roleId": 7, | |
| 21 | + "title": "新增对话" | |
| 22 | +} | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 14 | 26 | ### 对话 - id获取 |
| 15 | 27 | GET {{baseUrl}}/ai/chat/conversation/1781604279872581644 |
| 16 | 28 | Authorization: {{token}} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/resources/http/chat-role.http
| ... | ... | @@ -19,14 +19,14 @@ Authorization: {{token}} |
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | ### chat update |
| 22 | -POST {{baseUrl}}/ai/chat/role/6 | |
| 22 | +POST {{baseUrl}}/ai/chat/role/7 | |
| 23 | 23 | Content-Type: application/json |
| 24 | 24 | Authorization: {{token}} |
| 25 | 25 | |
| 26 | 26 | { |
| 27 | 27 | "modelId": 1, |
| 28 | - "name": "小红书写作v1---hh😄", | |
| 29 | - "introduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。", | |
| 28 | + "name": "小红书写作v1---hh😄❀", | |
| 29 | + "introduce": "采用gpt3.5模型,拥有小红书优质作者写作经验。0----", | |
| 30 | 30 | "classify": "writing", |
| 31 | 31 | "enable": "close" |
| 32 | 32 | } | ... | ... |