From 9fbaada1be2cc0f9045731a29e156465acd63d24 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 11 May 2024 19:46:49 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91AI=EF=BC=9A?= =?UTF-8?q?API=20=E6=A8=A1=E5=9E=8B=E7=AE=A1=E7=90=86=EF=BC=88=E5=AE=8C?= =?UTF-8?q?=E5=96=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/model/AiApiKeyController.java | 12 ++++++++++++ .../admin/model/AiChatModelController.java | 12 ++++++++++++ .../module/ai/dal/mysql/AiChatModelMapper.java | 10 +++++++++- .../module/ai/service/model/AiApiKeyService.java | 9 +++++++++ .../ai/service/model/AiApiKeyServiceImpl.java | 7 +++++++ .../ai/service/model/AiChatModelService.java | 14 ++++++++++++-- .../ai/service/model/AiChatModelServiceImpl.java | 8 ++++++++ .../iocoder/yudao/framework/ai/AiPlatformEnum.java | 12 ++++++------ 8 files changed, 75 insertions(+), 9 deletions(-) diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiApiKeyController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiApiKeyController.java index 78b5886471..2bc190051d 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiApiKeyController.java +++ b/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; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyPageReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyRespVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeySaveReqVO; +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatModel.AiChatModelRespVO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -17,7 +19,10 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.List; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @Tag(name = "管理后台 - AI API 密钥") @RestController @@ -69,4 +74,11 @@ public class AiApiKeyController { return success(BeanUtils.toBean(pageResult, AiApiKeyRespVO.class)); } + @GetMapping("/simple-list") + @Operation(summary = "获得 API 密钥分页列表") + public CommonResult> getApiKeySimpleList() { + List list = apiKeyService.getApiKeyList(); + return success(convertList(list, key -> new AiChatModelRespVO().setId(key.getId()).setName(key.getName()))); + } + } \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiChatModelController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiChatModelController.java index 7d73e222a5..6d568140b9 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiChatModelController.java +++ b/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; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.List; +import java.util.function.Function; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @Tag(name = "管理后台 - AI 聊天模型") @RestController @@ -69,4 +73,12 @@ public class AiChatModelController { return success(BeanUtils.toBean(pageResult, AiChatModelRespVO.class)); } + @GetMapping("/simple-list") + @Operation(summary = "获得聊天模型列表") + @Parameter(name = "status", description = "状态", required = true, example = "1") + public CommonResult> getChatModelSimpleList(@RequestParam("status") Integer status) { + List list = chatModelService.getChatModelList(status); + return success(convertList(list, model -> new AiChatModelRespVO().setId(model.getId()).setName(model.getName()))); + } + } \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java index c2d75a2182..289730f936 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatModelMapper.java +++ b/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 import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * API 聊天模型 Mapper * @@ -39,7 +41,13 @@ public interface AiChatModelMapper extends BaseMapperX { .likeIfPresent(AiChatModelDO::getName, reqVO.getName()) .eqIfPresent(AiChatModelDO::getModel, reqVO.getModel()) .eqIfPresent(AiChatModelDO::getPlatform, reqVO.getPlatform()) - .orderByDesc(AiChatModelDO::getId)); + .orderByAsc(AiChatModelDO::getSort)); + } + + default List selectList(Integer status) { + return selectList(new LambdaQueryWrapperX() + .eq(AiChatModelDO::getStatus, status) + .orderByAsc(AiChatModelDO::getSort)); } } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyService.java index 4da3c3500e..331dd62e2b 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyService.java +++ b/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 import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; import jakarta.validation.Valid; +import java.util.List; + /** * AI API 密钥 Service 接口 * @@ -59,4 +61,11 @@ public interface AiApiKeyService { */ PageResult getApiKeyPage(AiApiKeyPageReqVO pageReqVO); + /** + * 获得 API 密钥列表 + * + * @return API 密钥列表 + */ + List getApiKeyList(); + } \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyServiceImpl.java index 06e68748f5..f8a83ce57c 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyServiceImpl.java +++ b/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; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import java.util.List; + import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*; @@ -79,4 +81,9 @@ public class AiApiKeyServiceImpl implements AiApiKeyService { return apiKeyMapper.selectPage(pageReqVO); } + @Override + public List getApiKeyList() { + return apiKeyMapper.selectList(); + } + } \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelService.java index d05941989a..72d2233e54 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelService.java +++ b/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 import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; import jakarta.validation.Valid; +import java.util.List; + /** * AI 聊天模型 Service 接口 * @@ -40,7 +42,7 @@ public interface AiChatModelService { * 获得聊天模型 * * @param id 编号 - * @return API 聊天模型 + * @return 聊天模型 */ AiChatModelDO getChatModel(Long id); @@ -48,7 +50,7 @@ public interface AiChatModelService { * 获得聊天模型分页 * * @param pageReqVO 分页查询 - * @return API 聊天模型分页 + * @return 聊天模型分页 */ PageResult getChatModelPage(AiChatModelPageReqVO pageReqVO); @@ -60,4 +62,12 @@ public interface AiChatModelService { */ AiChatModelDO validateChatModel(Long id); + /** + * 获得聊天模型列表 + * + * @param status 状态 + * @return 聊天模型列表 + */ + List getChatModelList(Integer status); + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelServiceImpl.java index 0c0386cccc..47c3cad577 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiChatModelServiceImpl.java +++ b/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; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import java.util.List; + import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*; @@ -89,4 +91,10 @@ public class AiChatModelServiceImpl implements AiChatModelService { return model; } + @Override + public List getChatModelList(Integer status) { + chatModelMapper.selectList(status); + return null; + } + } \ No newline at end of file diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/AiPlatformEnum.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/AiPlatformEnum.java index c774d25153..3882e1a995 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/AiPlatformEnum.java +++ b/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 { YI_YAN("yiyan", "一言"), QIAN_WEN("qianwen", "千问"), XING_HUO("xinghuo", "星火"), - OPEN_AI("openai", "openAi"), // TODO 芋艿:OpenAI + OPENAI("OpenAI", "OpenAI"), OPEN_AI_DALL("dall", "dall"), MIDJOURNEY("midjourney", "midjourney"), @@ -33,7 +33,7 @@ public enum AiPlatformEnum { AiPlatformEnum.YI_YAN, AiPlatformEnum.QIAN_WEN, AiPlatformEnum.XING_HUO, - AiPlatformEnum.OPEN_AI + AiPlatformEnum.OPENAI ); public static List IMAGE_PLATFORM_LIST = Lists.newArrayList( @@ -42,12 +42,12 @@ public enum AiPlatformEnum { ); public static AiPlatformEnum validatePlatform(String platform) { - for (AiPlatformEnum itemEnum : AiPlatformEnum.values()) { - if (itemEnum.getPlatform().equals(platform)) { - return itemEnum; + for (AiPlatformEnum platformEnum : AiPlatformEnum.values()) { + if (platformEnum.getPlatform().equals(platform)) { + return platformEnum; } } - throw new IllegalArgumentException("Invalid MessageType value: " + platform); + throw new IllegalArgumentException("非法平台: " + platform); } }