Commit bc070476 authored by linpeiqin's avatar linpeiqin

增加运行状态信息

parent 3c155aac
...@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON; ...@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.github.pagehelper.page.PageMethod; import com.github.pagehelper.page.PageMethod;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yice.common.core.annotation.MyRequestBody; import com.yice.common.core.annotation.MyRequestBody;
...@@ -33,12 +32,9 @@ import org.springframework.web.bind.annotation.*; ...@@ -33,12 +32,9 @@ import org.springframework.web.bind.annotation.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -170,7 +166,7 @@ public class TuningRunController { ...@@ -170,7 +166,7 @@ public class TuningRunController {
array.add(true); array.add(true);
array.add(jsonObject.get("dpoBetaData")); array.add(jsonObject.get("dpoBetaData"));
array.add(new JSONArray()); array.add(new JSONArray());
array.add("train_"+runId); array.add("train_" + runId);
System.out.println(array.toJSONString()); System.out.println(array.toJSONString());
return ResponseResult.success(array.toJSONString()); return ResponseResult.success(array.toJSONString());
} }
...@@ -244,6 +240,26 @@ public class TuningRunController { ...@@ -244,6 +240,26 @@ public class TuningRunController {
return ResponseResult.success(TuningRun.INSTANCE.fromModelList(tuningRunList)); return ResponseResult.success(TuningRun.INSTANCE.fromModelList(tuningRunList));
} }
/**
* 提交运行状态信息。
*
* @return 应答结果对象,包含查询结果集。
*/
@PostMapping("/postRunStatus")
public ResponseResult<Void> postRunStatus(@MyRequestBody Long runId,
@MyRequestBody Long runTime,
@MyRequestBody Integer runStatus) {
TuningRun tuningRun = this.tuningRunService.getById(runId);
tuningRun.setRunStatus(runStatus);
tuningRun.setRunTime(runTime);
String errorMessage;
if (!tuningRunService.updateById(tuningRun)) {
errorMessage = "运行状态信息提交错误!";
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
}
return ResponseResult.success();
}
/** /**
* 查看指定精调任务运行对象详情。 * 查看指定精调任务运行对象详情。
* *
...@@ -270,9 +286,10 @@ public class TuningRunController { ...@@ -270,9 +286,10 @@ public class TuningRunController {
public ResponseEntity<Resource> getLog(@RequestParam Long runId) throws IOException { public ResponseEntity<Resource> getLog(@RequestParam Long runId) throws IOException {
TuningRun tuningRun = this.tuningRunService.getById(runId); TuningRun tuningRun = this.tuningRunService.getById(runId);
ModelVersion modelVersion = this.modelVersionService.getById(tuningRun.getModelVersionId()); ModelVersion modelVersion = this.modelVersionService.getById(tuningRun.getModelVersionId());
String url = this.pythonConfig.getModelTuningFileBaseDir() + modelVersion.getVersionName() + File.separator + tuningRun.getTrainMethod() + File.separator +"train_" + tuningRun.getRunId() + File.separator + "run_train.log"; String url = this.pythonConfig.getModelTuningFileBaseDir() + modelVersion.getVersionName() + File.separator + tuningRun.getTrainMethod() + File.separator + "train_" + tuningRun.getRunId() + File.separator + "run_train.log";
return this.getFileByUrl(url); return this.getFileByUrl(url);
} }
/** /**
* 获取运行状态。 * 获取运行状态。
* *
...@@ -283,13 +300,12 @@ public class TuningRunController { ...@@ -283,13 +300,12 @@ public class TuningRunController {
public ResponseResult<String> getStatus(@RequestParam Long runId) throws IOException { public ResponseResult<String> getStatus(@RequestParam Long runId) throws IOException {
TuningRun tuningRun = this.tuningRunService.getById(runId); TuningRun tuningRun = this.tuningRunService.getById(runId);
ModelVersion modelVersion = this.modelVersionService.getById(tuningRun.getModelVersionId()); ModelVersion modelVersion = this.modelVersionService.getById(tuningRun.getModelVersionId());
String url = this.pythonConfig.getModelTuningFileBaseDir() + modelVersion.getVersionName() + File.separator + tuningRun.getTrainMethod() + File.separator +"train_" + tuningRun.getRunId() + File.separator + "trainer_state.json"; String url = this.pythonConfig.getModelTuningFileBaseDir() + modelVersion.getVersionName() + File.separator + tuningRun.getTrainMethod() + File.separator + "train_" + tuningRun.getRunId() + File.separator + "trainer_state.json";
File file = new File(url); // 指定文件路径 File file = new File(url); // 指定文件路径
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
ArrayNode arrayNode = (ArrayNode) objectMapper.readTree(file); return ResponseResult.success(objectMapper.readTree(file).toString());
String jsonString = objectMapper.writeValueAsString(arrayNode);
return ResponseResult.success(jsonString);
} }
private ResponseEntity<Resource> getFileByUrl(String url) throws IOException { private ResponseEntity<Resource> getFileByUrl(String url) throws IOException {
Path file = Paths.get(url); Path file = Paths.get(url);
Resource resource = new UrlResource(file.toUri()); // 使用UrlResource从文件路径构建一个Resource对象 Resource resource = new UrlResource(file.toUri()); // 使用UrlResource从文件路径构建一个Resource对象
......
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