Commit cc24eca470cea786c065b327ef2e4ea1dbe06e40
1 parent
433e91da
【代码重构】AI:“聊天模型”重构为“模型”,支持 type 模型类型
Showing
4 changed files
with
40 additions
and
6 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java
| @@ -17,6 +17,7 @@ public interface ErrorCodeConstants { | @@ -17,6 +17,7 @@ public interface ErrorCodeConstants { | ||
| 17 | ErrorCode MODEL_NOT_EXISTS = new ErrorCode(1_040_001_000, "模型不存在!"); | 17 | ErrorCode MODEL_NOT_EXISTS = new ErrorCode(1_040_001_000, "模型不存在!"); |
| 18 | ErrorCode MODEL_DISABLE = new ErrorCode(1_040_001_001, "模型({})已禁用!"); | 18 | ErrorCode MODEL_DISABLE = new ErrorCode(1_040_001_001, "模型({})已禁用!"); |
| 19 | ErrorCode MODEL_DEFAULT_NOT_EXISTS = new ErrorCode(1_040_001_002, "操作失败,找不到默认模型"); | 19 | ErrorCode MODEL_DEFAULT_NOT_EXISTS = new ErrorCode(1_040_001_002, "操作失败,找不到默认模型"); |
| 20 | + ErrorCode MODEL_USE_TYPE_ERROR = new ErrorCode(1_040_001_003, "操作失败,该模型的模型类型不正确"); | ||
| 20 | 21 | ||
| 21 | // ========== API 聊天角色 1-040-002-000 ========== | 22 | // ========== API 聊天角色 1-040-002-000 ========== |
| 22 | ErrorCode CHAT_ROLE_NOT_EXISTS = new ErrorCode(1_040_002_000, "聊天角色不存在"); | 23 | ErrorCode CHAT_ROLE_NOT_EXISTS = new ErrorCode(1_040_002_000, "聊天角色不存在"); |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/segment/AiKnowledgeSegmentSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +@Schema(description = "管理后台 - AI 新增/修改知识库段落 request VO") | ||
| 8 | +@Data | ||
| 9 | +public class AiKnowledgeSegmentSaveReqVO { | ||
| 10 | + | ||
| 11 | + @Schema(description = "编号", example = "24790") | ||
| 12 | + private Long id; | ||
| 13 | + | ||
| 14 | + @Schema(description = "知识库文档编号", example = "1024") | ||
| 15 | + private Long documentId; | ||
| 16 | + | ||
| 17 | + @Schema(description = "切片内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "Java 开发手册") | ||
| 18 | + @NotEmpty(message = "切片内容不能为空") | ||
| 19 | + private String content; | ||
| 20 | + | ||
| 21 | +} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/mindmap/AiMindMapServiceImpl.java
| 1 | package cn.iocoder.yudao.module.ai.service.mindmap; | 1 | package cn.iocoder.yudao.module.ai.service.mindmap; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.lang.Assert; | 4 | +import cn.hutool.core.util.ObjUtil; |
| 5 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | import cn.iocoder.yudao.framework.ai.core.enums.AiModelTypeEnum; | 6 | import cn.iocoder.yudao.framework.ai.core.enums.AiModelTypeEnum; |
| 7 | import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; | 7 | import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; |
| @@ -38,7 +38,7 @@ import java.util.List; | @@ -38,7 +38,7 @@ import java.util.List; | ||
| 38 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 38 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 39 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; | 39 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; |
| 40 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 40 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 41 | -import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.MIND_MAP_NOT_EXISTS; | 41 | +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.*; |
| 42 | 42 | ||
| 43 | /** | 43 | /** |
| 44 | * AI 思维导图 Service 实现类 | 44 | * AI 思维导图 Service 实现类 |
| @@ -129,7 +129,13 @@ public class AiMindMapServiceImpl implements AiMindMapService { | @@ -129,7 +129,13 @@ public class AiMindMapServiceImpl implements AiMindMapService { | ||
| 129 | if (model == null) { | 129 | if (model == null) { |
| 130 | model = modalService.getRequiredDefaultModel(AiModelTypeEnum.CHAT.getType()); | 130 | model = modalService.getRequiredDefaultModel(AiModelTypeEnum.CHAT.getType()); |
| 131 | } | 131 | } |
| 132 | - Assert.notNull(model, "[AI] 获取不到模型"); | 132 | + // 校验模型存在、且合法 |
| 133 | + if (model == null) { | ||
| 134 | + throw exception(MODEL_NOT_EXISTS); | ||
| 135 | + } | ||
| 136 | + if (ObjUtil.notEqual(model.getType(), AiModelTypeEnum.CHAT.getType())) { | ||
| 137 | + throw exception(MODEL_USE_TYPE_ERROR); | ||
| 138 | + } | ||
| 133 | return model; | 139 | return model; |
| 134 | } | 140 | } |
| 135 | 141 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteServiceImpl.java
| 1 | package cn.iocoder.yudao.module.ai.service.write; | 1 | package cn.iocoder.yudao.module.ai.service.write; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.lang.Assert; | 4 | +import cn.hutool.core.util.ObjUtil; |
| 5 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | import cn.iocoder.yudao.framework.ai.core.enums.AiModelTypeEnum; | 6 | import cn.iocoder.yudao.framework.ai.core.enums.AiModelTypeEnum; |
| 7 | import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; | 7 | import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; |
| @@ -42,7 +42,7 @@ import java.util.Objects; | @@ -42,7 +42,7 @@ import java.util.Objects; | ||
| 42 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 42 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 43 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; | 43 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; |
| 44 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 44 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 45 | -import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.WRITE_NOT_EXISTS; | 45 | +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.*; |
| 46 | 46 | ||
| 47 | /** | 47 | /** |
| 48 | * AI 写作 Service 实现类 | 48 | * AI 写作 Service 实现类 |
| @@ -115,7 +115,13 @@ public class AiWriteServiceImpl implements AiWriteService { | @@ -115,7 +115,13 @@ public class AiWriteServiceImpl implements AiWriteService { | ||
| 115 | if (model == null) { | 115 | if (model == null) { |
| 116 | model = modalService.getRequiredDefaultModel(AiModelTypeEnum.CHAT.getType()); | 116 | model = modalService.getRequiredDefaultModel(AiModelTypeEnum.CHAT.getType()); |
| 117 | } | 117 | } |
| 118 | - Assert.notNull(model, "[AI] 获取不到模型"); | 118 | + // 校验模型存在、且合法 |
| 119 | + if (model == null) { | ||
| 120 | + throw exception(MODEL_NOT_EXISTS); | ||
| 121 | + } | ||
| 122 | + if (ObjUtil.notEqual(model.getType(), AiModelTypeEnum.CHAT.getType())) { | ||
| 123 | + throw exception(MODEL_USE_TYPE_ERROR); | ||
| 124 | + } | ||
| 119 | return model; | 125 | return model; |
| 120 | } | 126 | } |
| 121 | 127 |