Commit 56c6e197 authored by pengxin's avatar pengxin

模型部署服务新增接口。

parent 68d7baf3
...@@ -10,4 +10,18 @@ public class ModelConstant { ...@@ -10,4 +10,18 @@ public class ModelConstant {
*/ */
public static final Integer DEPLOY_STATUS = 3; public static final Integer DEPLOY_STATUS = 3;
/**
* 部署状态:成功
*/
public static final Integer DEPLOY_STATUS_COMPLETE = 1;
/**
* 部署状态:部署中
*/
public static final Integer DEPLOY_STATUS_DEPLOYED = 0;
/**
* 部署状态:失败
*/
public static final Integer DEPLOY_STATUS_FAILURE = -1;
} }
...@@ -166,7 +166,6 @@ public class ModelDeployController { ...@@ -166,7 +166,6 @@ public class ModelDeployController {
ModelDeploy modelDeploy = MyModelUtil.copyTo(modelDeployDto, ModelDeploy.class); ModelDeploy modelDeploy = MyModelUtil.copyTo(modelDeployDto, ModelDeploy.class);
ModelDeploy originalModelDeploy = modelDeployService.getById(modelDeploy.getDeployId()); ModelDeploy originalModelDeploy = modelDeployService.getById(modelDeploy.getDeployId());
if (originalModelDeploy == null) { if (originalModelDeploy == null) {
// NOTE: 修改下面方括号中的话述
errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!"; errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage); return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
} }
......
...@@ -12,10 +12,15 @@ import com.yice.common.core.util.MyModelUtil; ...@@ -12,10 +12,15 @@ import com.yice.common.core.util.MyModelUtil;
import com.yice.common.core.util.MyPageUtil; import com.yice.common.core.util.MyPageUtil;
import com.yice.common.log.annotation.OperationLog; import com.yice.common.log.annotation.OperationLog;
import com.yice.common.log.model.constant.SysOperationLogType; import com.yice.common.log.model.constant.SysOperationLogType;
import com.yice.webadmin.app.config.LlmModelConfig;
import com.yice.webadmin.app.config.OtherConfig; import com.yice.webadmin.app.config.OtherConfig;
import com.yice.webadmin.app.config.PythonConfig;
import com.yice.webadmin.app.constant.ModelConstant;
import com.yice.webadmin.app.dto.ModelInstanceDto; import com.yice.webadmin.app.dto.ModelInstanceDto;
import com.yice.webadmin.app.model.ModelInstance; import com.yice.webadmin.app.model.ModelInstance;
import com.yice.webadmin.app.model.ModelVersion;
import com.yice.webadmin.app.service.ModelInstanceService; import com.yice.webadmin.app.service.ModelInstanceService;
import com.yice.webadmin.app.service.ModelVersionService;
import com.yice.webadmin.app.service.ProxyPythonService; import com.yice.webadmin.app.service.ProxyPythonService;
import com.yice.webadmin.app.vo.ModelInstanceVo; import com.yice.webadmin.app.vo.ModelInstanceVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -25,6 +30,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -25,6 +30,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 模型实例管理操作控制器类。 * 模型实例管理操作控制器类。
...@@ -44,13 +50,20 @@ public class ModelInstanceController { ...@@ -44,13 +50,20 @@ public class ModelInstanceController {
private ProxyPythonService proxyPythonService; private ProxyPythonService proxyPythonService;
@Autowired @Autowired
private OtherConfig otherConfig; private OtherConfig otherConfig;
@Autowired
private LlmModelConfig llmModelConfig;
@Autowired
private PythonConfig pythonConfig;
@Autowired
private ModelVersionService modelVersionService;
/** /**
* 新增知识图谱管理数据。 * 新增知识图谱管理数据。
* *
* @param modelInstanceDto 新增对象。 * @param modelInstanceDto 新增对象。
* @return 应答结果对象,包含新增对象主键Id。 * @return 应答结果对象,包含新增对象主键Id。
*/ */
@ApiOperationSupport(ignoreParameters = {"modelInstanceDto.deployId"}) @ApiOperationSupport(ignoreParameters = {"modelInstanceDto.instanceId"})
@OperationLog(type = SysOperationLogType.ADD) @OperationLog(type = SysOperationLogType.ADD)
@PostMapping("/add") @PostMapping("/add")
public ResponseResult<Long> add(@MyRequestBody ModelInstanceDto modelInstanceDto) { public ResponseResult<Long> add(@MyRequestBody ModelInstanceDto modelInstanceDto) {
...@@ -73,6 +86,113 @@ public class ModelInstanceController { ...@@ -73,6 +86,113 @@ public class ModelInstanceController {
return ResponseResult.success(modelInstance.getInstanceId()); return ResponseResult.success(modelInstance.getInstanceId());
} }
/**
* 停止指定LLM模型。
*
* @return 应答结果对象,包含查询结果集。
*/
@PostMapping("/stop")
public ResponseResult<String> stop(@MyRequestBody ModelInstanceDto modelInstanceDto) {
ModelInstance modelInstance = modelInstanceService.getById(modelInstanceDto.getInstanceId());
ResponseResult<String> responseResult = this.doStop(modelInstance);
if (responseResult.isSuccess()) {
modelInstance.setDeployStatus(3);
modelInstanceService.updateById(modelInstance);
return ResponseResult.success(responseResult.getData());
}
return responseResult;
}
/**
* 部署指定LLM模型。
*
* @return 应答结果对象,包含查询结果集。
*/
@PostMapping("/deploy")
public ResponseResult<String> deploy(@MyRequestBody ModelInstanceDto modelInstanceDto,
@MyRequestBody String type) {
ModelInstance modelInstance = modelInstanceService.getById(modelInstanceDto.getInstanceId());
modelInstance.setDeployStatus(ModelConstant.DEPLOY_STATUS_DEPLOYED);
modelInstanceService.updateById(modelInstance);
ResponseResult<String> responseResult = this.doReloadOrStart(modelInstance, type);
if (responseResult.isSuccess()) {
modelInstance.setDeployStatus(ModelConstant.DEPLOY_STATUS_COMPLETE);
modelInstanceService.updateById(modelInstance);
return ResponseResult.success(responseResult.getData());
}
modelInstance.setDeployStatus(ModelConstant.DEPLOY_STATUS_FAILURE);
modelInstanceService.updateById(modelInstance);
return responseResult;
}
/**
* 调用Python模型方法
* @param modelInstance 模型实例
* @param type 类型
* @return 消息
*/
private ResponseResult<String> doReloadOrStart(ModelInstance modelInstance, String type) {
String gps_ids = JSON.parseArray(modelInstance.getResourceInfo()).stream()
.map(obj -> ((JSONObject) obj).getString("gpu_id"))
.collect(Collectors.joining(","));
ModelVersion modelVersion = this.modelVersionService.getById(modelInstance.getVersionId());
String requestBody = "{\n" +
" \"new_model_name\": \"" + modelInstance.getVersionName() + "\",\n" +
" \"new_model_path\": \"" + modelVersion.getModelUrl() + "\",\n" +
" \"startup_param\": {\n" +
" \"gpu_ids\": \"" + gps_ids + "\"\n" +
" },\n" +
" \"controller_address\": \"" + pythonConfig.getControllerAddress() + "\"\n" +
"}";
try {
String apiName = type.equals("start") ? llmModelConfig.getStart() : llmModelConfig.getReload();
String result = proxyPythonService.predictPost(llmModelConfig.getLlmModelInterface() + apiName, requestBody);
JSONObject jo = JSON.parseObject(result);
Integer code = jo.getIntValue("code");
String msg = jo.getString("msg");
String data = jo.getString("data");
if (code != null && code == 200) {
return ResponseResult.success(data);
} else {
return ResponseResult.create(ErrorCodeEnum.SERVER_INTERNAL_ERROR, msg, data);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* 模型停止,调用python接口
* @param modelInstance 模型实例
* @return 消息
*/
private ResponseResult<String> doStop(ModelInstance modelInstance) {
String errorMessage = MyCommonUtil.getModelValidationError(modelInstance, true);
if (errorMessage != null) {
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
}
String requestBody = "{\n" +
" \"model_name\": \"" + modelInstance.getVersionName() + "\",\n" +
" \"controller_address\": \"" + pythonConfig.getControllerAddress() + "\"\n" +
"}";
try {
String result = proxyPythonService.predictPost(llmModelConfig.getLlmModelInterface() + llmModelConfig.getStop(), requestBody);
JSONObject jo = JSON.parseObject(result);
Integer code = jo.getIntValue("code");
String msg = jo.getString("msg");
String data = jo.getString("data");
if (code != null && code == 200) {
return ResponseResult.success(data);
} else {
return ResponseResult.create(ErrorCodeEnum.SERVER_INTERNAL_ERROR, msg, data);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/** /**
* 获取GPU信息。 * 获取GPU信息。
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment