【新增】AI:API 模型管理(完善)
This commit is contained in:
parent
ba1333bdef
commit
9fbaada1be
|
@ -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.AiApiKeyPageReqVO;
|
||||||
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyRespVO;
|
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.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.AiApiKeyDO;
|
||||||
|
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO;
|
||||||
import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService;
|
import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
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.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - AI API 密钥")
|
@Tag(name = "管理后台 - AI API 密钥")
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -69,4 +74,11 @@ public class AiApiKeyController {
|
||||||
return success(BeanUtils.toBean(pageResult, AiApiKeyRespVO.class));
|
return success(BeanUtils.toBean(pageResult, AiApiKeyRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/simple-list")
|
||||||
|
@Operation(summary = "获得 API 密钥分页列表")
|
||||||
|
public CommonResult<List<AiChatModelRespVO>> getApiKeySimpleList() {
|
||||||
|
List<AiApiKeyDO> list = apiKeyService.getApiKeyList();
|
||||||
|
return success(convertList(list, key -> new AiChatModelRespVO().setId(key.getId()).setName(key.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -17,7 +17,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - AI 聊天模型")
|
@Tag(name = "管理后台 - AI 聊天模型")
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -69,4 +73,12 @@ public class AiChatModelController {
|
||||||
return success(BeanUtils.toBean(pageResult, AiChatModelRespVO.class));
|
return success(BeanUtils.toBean(pageResult, AiChatModelRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/simple-list")
|
||||||
|
@Operation(summary = "获得聊天模型列表")
|
||||||
|
@Parameter(name = "status", description = "状态", required = true, example = "1")
|
||||||
|
public CommonResult<List<AiChatModelRespVO>> getChatModelSimpleList(@RequestParam("status") Integer status) {
|
||||||
|
List<AiChatModelDO> list = chatModelService.getChatModelList(status);
|
||||||
|
return success(convertList(list, model -> new AiChatModelRespVO().setId(model.getId()).setName(model.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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 cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API 聊天模型 Mapper
|
* API 聊天模型 Mapper
|
||||||
*
|
*
|
||||||
|
@ -39,7 +41,13 @@ public interface AiChatModelMapper extends BaseMapperX<AiChatModelDO> {
|
||||||
.likeIfPresent(AiChatModelDO::getName, reqVO.getName())
|
.likeIfPresent(AiChatModelDO::getName, reqVO.getName())
|
||||||
.eqIfPresent(AiChatModelDO::getModel, reqVO.getModel())
|
.eqIfPresent(AiChatModelDO::getModel, reqVO.getModel())
|
||||||
.eqIfPresent(AiChatModelDO::getPlatform, reqVO.getPlatform())
|
.eqIfPresent(AiChatModelDO::getPlatform, reqVO.getPlatform())
|
||||||
.orderByDesc(AiChatModelDO::getId));
|
.orderByAsc(AiChatModelDO::getSort));
|
||||||
|
}
|
||||||
|
|
||||||
|
default List<AiChatModelDO> selectList(Integer status) {
|
||||||
|
return selectList(new LambdaQueryWrapperX<AiChatModelDO>()
|
||||||
|
.eq(AiChatModelDO::getStatus, status)
|
||||||
|
.orderByAsc(AiChatModelDO::getSort));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AI API 密钥 Service 接口
|
* AI API 密钥 Service 接口
|
||||||
*
|
*
|
||||||
|
@ -59,4 +61,11 @@ public interface AiApiKeyService {
|
||||||
*/
|
*/
|
||||||
PageResult<AiApiKeyDO> getApiKeyPage(AiApiKeyPageReqVO pageReqVO);
|
PageResult<AiApiKeyDO> getApiKeyPage(AiApiKeyPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得 API 密钥列表
|
||||||
|
*
|
||||||
|
* @return API 密钥列表
|
||||||
|
*/
|
||||||
|
List<AiApiKeyDO> getApiKeyList();
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,6 +11,8 @@ import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
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.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
@ -79,4 +81,9 @@ public class AiApiKeyServiceImpl implements AiApiKeyService {
|
||||||
return apiKeyMapper.selectPage(pageReqVO);
|
return apiKeyMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AiApiKeyDO> getApiKeyList() {
|
||||||
|
return apiKeyMapper.selectList();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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 cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AI 聊天模型 Service 接口
|
* AI 聊天模型 Service 接口
|
||||||
*
|
*
|
||||||
|
@ -40,7 +42,7 @@ public interface AiChatModelService {
|
||||||
* 获得聊天模型
|
* 获得聊天模型
|
||||||
*
|
*
|
||||||
* @param id 编号
|
* @param id 编号
|
||||||
* @return API 聊天模型
|
* @return 聊天模型
|
||||||
*/
|
*/
|
||||||
AiChatModelDO getChatModel(Long id);
|
AiChatModelDO getChatModel(Long id);
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ public interface AiChatModelService {
|
||||||
* 获得聊天模型分页
|
* 获得聊天模型分页
|
||||||
*
|
*
|
||||||
* @param pageReqVO 分页查询
|
* @param pageReqVO 分页查询
|
||||||
* @return API 聊天模型分页
|
* @return 聊天模型分页
|
||||||
*/
|
*/
|
||||||
PageResult<AiChatModelDO> getChatModelPage(AiChatModelPageReqVO pageReqVO);
|
PageResult<AiChatModelDO> getChatModelPage(AiChatModelPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
@ -60,4 +62,12 @@ public interface AiChatModelService {
|
||||||
*/
|
*/
|
||||||
AiChatModelDO validateChatModel(Long id);
|
AiChatModelDO validateChatModel(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得聊天模型列表
|
||||||
|
*
|
||||||
|
* @param status 状态
|
||||||
|
* @return 聊天模型列表
|
||||||
|
*/
|
||||||
|
List<AiChatModelDO> getChatModelList(Integer status);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
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.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.ai.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
@ -89,4 +91,10 @@ public class AiChatModelServiceImpl implements AiChatModelService {
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AiChatModelDO> getChatModelList(Integer status) {
|
||||||
|
chatModelMapper.selectList(status);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@ public enum AiPlatformEnum {
|
||||||
YI_YAN("yiyan", "一言"),
|
YI_YAN("yiyan", "一言"),
|
||||||
QIAN_WEN("qianwen", "千问"),
|
QIAN_WEN("qianwen", "千问"),
|
||||||
XING_HUO("xinghuo", "星火"),
|
XING_HUO("xinghuo", "星火"),
|
||||||
OPEN_AI("openai", "openAi"), // TODO 芋艿:OpenAI
|
OPENAI("OpenAI", "OpenAI"),
|
||||||
OPEN_AI_DALL("dall", "dall"),
|
OPEN_AI_DALL("dall", "dall"),
|
||||||
MIDJOURNEY("midjourney", "midjourney"),
|
MIDJOURNEY("midjourney", "midjourney"),
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public enum AiPlatformEnum {
|
||||||
AiPlatformEnum.YI_YAN,
|
AiPlatformEnum.YI_YAN,
|
||||||
AiPlatformEnum.QIAN_WEN,
|
AiPlatformEnum.QIAN_WEN,
|
||||||
AiPlatformEnum.XING_HUO,
|
AiPlatformEnum.XING_HUO,
|
||||||
AiPlatformEnum.OPEN_AI
|
AiPlatformEnum.OPENAI
|
||||||
);
|
);
|
||||||
|
|
||||||
public static List<AiPlatformEnum> IMAGE_PLATFORM_LIST = Lists.newArrayList(
|
public static List<AiPlatformEnum> IMAGE_PLATFORM_LIST = Lists.newArrayList(
|
||||||
|
@ -42,12 +42,12 @@ public enum AiPlatformEnum {
|
||||||
);
|
);
|
||||||
|
|
||||||
public static AiPlatformEnum validatePlatform(String platform) {
|
public static AiPlatformEnum validatePlatform(String platform) {
|
||||||
for (AiPlatformEnum itemEnum : AiPlatformEnum.values()) {
|
for (AiPlatformEnum platformEnum : AiPlatformEnum.values()) {
|
||||||
if (itemEnum.getPlatform().equals(platform)) {
|
if (platformEnum.getPlatform().equals(platform)) {
|
||||||
return itemEnum;
|
return platformEnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Invalid MessageType value: " + platform);
|
throw new IllegalArgumentException("非法平台: " + platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue