Commit 9fbaada1be2cc0f9045731a29e156465acd63d24
1 parent
ba1333bd
【新增】AI:API 模型管理(完善)
Showing
8 changed files
with
75 additions
and
9 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiApiKeyController.java
| ... | ... | @@ -6,7 +6,9 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 6 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyPageReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyRespVO; |
| 8 | 8 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeySaveReqVO; |
| 9 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatModelRespVO; | |
| 9 | 10 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; |
| 11 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; | |
| 10 | 12 | import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService; |
| 11 | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 12 | 14 | import io.swagger.v3.oas.annotations.Parameter; |
| ... | ... | @@ -17,7 +19,10 @@ import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | 19 | import org.springframework.validation.annotation.Validated; |
| 18 | 20 | import org.springframework.web.bind.annotation.*; |
| 19 | 21 | |
| 22 | +import java.util.List; | |
| 23 | + | |
| 20 | 24 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 25 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 21 | 26 | |
| 22 | 27 | @Tag(name = "管理后台 - AI API 密钥") |
| 23 | 28 | @RestController |
| ... | ... | @@ -69,4 +74,11 @@ public class AiApiKeyController { |
| 69 | 74 | return success(BeanUtils.toBean(pageResult, AiApiKeyRespVO.class)); |
| 70 | 75 | } |
| 71 | 76 | |
| 77 | + @GetMapping("/simple-list") | |
| 78 | + @Operation(summary = "获得 API 密钥分页列表") | |
| 79 | + public CommonResult<List<AiChatModelRespVO>> getApiKeySimpleList() { | |
| 80 | + List<AiApiKeyDO> list = apiKeyService.getApiKeyList(); | |
| 81 | + return success(convertList(list, key -> new AiChatModelRespVO().setId(key.getId()).setName(key.getName()))); | |
| 82 | + } | |
| 83 | + | |
| 72 | 84 | } |
| 73 | 85 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiChatModelController.java
| ... | ... | @@ -17,7 +17,11 @@ import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | 17 | import org.springframework.validation.annotation.Validated; |
| 18 | 18 | import org.springframework.web.bind.annotation.*; |
| 19 | 19 | |
| 20 | +import java.util.List; | |
| 21 | +import java.util.function.Function; | |
| 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 | @Tag(name = "管理后台 - AI 聊天模型") |
| 23 | 27 | @RestController |
| ... | ... | @@ -69,4 +73,12 @@ public class AiChatModelController { |
| 69 | 73 | return success(BeanUtils.toBean(pageResult, AiChatModelRespVO.class)); |
| 70 | 74 | } |
| 71 | 75 | |
| 76 | + @GetMapping("/simple-list") | |
| 77 | + @Operation(summary = "获得聊天模型列表") | |
| 78 | + @Parameter(name = "status", description = "状态", required = true, example = "1") | |
| 79 | + public CommonResult<List<AiChatModelRespVO>> getChatModelSimpleList(@RequestParam("status") Integer status) { | |
| 80 | + List<AiChatModelDO> list = chatModelService.getChatModelList(status); | |
| 81 | + return success(convertList(list, model -> new AiChatModelRespVO().setId(model.getId()).setName(model.getName()))); | |
| 82 | + } | |
| 83 | + | |
| 72 | 84 | } |
| 73 | 85 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java
| ... | ... | @@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatMode |
| 9 | 9 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 10 | 10 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 11 | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 12 | 14 | /** |
| 13 | 15 | * API 聊天模型 Mapper |
| 14 | 16 | * |
| ... | ... | @@ -39,7 +41,13 @@ public interface AiChatModelMapper extends BaseMapperX<AiChatModelDO> { |
| 39 | 41 | .likeIfPresent(AiChatModelDO::getName, reqVO.getName()) |
| 40 | 42 | .eqIfPresent(AiChatModelDO::getModel, reqVO.getModel()) |
| 41 | 43 | .eqIfPresent(AiChatModelDO::getPlatform, reqVO.getPlatform()) |
| 42 | - .orderByDesc(AiChatModelDO::getId)); | |
| 44 | + .orderByAsc(AiChatModelDO::getSort)); | |
| 45 | + } | |
| 46 | + | |
| 47 | + default List<AiChatModelDO> selectList(Integer status) { | |
| 48 | + return selectList(new LambdaQueryWrapperX<AiChatModelDO>() | |
| 49 | + .eq(AiChatModelDO::getStatus, status) | |
| 50 | + .orderByAsc(AiChatModelDO::getSort)); | |
| 43 | 51 | } |
| 44 | 52 | |
| 45 | 53 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyService.java
| ... | ... | @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeySaveR |
| 6 | 6 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | 8 | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 9 | 11 | /** |
| 10 | 12 | * AI API 密钥 Service 接口 |
| 11 | 13 | * |
| ... | ... | @@ -59,4 +61,11 @@ public interface AiApiKeyService { |
| 59 | 61 | */ |
| 60 | 62 | PageResult<AiApiKeyDO> getApiKeyPage(AiApiKeyPageReqVO pageReqVO); |
| 61 | 63 | |
| 64 | + /** | |
| 65 | + * 获得 API 密钥列表 | |
| 66 | + * | |
| 67 | + * @return API 密钥列表 | |
| 68 | + */ | |
| 69 | + List<AiApiKeyDO> getApiKeyList(); | |
| 70 | + | |
| 62 | 71 | } |
| 63 | 72 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyServiceImpl.java
| ... | ... | @@ -11,6 +11,8 @@ import jakarta.annotation.Resource; |
| 11 | 11 | import org.springframework.stereotype.Service; |
| 12 | 12 | import org.springframework.validation.annotation.Validated; |
| 13 | 13 | |
| 14 | +import java.util.List; | |
| 15 | + | |
| 14 | 16 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 15 | 17 | import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*; |
| 16 | 18 | |
| ... | ... | @@ -79,4 +81,9 @@ public class AiApiKeyServiceImpl implements AiApiKeyService { |
| 79 | 81 | return apiKeyMapper.selectPage(pageReqVO); |
| 80 | 82 | } |
| 81 | 83 | |
| 84 | + @Override | |
| 85 | + public List<AiApiKeyDO> getApiKeyList() { | |
| 86 | + return apiKeyMapper.selectList(); | |
| 87 | + } | |
| 88 | + | |
| 82 | 89 | } |
| 83 | 90 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelService.java
| ... | ... | @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatMode |
| 6 | 6 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | 8 | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 9 | 11 | /** |
| 10 | 12 | * AI 聊天模型 Service 接口 |
| 11 | 13 | * |
| ... | ... | @@ -40,7 +42,7 @@ public interface AiChatModelService { |
| 40 | 42 | * 获得聊天模型 |
| 41 | 43 | * |
| 42 | 44 | * @param id 编号 |
| 43 | - * @return API 聊天模型 | |
| 45 | + * @return 聊天模型 | |
| 44 | 46 | */ |
| 45 | 47 | AiChatModelDO getChatModel(Long id); |
| 46 | 48 | |
| ... | ... | @@ -48,7 +50,7 @@ public interface AiChatModelService { |
| 48 | 50 | * 获得聊天模型分页 |
| 49 | 51 | * |
| 50 | 52 | * @param pageReqVO 分页查询 |
| 51 | - * @return API 聊天模型分页 | |
| 53 | + * @return 聊天模型分页 | |
| 52 | 54 | */ |
| 53 | 55 | PageResult<AiChatModelDO> getChatModelPage(AiChatModelPageReqVO pageReqVO); |
| 54 | 56 | |
| ... | ... | @@ -60,4 +62,12 @@ public interface AiChatModelService { |
| 60 | 62 | */ |
| 61 | 63 | AiChatModelDO validateChatModel(Long id); |
| 62 | 64 | |
| 65 | + /** | |
| 66 | + * 获得聊天模型列表 | |
| 67 | + * | |
| 68 | + * @param status 状态 | |
| 69 | + * @return 聊天模型列表 | |
| 70 | + */ | |
| 71 | + List<AiChatModelDO> getChatModelList(Integer status); | |
| 72 | + | |
| 63 | 73 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelServiceImpl.java
| ... | ... | @@ -12,6 +12,8 @@ import jakarta.annotation.Resource; |
| 12 | 12 | import org.springframework.stereotype.Service; |
| 13 | 13 | import org.springframework.validation.annotation.Validated; |
| 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.ErrorCodeConstants.*; |
| 17 | 19 | |
| ... | ... | @@ -89,4 +91,10 @@ public class AiChatModelServiceImpl implements AiChatModelService { |
| 89 | 91 | return model; |
| 90 | 92 | } |
| 91 | 93 | |
| 94 | + @Override | |
| 95 | + public List<AiChatModelDO> getChatModelList(Integer status) { | |
| 96 | + chatModelMapper.selectList(status); | |
| 97 | + return null; | |
| 98 | + } | |
| 99 | + | |
| 92 | 100 | } |
| 93 | 101 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/AiPlatformEnum.java
| ... | ... | @@ -20,7 +20,7 @@ public enum AiPlatformEnum { |
| 20 | 20 | YI_YAN("yiyan", "一言"), |
| 21 | 21 | QIAN_WEN("qianwen", "千问"), |
| 22 | 22 | XING_HUO("xinghuo", "星火"), |
| 23 | - OPEN_AI("openai", "openAi"), // TODO 芋艿:OpenAI | |
| 23 | + OPENAI("OpenAI", "OpenAI"), | |
| 24 | 24 | OPEN_AI_DALL("dall", "dall"), |
| 25 | 25 | MIDJOURNEY("midjourney", "midjourney"), |
| 26 | 26 | |
| ... | ... | @@ -33,7 +33,7 @@ public enum AiPlatformEnum { |
| 33 | 33 | AiPlatformEnum.YI_YAN, |
| 34 | 34 | AiPlatformEnum.QIAN_WEN, |
| 35 | 35 | AiPlatformEnum.XING_HUO, |
| 36 | - AiPlatformEnum.OPEN_AI | |
| 36 | + AiPlatformEnum.OPENAI | |
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | 39 | public static List<AiPlatformEnum> IMAGE_PLATFORM_LIST = Lists.newArrayList( |
| ... | ... | @@ -42,12 +42,12 @@ public enum AiPlatformEnum { |
| 42 | 42 | ); |
| 43 | 43 | |
| 44 | 44 | public static AiPlatformEnum validatePlatform(String platform) { |
| 45 | - for (AiPlatformEnum itemEnum : AiPlatformEnum.values()) { | |
| 46 | - if (itemEnum.getPlatform().equals(platform)) { | |
| 47 | - return itemEnum; | |
| 45 | + for (AiPlatformEnum platformEnum : AiPlatformEnum.values()) { | |
| 46 | + if (platformEnum.getPlatform().equals(platform)) { | |
| 47 | + return platformEnum; | |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | - throw new IllegalArgumentException("Invalid MessageType value: " + platform); | |
| 50 | + throw new IllegalArgumentException("非法平台: " + platform); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | } | ... | ... |