模型服务
This commit is contained in:
parent
b824aeda6c
commit
403ee35f35
@ -6,4 +6,6 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode KNOWLEDGE_BASE_NOT_EXISTS = new ErrorCode(10001, "知识库不存在");
|
||||
|
||||
ErrorCode DATASET_NOT_EXISTS = new ErrorCode(10002, "数据集不存在");
|
||||
|
||||
ErrorCode MODEL_SERVICE_NOT_EXISTS = new ErrorCode(10003, "模型服务不存在");
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.llm.controller.admin.modelservice;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.llm.controller.admin.modelservice.vo.*;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.modelservice.ModelServiceDO;
|
||||
import cn.iocoder.yudao.module.llm.service.modelservice.ModelServiceService;
|
||||
|
||||
@Tag(name = "管理后台 - 模型服务")
|
||||
@RestController
|
||||
@RequestMapping("/llm/model-service")
|
||||
@Validated
|
||||
public class ModelServiceController {
|
||||
|
||||
@Resource
|
||||
private ModelServiceService modelServiceService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建模型服务")
|
||||
@PreAuthorize("@ss.hasPermission('llm:model-service:create')")
|
||||
public CommonResult<Long> createModelService(@Valid @RequestBody ModelServiceSaveReqVO createReqVO) {
|
||||
return success(modelServiceService.createModelService(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新模型服务")
|
||||
@PreAuthorize("@ss.hasPermission('llm:model-service:update')")
|
||||
public CommonResult<Boolean> updateModelService(@Valid @RequestBody ModelServiceSaveReqVO updateReqVO) {
|
||||
modelServiceService.updateModelService(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除模型服务")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('llm:model-service:delete')")
|
||||
public CommonResult<Boolean> deleteModelService(@RequestParam("id") Long id) {
|
||||
modelServiceService.deleteModelService(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得模型服务")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('llm:model-service:query')")
|
||||
public CommonResult<ModelServiceRespVO> getModelService(@RequestParam("id") Long id) {
|
||||
ModelServiceDO modelService = modelServiceService.getModelService(id);
|
||||
return success(BeanUtils.toBean(modelService, ModelServiceRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得模型服务分页")
|
||||
@PreAuthorize("@ss.hasPermission('llm:model-service:query')")
|
||||
public CommonResult<PageResult<ModelServiceRespVO>> getModelServicePage(@Valid ModelServicePageReqVO pageReqVO) {
|
||||
PageResult<ModelServiceDO> pageResult = modelServiceService.getModelServicePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ModelServiceRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出模型服务 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('llm:model-service:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportModelServiceExcel(@Valid ModelServicePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ModelServiceDO> list = modelServiceService.getModelServicePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "模型服务.xls", "数据", ModelServiceRespVO.class,
|
||||
BeanUtils.toBean(list, ModelServiceRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.llm.controller.admin.modelservice.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 模型服务分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ModelServicePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "服务名称", example = "芋艿")
|
||||
private String serviceName;
|
||||
|
||||
@Schema(description = "微调任务ID")
|
||||
private Long fineTuningTask;
|
||||
|
||||
@Schema(description = "检查点,使用字典(llm_model_checkpoint)")
|
||||
private Long checkPoint;
|
||||
|
||||
@Schema(description = "GPU,使用字典(llm_gpu_type)", example = "1")
|
||||
private Long gpuType;
|
||||
|
||||
@Schema(description = "GPU数量", example = "2")
|
||||
private Integer gpuCount;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "模型服务状态,使用字典(llm_model_status)", example = "1")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.llm.controller.admin.modelservice.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
|
||||
@Schema(description = "管理后台 - 模型服务 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class ModelServiceRespVO {
|
||||
|
||||
@Schema(description = "模型服务ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8280")
|
||||
@ExcelProperty("模型服务ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "服务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@ExcelProperty("服务名称")
|
||||
private String serviceName;
|
||||
|
||||
@Schema(description = "微调任务ID")
|
||||
@ExcelProperty("微调任务ID")
|
||||
private Long fineTuningTask;
|
||||
|
||||
@Schema(description = "检查点,使用字典(llm_model_checkpoint)")
|
||||
@ExcelProperty(value = "检查点,使用字典(llm_model_checkpoint)", converter = DictConvert.class)
|
||||
@DictFormat("llm_model_checkpoint") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Long checkPoint;
|
||||
|
||||
@Schema(description = "GPU,使用字典(llm_gpu_type)", example = "1")
|
||||
@ExcelProperty(value = "GPU,使用字典(llm_gpu_type)", converter = DictConvert.class)
|
||||
@DictFormat("llm_gpu_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Long gpuType;
|
||||
|
||||
@Schema(description = "GPU数量", example = "2")
|
||||
@ExcelProperty("GPU数量")
|
||||
private Integer gpuCount;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "模型服务状态,使用字典(llm_model_status)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "模型服务状态,使用字典(llm_model_status)", converter = DictConvert.class)
|
||||
@DictFormat("llm_model_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.llm.controller.admin.modelservice.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 模型服务新增/修改 Request VO")
|
||||
@Data
|
||||
public class ModelServiceSaveReqVO {
|
||||
|
||||
@Schema(description = "模型服务ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8280")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "服务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@NotEmpty(message = "服务名称不能为空")
|
||||
private String serviceName;
|
||||
|
||||
@Schema(description = "微调任务ID")
|
||||
private Long fineTuningTask;
|
||||
|
||||
@Schema(description = "检查点,使用字典(llm_model_checkpoint)")
|
||||
private Long checkPoint;
|
||||
|
||||
@Schema(description = "GPU,使用字典(llm_gpu_type)", example = "1")
|
||||
private Long gpuType;
|
||||
|
||||
@Schema(description = "GPU数量", example = "2")
|
||||
private Integer gpuCount;
|
||||
|
||||
@Schema(description = "模型服务状态,使用字典(llm_model_status)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "模型服务状态,使用字典(llm_model_status)不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package cn.iocoder.yudao.module.llm.dal.dataobject.modelservice;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 模型服务 DO
|
||||
*
|
||||
* @author 华大大模型
|
||||
*/
|
||||
@TableName("llm_model_service")
|
||||
@KeySequence("llm_model_service_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ModelServiceDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 模型服务ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String serviceName;
|
||||
/**
|
||||
* 微调任务ID
|
||||
*/
|
||||
private Long fineTuningTask;
|
||||
/**
|
||||
* 检查点,使用字典(llm_model_checkpoint)
|
||||
*
|
||||
* 枚举 {@link TODO llm_model_checkpoint 对应的类}
|
||||
*/
|
||||
private Long checkPoint;
|
||||
/**
|
||||
* GPU,使用字典(llm_gpu_type)
|
||||
*
|
||||
* 枚举 {@link TODO llm_gpu_type 对应的类}
|
||||
*/
|
||||
private Long gpuType;
|
||||
/**
|
||||
* GPU数量
|
||||
*/
|
||||
private Integer gpuCount;
|
||||
/**
|
||||
* 模型服务状态,使用字典(llm_model_status)
|
||||
*
|
||||
* 枚举 {@link TODO llm_model_status 对应的类}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.llm.dal.mysql.modelservice;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.modelservice.ModelServiceDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.llm.controller.admin.modelservice.vo.*;
|
||||
|
||||
/**
|
||||
* 模型服务 Mapper
|
||||
*
|
||||
* @author 华大大模型
|
||||
*/
|
||||
@Mapper
|
||||
public interface ModelServiceMapper extends BaseMapperX<ModelServiceDO> {
|
||||
|
||||
default PageResult<ModelServiceDO> selectPage(ModelServicePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ModelServiceDO>()
|
||||
.likeIfPresent(ModelServiceDO::getServiceName, reqVO.getServiceName())
|
||||
.eqIfPresent(ModelServiceDO::getFineTuningTask, reqVO.getFineTuningTask())
|
||||
.eqIfPresent(ModelServiceDO::getCheckPoint, reqVO.getCheckPoint())
|
||||
.eqIfPresent(ModelServiceDO::getGpuType, reqVO.getGpuType())
|
||||
.eqIfPresent(ModelServiceDO::getGpuCount, reqVO.getGpuCount())
|
||||
.betweenIfPresent(ModelServiceDO::getCreateTime, reqVO.getCreateTime())
|
||||
.eqIfPresent(ModelServiceDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(ModelServiceDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.llm.service.modelservice;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.llm.controller.admin.modelservice.vo.*;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.modelservice.ModelServiceDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 模型服务 Service 接口
|
||||
*
|
||||
* @author 华大大模型
|
||||
*/
|
||||
public interface ModelServiceService {
|
||||
|
||||
/**
|
||||
* 创建模型服务
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createModelService(@Valid ModelServiceSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新模型服务
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateModelService(@Valid ModelServiceSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除模型服务
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteModelService(Long id);
|
||||
|
||||
/**
|
||||
* 获得模型服务
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 模型服务
|
||||
*/
|
||||
ModelServiceDO getModelService(Long id);
|
||||
|
||||
/**
|
||||
* 获得模型服务分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 模型服务分页
|
||||
*/
|
||||
PageResult<ModelServiceDO> getModelServicePage(ModelServicePageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.llm.service.modelservice;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.llm.controller.admin.modelservice.vo.*;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.modelservice.ModelServiceDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.llm.dal.mysql.modelservice.ModelServiceMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 模型服务 Service 实现类
|
||||
*
|
||||
* @author 华大大模型
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ModelServiceServiceImpl implements ModelServiceService {
|
||||
|
||||
@Resource
|
||||
private ModelServiceMapper modelServiceMapper;
|
||||
|
||||
@Override
|
||||
public Long createModelService(ModelServiceSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ModelServiceDO modelService = BeanUtils.toBean(createReqVO, ModelServiceDO.class);
|
||||
modelServiceMapper.insert(modelService);
|
||||
// 返回
|
||||
return modelService.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateModelService(ModelServiceSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateModelServiceExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ModelServiceDO updateObj = BeanUtils.toBean(updateReqVO, ModelServiceDO.class);
|
||||
modelServiceMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteModelService(Long id) {
|
||||
// 校验存在
|
||||
validateModelServiceExists(id);
|
||||
// 删除
|
||||
modelServiceMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateModelServiceExists(Long id) {
|
||||
if (modelServiceMapper.selectById(id) == null) {
|
||||
throw exception(MODEL_SERVICE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelServiceDO getModelService(Long id) {
|
||||
return modelServiceMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ModelServiceDO> getModelServicePage(ModelServicePageReqVO pageReqVO) {
|
||||
return modelServiceMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.llm.dal.mysql.modelservice.ModelServiceMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user