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,7 +6,9 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 6 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyPageReqVO; | 6 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyPageReqVO; |
| 7 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyRespVO; | 7 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyRespVO; |
| 8 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeySaveReqVO; | 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 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; | 10 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; |
| 11 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; | ||
| 10 | import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService; | 12 | import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService; |
| 11 | import io.swagger.v3.oas.annotations.Operation; | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 12 | import io.swagger.v3.oas.annotations.Parameter; | 14 | import io.swagger.v3.oas.annotations.Parameter; |
| @@ -17,7 +19,10 @@ import org.springframework.security.access.prepost.PreAuthorize; | @@ -17,7 +19,10 @@ import org.springframework.security.access.prepost.PreAuthorize; | ||
| 17 | import org.springframework.validation.annotation.Validated; | 19 | import org.springframework.validation.annotation.Validated; |
| 18 | import org.springframework.web.bind.annotation.*; | 20 | import org.springframework.web.bind.annotation.*; |
| 19 | 21 | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 20 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 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 | @Tag(name = "管理后台 - AI API 密钥") | 27 | @Tag(name = "管理后台 - AI API 密钥") |
| 23 | @RestController | 28 | @RestController |
| @@ -69,4 +74,11 @@ public class AiApiKeyController { | @@ -69,4 +74,11 @@ public class AiApiKeyController { | ||
| 69 | return success(BeanUtils.toBean(pageResult, AiApiKeyRespVO.class)); | 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 | \ No newline at end of file | 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,7 +17,11 @@ import org.springframework.security.access.prepost.PreAuthorize; | ||
| 17 | import org.springframework.validation.annotation.Validated; | 17 | import org.springframework.validation.annotation.Validated; |
| 18 | import org.springframework.web.bind.annotation.*; | 18 | import org.springframework.web.bind.annotation.*; |
| 19 | 19 | ||
| 20 | +import java.util.List; | ||
| 21 | +import java.util.function.Function; | ||
| 22 | + | ||
| 20 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 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 | @Tag(name = "管理后台 - AI 聊天模型") | 26 | @Tag(name = "管理后台 - AI 聊天模型") |
| 23 | @RestController | 27 | @RestController |
| @@ -69,4 +73,12 @@ public class AiChatModelController { | @@ -69,4 +73,12 @@ public class AiChatModelController { | ||
| 69 | return success(BeanUtils.toBean(pageResult, AiChatModelRespVO.class)); | 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 | \ No newline at end of file | 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,6 +9,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatMode | ||
| 9 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; | 9 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 10 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 11 | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 12 | /** | 14 | /** |
| 13 | * API 聊天模型 Mapper | 15 | * API 聊天模型 Mapper |
| 14 | * | 16 | * |
| @@ -39,7 +41,13 @@ public interface AiChatModelMapper extends BaseMapperX<AiChatModelDO> { | @@ -39,7 +41,13 @@ public interface AiChatModelMapper extends BaseMapperX<AiChatModelDO> { | ||
| 39 | .likeIfPresent(AiChatModelDO::getName, reqVO.getName()) | 41 | .likeIfPresent(AiChatModelDO::getName, reqVO.getName()) |
| 40 | .eqIfPresent(AiChatModelDO::getModel, reqVO.getModel()) | 42 | .eqIfPresent(AiChatModelDO::getModel, reqVO.getModel()) |
| 41 | .eqIfPresent(AiChatModelDO::getPlatform, reqVO.getPlatform()) | 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 +6,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeySaveR | ||
| 6 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; | 6 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; |
| 7 | import jakarta.validation.Valid; | 7 | import jakarta.validation.Valid; |
| 8 | 8 | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 9 | /** | 11 | /** |
| 10 | * AI API 密钥 Service 接口 | 12 | * AI API 密钥 Service 接口 |
| 11 | * | 13 | * |
| @@ -59,4 +61,11 @@ public interface AiApiKeyService { | @@ -59,4 +61,11 @@ public interface AiApiKeyService { | ||
| 59 | */ | 61 | */ |
| 60 | PageResult<AiApiKeyDO> getApiKeyPage(AiApiKeyPageReqVO pageReqVO); | 62 | PageResult<AiApiKeyDO> getApiKeyPage(AiApiKeyPageReqVO pageReqVO); |
| 61 | 63 | ||
| 64 | + /** | ||
| 65 | + * 获得 API 密钥列表 | ||
| 66 | + * | ||
| 67 | + * @return API 密钥列表 | ||
| 68 | + */ | ||
| 69 | + List<AiApiKeyDO> getApiKeyList(); | ||
| 70 | + | ||
| 62 | } | 71 | } |
| 63 | \ No newline at end of file | 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,6 +11,8 @@ import jakarta.annotation.Resource; | ||
| 11 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 12 | import org.springframework.validation.annotation.Validated; | 12 | import org.springframework.validation.annotation.Validated; |
| 13 | 13 | ||
| 14 | +import java.util.List; | ||
| 15 | + | ||
| 14 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 16 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 15 | import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*; | 17 | import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*; |
| 16 | 18 | ||
| @@ -79,4 +81,9 @@ public class AiApiKeyServiceImpl implements AiApiKeyService { | @@ -79,4 +81,9 @@ public class AiApiKeyServiceImpl implements AiApiKeyService { | ||
| 79 | return apiKeyMapper.selectPage(pageReqVO); | 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 | \ No newline at end of file | 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 +6,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatMode | ||
| 6 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; | 6 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 7 | import jakarta.validation.Valid; | 7 | import jakarta.validation.Valid; |
| 8 | 8 | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 9 | /** | 11 | /** |
| 10 | * AI 聊天模型 Service 接口 | 12 | * AI 聊天模型 Service 接口 |
| 11 | * | 13 | * |
| @@ -40,7 +42,7 @@ public interface AiChatModelService { | @@ -40,7 +42,7 @@ public interface AiChatModelService { | ||
| 40 | * 获得聊天模型 | 42 | * 获得聊天模型 |
| 41 | * | 43 | * |
| 42 | * @param id 编号 | 44 | * @param id 编号 |
| 43 | - * @return API 聊天模型 | 45 | + * @return 聊天模型 |
| 44 | */ | 46 | */ |
| 45 | AiChatModelDO getChatModel(Long id); | 47 | AiChatModelDO getChatModel(Long id); |
| 46 | 48 | ||
| @@ -48,7 +50,7 @@ public interface AiChatModelService { | @@ -48,7 +50,7 @@ public interface AiChatModelService { | ||
| 48 | * 获得聊天模型分页 | 50 | * 获得聊天模型分页 |
| 49 | * | 51 | * |
| 50 | * @param pageReqVO 分页查询 | 52 | * @param pageReqVO 分页查询 |
| 51 | - * @return API 聊天模型分页 | 53 | + * @return 聊天模型分页 |
| 52 | */ | 54 | */ |
| 53 | PageResult<AiChatModelDO> getChatModelPage(AiChatModelPageReqVO pageReqVO); | 55 | PageResult<AiChatModelDO> getChatModelPage(AiChatModelPageReqVO pageReqVO); |
| 54 | 56 | ||
| @@ -60,4 +62,12 @@ public interface AiChatModelService { | @@ -60,4 +62,12 @@ public interface AiChatModelService { | ||
| 60 | */ | 62 | */ |
| 61 | AiChatModelDO validateChatModel(Long id); | 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,6 +12,8 @@ import jakarta.annotation.Resource; | ||
| 12 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 13 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 14 | 14 | ||
| 15 | +import java.util.List; | ||
| 16 | + | ||
| 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 16 | import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*; | 18 | import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*; |
| 17 | 19 | ||
| @@ -89,4 +91,10 @@ public class AiChatModelServiceImpl implements AiChatModelService { | @@ -89,4 +91,10 @@ public class AiChatModelServiceImpl implements AiChatModelService { | ||
| 89 | return model; | 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 | \ No newline at end of file | 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,7 +20,7 @@ public enum AiPlatformEnum { | ||
| 20 | YI_YAN("yiyan", "一言"), | 20 | YI_YAN("yiyan", "一言"), |
| 21 | QIAN_WEN("qianwen", "千问"), | 21 | QIAN_WEN("qianwen", "千问"), |
| 22 | XING_HUO("xinghuo", "星火"), | 22 | XING_HUO("xinghuo", "星火"), |
| 23 | - OPEN_AI("openai", "openAi"), // TODO 芋艿:OpenAI | 23 | + OPENAI("OpenAI", "OpenAI"), |
| 24 | OPEN_AI_DALL("dall", "dall"), | 24 | OPEN_AI_DALL("dall", "dall"), |
| 25 | MIDJOURNEY("midjourney", "midjourney"), | 25 | MIDJOURNEY("midjourney", "midjourney"), |
| 26 | 26 | ||
| @@ -33,7 +33,7 @@ public enum AiPlatformEnum { | @@ -33,7 +33,7 @@ public enum AiPlatformEnum { | ||
| 33 | AiPlatformEnum.YI_YAN, | 33 | AiPlatformEnum.YI_YAN, |
| 34 | AiPlatformEnum.QIAN_WEN, | 34 | AiPlatformEnum.QIAN_WEN, |
| 35 | AiPlatformEnum.XING_HUO, | 35 | AiPlatformEnum.XING_HUO, |
| 36 | - AiPlatformEnum.OPEN_AI | 36 | + AiPlatformEnum.OPENAI |
| 37 | ); | 37 | ); |
| 38 | 38 | ||
| 39 | public static List<AiPlatformEnum> IMAGE_PLATFORM_LIST = Lists.newArrayList( | 39 | public static List<AiPlatformEnum> IMAGE_PLATFORM_LIST = Lists.newArrayList( |
| @@ -42,12 +42,12 @@ public enum AiPlatformEnum { | @@ -42,12 +42,12 @@ public enum AiPlatformEnum { | ||
| 42 | ); | 42 | ); |
| 43 | 43 | ||
| 44 | public static AiPlatformEnum validatePlatform(String platform) { | 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 | } |