Commit 3bb57edc85c48dcb6475ce7c7b98395a3682054b
1 parent
9126691a
【功能新增】AI:聊天角色,新增 knowledge 的引用绑定
Showing
12 changed files
with
59 additions
and
55 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeController.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.controller.admin.knowledge; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| ... | ... | @@ -17,7 +18,10 @@ import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | 18 | import org.springframework.validation.annotation.Validated; |
| 18 | 19 | import org.springframework.web.bind.annotation.*; |
| 19 | 20 | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 20 | 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 21 | 25 | |
| 22 | 26 | // TODO @芋艿:增加权限标识 |
| 23 | 27 | @Tag(name = "管理后台 - AI 知识库") |
| ... | ... | @@ -62,4 +66,12 @@ public class AiKnowledgeController { |
| 62 | 66 | return success(true); |
| 63 | 67 | } |
| 64 | 68 | |
| 69 | + @GetMapping("/simple-list") | |
| 70 | + @Operation(summary = "获得知识库的精简列表") | |
| 71 | + public CommonResult<List<AiKnowledgeRespVO>> getKnowledgeSimpleList() { | |
| 72 | + List<AiKnowledgeDO> list = knowledgeService.getKnowledgeSimpleListByStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 73 | + return success(convertList(list, knowledge -> new AiKnowledgeRespVO() | |
| 74 | + .setId(knowledge.getId()).setName(knowledge.getName()))); | |
| 75 | + } | |
| 76 | + | |
| 65 | 77 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeDocumentController.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.controller.admin.knowledge; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentPageReqVO; | |
| 8 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentRespVO; | |
| 9 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentUpdateReqVO; | |
| 10 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentCreateListReqVO; | |
| 11 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentUpdateStatusReqVO; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.*; | |
| 12 | 7 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeDocumentCreateReqVO; |
| 13 | 8 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO; |
| 14 | -import cn.iocoder.yudao.module.ai.dal.mysql.knowledge.AiKnowledgeDocumentMapper; | |
| 15 | 9 | import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeDocumentService; |
| 16 | 10 | import io.swagger.v3.oas.annotations.Operation; |
| 17 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 18 | 11 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 19 | 12 | import jakarta.annotation.Resource; |
| 20 | 13 | import jakarta.validation.Valid; |
| ... | ... | @@ -25,7 +18,6 @@ import org.springframework.web.bind.annotation.*; |
| 25 | 18 | import java.util.List; |
| 26 | 19 | |
| 27 | 20 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 29 | 21 | |
| 30 | 22 | @Tag(name = "管理后台 - AI 知识库文档") |
| 31 | 23 | @RestController |
| ... | ... | @@ -95,13 +87,4 @@ public class AiKnowledgeDocumentController { |
| 95 | 87 | return success(true); |
| 96 | 88 | } |
| 97 | 89 | |
| 98 | - @GetMapping("/simple-list") | |
| 99 | - @Operation(summary = "获得知识库文档的精简列表") | |
| 100 | - public CommonResult<List<AiKnowledgeDocumentRespVO>> getKnowledgeDocumentSimpleList() { | |
| 101 | - List<AiKnowledgeDocumentDO> list = documentService | |
| 102 | - .getKnowledgeDocumentListByStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 103 | - return success(convertList(list, document -> new AiKnowledgeDocumentRespVO() | |
| 104 | - .setId(document.getId()).setName(document.getName()))); | |
| 105 | - } | |
| 106 | - | |
| 107 | 90 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/chatRole/AiChatRoleRespVO.java
| ... | ... | @@ -46,8 +46,8 @@ public class AiChatRoleRespVO implements VO { |
| 46 | 46 | @Schema(description = "角色设定", requiredMode = Schema.RequiredMode.REQUIRED) |
| 47 | 47 | private String systemMessage; |
| 48 | 48 | |
| 49 | - @Schema(description = "知识库文档编号列表", example = "1,2,3") | |
| 50 | - private List<Long> documentIds; | |
| 49 | + @Schema(description = "引用的知识库编号列表", example = "1,2,3") | |
| 50 | + private List<Long> knowledgeIds; | |
| 51 | 51 | |
| 52 | 52 | @Schema(description = "是否公开", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 53 | 53 | private Boolean publicStatus; | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/chatRole/AiChatRoleSaveMyReqVO.java
| ... | ... | @@ -31,7 +31,7 @@ public class AiChatRoleSaveMyReqVO { |
| 31 | 31 | @NotEmpty(message = "角色设定不能为空") |
| 32 | 32 | private String systemMessage; |
| 33 | 33 | |
| 34 | - @Schema(description = "知识库文档编号列表", example = "1,2,3") | |
| 35 | - private List<Long> documentIds; | |
| 34 | + @Schema(description = "引用的知识库编号列表", example = "1,2,3") | |
| 35 | + private List<Long> knowledgeIds; | |
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/chatRole/AiChatRoleSaveReqVO.java
| ... | ... | @@ -44,8 +44,8 @@ public class AiChatRoleSaveReqVO { |
| 44 | 44 | @NotEmpty(message = "角色设定不能为空") |
| 45 | 45 | private String systemMessage; |
| 46 | 46 | |
| 47 | - @Schema(description = "知识库文档编号列表", example = "1,2,3") | |
| 48 | - private List<Long> documentIds; | |
| 47 | + @Schema(description = "引用的知识库编号列表", example = "1,2,3") | |
| 48 | + private List<Long> knowledgeIds; | |
| 49 | 49 | |
| 50 | 50 | @Schema(description = "是否公开", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 51 | 51 | @NotNull(message = "是否公开不能为空") | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/model/AiChatRoleDO.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.ai.dal.dataobject.model; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; |
| 6 | -import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO; | |
| 6 | +import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO; | |
| 7 | 7 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 8 | 8 | import com.baomidou.mybatisplus.annotation.TableField; |
| 9 | 9 | import com.baomidou.mybatisplus.annotation.TableId; |
| ... | ... | @@ -68,12 +68,12 @@ public class AiChatRoleDO extends BaseDO { |
| 68 | 68 | private Long modelId; |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * 知识库文档编号列表 | |
| 71 | + * 引用的知识库编号列表 | |
| 72 | 72 | * |
| 73 | - * 关联 {@link AiKnowledgeDocumentDO#getId()} 字段 | |
| 73 | + * 关联 {@link AiKnowledgeDO#getId()} 字段 | |
| 74 | 74 | */ |
| 75 | 75 | @TableField(typeHandler = LongListTypeHandler.class) |
| 76 | - private List<Long> documentIds; | |
| 76 | + private List<Long> knowledgeIds; | |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * 是否公开 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeMapper.java
| ... | ... | @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnow |
| 7 | 7 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO; |
| 8 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 10 | 12 | /** |
| 11 | 13 | * AI 知识库 Mapper |
| 12 | 14 | * |
| ... | ... | @@ -23,4 +25,8 @@ public interface AiKnowledgeMapper extends BaseMapperX<AiKnowledgeDO> { |
| 23 | 25 | .orderByDesc(AiKnowledgeDO::getId)); |
| 24 | 26 | } |
| 25 | 27 | |
| 28 | + default List<AiKnowledgeDO> selectListByStatus(Integer status) { | |
| 29 | + return selectList(AiKnowledgeDO::getStatus, status); | |
| 30 | + } | |
| 31 | + | |
| 26 | 32 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeDocumentService.java
| ... | ... | @@ -115,12 +115,4 @@ public interface AiKnowledgeDocumentService { |
| 115 | 115 | return convertMap(getKnowledgeDocumentList(ids), AiKnowledgeDocumentDO::getId); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - /** | |
| 119 | - * 获取指定状态的文档列表 | |
| 120 | - * | |
| 121 | - * @param status 状态 | |
| 122 | - * @return 文档列表 | |
| 123 | - */ | |
| 124 | - List<AiKnowledgeDocumentDO> getKnowledgeDocumentListByStatus(Integer status); | |
| 125 | - | |
| 126 | 118 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeDocumentServiceImpl.java
| ... | ... | @@ -7,7 +7,6 @@ import cn.hutool.http.HttpUtil; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 10 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 11 | 10 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentCreateListReqVO; |
| 12 | 11 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentPageReqVO; |
| 13 | 12 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentUpdateReqVO; |
| ... | ... | @@ -211,9 +210,4 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic |
| 211 | 210 | return knowledgeDocumentMapper.selectByIds(ids); |
| 212 | 211 | } |
| 213 | 212 | |
| 214 | - @Override | |
| 215 | - public List<AiKnowledgeDocumentDO> getKnowledgeDocumentListByStatus(Integer status) { | |
| 216 | - return knowledgeDocumentMapper.selectListByStatus(status); | |
| 217 | - } | |
| 218 | - | |
| 219 | 213 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeService.java
| ... | ... | @@ -5,6 +5,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnow |
| 5 | 5 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeSaveReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO; |
| 7 | 7 | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 8 | 10 | /** |
| 9 | 11 | * AI 知识库-基础信息 Service 接口 |
| 10 | 12 | * |
| ... | ... | @@ -50,4 +52,12 @@ public interface AiKnowledgeService { |
| 50 | 52 | */ |
| 51 | 53 | PageResult<AiKnowledgeDO> getKnowledgePage(AiKnowledgePageReqVO pageReqVO); |
| 52 | 54 | |
| 55 | + /** | |
| 56 | + * 获得指定状态的知识库列表 | |
| 57 | + * | |
| 58 | + * @param status 状态 | |
| 59 | + * @return 知识库列表 | |
| 60 | + */ | |
| 61 | + List<AiKnowledgeDO> getKnowledgeSimpleListByStatus(Integer status); | |
| 62 | + | |
| 53 | 63 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeServiceImpl.java
| ... | ... | @@ -12,6 +12,8 @@ import jakarta.annotation.Resource; |
| 12 | 12 | import lombok.extern.slf4j.Slf4j; |
| 13 | 13 | import org.springframework.stereotype.Service; |
| 14 | 14 | |
| 15 | +import java.util.List; | |
| 16 | + | |
| 15 | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 16 | 18 | import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.KNOWLEDGE_NOT_EXISTS; |
| 17 | 19 | |
| ... | ... | @@ -76,4 +78,9 @@ public class AiKnowledgeServiceImpl implements AiKnowledgeService { |
| 76 | 78 | return knowledgeMapper.selectPage(pageReqVO); |
| 77 | 79 | } |
| 78 | 80 | |
| 81 | + @Override | |
| 82 | + public List<AiKnowledgeDO> getKnowledgeSimpleListByStatus(Integer status) { | |
| 83 | + return knowledgeMapper.selectListByStatus(status); | |
| 84 | + } | |
| 85 | + | |
| 79 | 86 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatRoleServiceImpl.java
| ... | ... | @@ -5,14 +5,13 @@ import cn.hutool.core.util.ObjectUtil; |
| 5 | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 9 | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 10 | 9 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRolePageReqVO; |
| 11 | 10 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleSaveMyReqVO; |
| 12 | 11 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleSaveReqVO; |
| 13 | 12 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; |
| 14 | 13 | import cn.iocoder.yudao.module.ai.dal.mysql.model.AiChatRoleMapper; |
| 15 | -import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeDocumentService; | |
| 14 | +import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeService; | |
| 16 | 15 | import jakarta.annotation.Resource; |
| 17 | 16 | import lombok.extern.slf4j.Slf4j; |
| 18 | 17 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -23,7 +22,8 @@ import java.util.List; |
| 23 | 22 | |
| 24 | 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 25 | 24 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 26 | -import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.*; | |
| 25 | +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.CHAT_ROLE_DISABLE; | |
| 26 | +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.CHAT_ROLE_NOT_EXISTS; | |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * AI 聊天角色 Service 实现类 |
| ... | ... | @@ -38,12 +38,12 @@ public class AiChatRoleServiceImpl implements AiChatRoleService { |
| 38 | 38 | private AiChatRoleMapper chatRoleMapper; |
| 39 | 39 | |
| 40 | 40 | @Resource |
| 41 | - private AiKnowledgeDocumentService knowledgeDocumentService; | |
| 41 | + private AiKnowledgeService knowledgeService; | |
| 42 | 42 | |
| 43 | 43 | @Override |
| 44 | 44 | public Long createChatRole(AiChatRoleSaveReqVO createReqVO) { |
| 45 | 45 | // 校验文档 |
| 46 | - validateDocuments(createReqVO.getDocumentIds()); | |
| 46 | + validateDocuments(createReqVO.getKnowledgeIds()); | |
| 47 | 47 | |
| 48 | 48 | // 保存角色 |
| 49 | 49 | AiChatRoleDO chatRole = BeanUtils.toBean(createReqVO, AiChatRoleDO.class); |
| ... | ... | @@ -54,7 +54,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService { |
| 54 | 54 | @Override |
| 55 | 55 | public Long createChatRoleMy(AiChatRoleSaveMyReqVO createReqVO, Long userId) { |
| 56 | 56 | // 校验文档 |
| 57 | - validateDocuments(createReqVO.getDocumentIds()); | |
| 57 | + validateDocuments(createReqVO.getKnowledgeIds()); | |
| 58 | 58 | |
| 59 | 59 | // 保存角色 |
| 60 | 60 | AiChatRoleDO chatRole = BeanUtils.toBean(createReqVO, AiChatRoleDO.class).setUserId(userId) |
| ... | ... | @@ -68,7 +68,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService { |
| 68 | 68 | // 校验存在 |
| 69 | 69 | validateChatRoleExists(updateReqVO.getId()); |
| 70 | 70 | // 校验文档 |
| 71 | - validateDocuments(updateReqVO.getDocumentIds()); | |
| 71 | + validateDocuments(updateReqVO.getKnowledgeIds()); | |
| 72 | 72 | |
| 73 | 73 | // 更新角色 |
| 74 | 74 | AiChatRoleDO updateObj = BeanUtils.toBean(updateReqVO, AiChatRoleDO.class); |
| ... | ... | @@ -83,7 +83,7 @@ public class AiChatRoleServiceImpl implements AiChatRoleService { |
| 83 | 83 | throw exception(CHAT_ROLE_NOT_EXISTS); |
| 84 | 84 | } |
| 85 | 85 | // 校验文档 |
| 86 | - validateDocuments(updateReqVO.getDocumentIds()); | |
| 86 | + validateDocuments(updateReqVO.getKnowledgeIds()); | |
| 87 | 87 | |
| 88 | 88 | // 更新 |
| 89 | 89 | AiChatRoleDO updateObj = BeanUtils.toBean(updateReqVO, AiChatRoleDO.class); |
| ... | ... | @@ -91,16 +91,16 @@ public class AiChatRoleServiceImpl implements AiChatRoleService { |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * 校验文档是否存在 | |
| 94 | + * 校验知识库是否存在 | |
| 95 | 95 | * |
| 96 | - * @param documentIds 文档编号列表 | |
| 96 | + * @param knowledgeIds 知识库编号列表 | |
| 97 | 97 | */ |
| 98 | - private void validateDocuments(List<Long> documentIds) { | |
| 99 | - if (CollUtil.isEmpty(documentIds)) { | |
| 98 | + private void validateDocuments(List<Long> knowledgeIds) { | |
| 99 | + if (CollUtil.isEmpty(knowledgeIds)) { | |
| 100 | 100 | return; |
| 101 | 101 | } |
| 102 | 102 | // 校验文档是否存在 |
| 103 | - documentIds.forEach(knowledgeDocumentService::validateKnowledgeDocumentExists); | |
| 103 | + knowledgeIds.forEach(knowledgeService::validateKnowledgeExists); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | @Override | ... | ... |