| | |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiModelImportExcelVO; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiModelImportReqVO; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiModelImportRespVO; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiModelPageReqVO; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiModelRespVO; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiModelSaveReqVO; |
| | |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import jakarta.validation.Valid; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获取 AI 模型") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('ai:model:query')") |
| | | public CommonResult<AiModelRespVO> getModel(@RequestParam("id") Long id) { |
| | | return success(BeanUtils.toBean(modelService.getModel(id), AiModelRespVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获取 AI 模型分页") |
| | | @PreAuthorize("@ss.hasPermission('ai:model:query')") |
| | | public CommonResult<PageResult<AiModelRespVO>> getModelPage(@Valid AiModelPageReqVO pageReqVO) { |
| | | PageResult<AiModelDO> pageResult = modelService.getModelPage(pageReqVO); |
| | | return success(BeanUtils.toBean(pageResult, AiModelRespVO.class)); |
| | |
| | | .setPlatform(model.getPlatform()))); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得导入模型模板") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 手动创建导出 demo |
| | | List<AiModelImportExcelVO> list = Arrays.asList( |
| | | AiModelImportExcelVO.builder().name("示例模型").keyName("示例密钥").model("qwen-plus") |
| | | .platform("TongYi").type(1).sort(0).status(0) |
| | | .temperature(0.7).maxTokens(4096).maxContexts(10).build() |
| | | ); |
| | | // 输出 |
| | | ExcelUtils.write(response, "模型配置导入模板.xls", "模型配置列表", AiModelImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导入模型") |
| | | @PreAuthorize("@ss.hasPermission('ai:model:import')") |
| | | public CommonResult<AiModelImportRespVO> importExcel(@Valid AiModelImportReqVO importReqVO) |
| | | throws Exception { |
| | | List<AiModelImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), AiModelImportExcelVO.class); |
| | | return success(modelService.importModelList(list, importReqVO)); |
| | | } |
| | | |
| | | } |