refactor(module-llm):移除调试日志并优化异常处理
- 删除了多处不必要的日志打印语句,减少生产环境中的日志噪音 - 在 getCheckFileList 方法中添加了异常捕获,提高了代码的健壮性 - 优化了部分代码格式,提高了可读性
This commit is contained in:
parent
fb7093b8be
commit
a665811e45
@ -122,7 +122,7 @@ public class TrainHttpService {
|
||||
String login = llmBackendProperties.getLogin();
|
||||
AigcLoginReqVO req = new AigcLoginReqVO(llmBackendProperties.getLoginUsername(), llmBackendProperties.getLoginPassword());
|
||||
String res = HttpUtils.post(login, headers, JSON.toJSONString(req));
|
||||
log.info("登录接口返回:{}", res);
|
||||
// log.info("登录接口返回:{}", res);
|
||||
AigcRespVO aigcRespVO = JSON.parseObject(res, AigcRespVO.class);
|
||||
if (aigcRespVO.isSuccess() && aigcRespVO.getData() != null) {
|
||||
AigcLoginRespVO aigcLoginRespVO = JSON.parseObject(aigcRespVO.getData().toString(), AigcLoginRespVO.class);
|
||||
@ -131,7 +131,7 @@ public class TrainHttpService {
|
||||
if (aigcAccountRespVO != null && CollUtil.isNotEmpty(aigcAccountRespVO.getTenants())) {
|
||||
aigcLoginRespVO.setTenantId(aigcAccountRespVO.getTenants().get(0).getId());
|
||||
headers.put("X-Tenant-Id", aigcLoginRespVO.getTenantId());
|
||||
log.info(" login:{}", aigcAccountRespVO);
|
||||
// log.info(" login:{}", aigcAccountRespVO);
|
||||
return aigcLoginRespVO;
|
||||
}
|
||||
}
|
||||
@ -141,11 +141,11 @@ public class TrainHttpService {
|
||||
public AigcAccountRespVO account (Map<String, String> headers) {
|
||||
String account = llmBackendProperties.getAccount();
|
||||
String res = HttpUtils.get(account, headers);
|
||||
log.info(" account:{}", res);
|
||||
// log.info(" account:{}", res);
|
||||
AigcRespVO aigcRespVO = JSON.parseObject(res, AigcRespVO.class);
|
||||
if (aigcRespVO.isSuccess() && aigcRespVO.getData() != null) {
|
||||
AigcAccountRespVO aigcAccountRespVO = JSON.parseObject(aigcRespVO.getData().toString(), AigcAccountRespVO.class);
|
||||
log.info(" account:{}", aigcAccountRespVO);
|
||||
// log.info(" account:{}", aigcAccountRespVO);
|
||||
return aigcAccountRespVO;
|
||||
}
|
||||
return null;
|
||||
@ -155,16 +155,16 @@ public class TrainHttpService {
|
||||
login(headers);
|
||||
String finetuningDetail = llmBackendProperties.getFinetuningDetail();
|
||||
String res = HttpUtils.get(finetuningDetail + "/" + jobId, headers);
|
||||
log.info(" finetuningDetail:{}", res);
|
||||
// log.info(" finetuningDetail:{}", res);
|
||||
try {
|
||||
AigcRespVO aigcRespVO = JSON.parseObject(res, AigcRespVO.class);
|
||||
if (aigcRespVO.isSuccess() && aigcRespVO.getData() != null) {
|
||||
AigcFineTuningDetailRespVO aigcFineTuningDetailRespVO = JSON.parseObject(aigcRespVO.getData().toString(), AigcFineTuningDetailRespVO.class);
|
||||
log.info(" finetuningDetail:{}", aigcFineTuningDetailRespVO);
|
||||
// log.info(" finetuningDetail:{}", aigcFineTuningDetailRespVO);
|
||||
return aigcFineTuningDetailRespVO;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(" finetuningDetail:{}", e.getMessage());
|
||||
// log.error(" finetuningDetail:{}", e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -174,16 +174,16 @@ public class TrainHttpService {
|
||||
login(headers);
|
||||
String finetuningDetail = llmBackendProperties.getFinetuningDetail();
|
||||
String res = HttpUtils.del(finetuningDetail + "/" + jobId, headers);
|
||||
log.info(" finetuningDelete:{}", res);
|
||||
// log.info(" finetuningDelete:{}", res);
|
||||
AigcRespVO aigcRespVO = JSON.parseObject(res, AigcRespVO.class);
|
||||
log.info(" finetuningDelete:{}", aigcRespVO);
|
||||
// log.info(" finetuningDelete:{}", aigcRespVO);
|
||||
return aigcRespVO;
|
||||
}
|
||||
|
||||
public String finetuningFileList (Map<String, String> headers) {
|
||||
String finetuningFileList = llmBackendProperties.getFinetuningFileList();
|
||||
String res = HttpUtils.get(finetuningFileList, headers);
|
||||
log.info(" finetuningFileList:{}", res);
|
||||
// log.info(" finetuningFileList:{}", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -200,10 +200,10 @@ public class TrainHttpService {
|
||||
List<String> dimension = Stream.of("事实性错误", "情感倾向性", "语义连贯性").collect(Collectors.toList());
|
||||
jsonObject.put("dimension", dimension);
|
||||
String body = JSONObject.toJSONString(jsonObject);
|
||||
log.info(" autoEvaluation body :{}", body);
|
||||
log.info(" autoEvaluation url :{}", url + autoEvaluation);
|
||||
// log.info(" autoEvaluation body :{}", body);
|
||||
// log.info(" autoEvaluation url :{}", url + autoEvaluation);
|
||||
String res = HttpUtils.post(url + autoEvaluation, map, body);
|
||||
log.info(" autoEvaluation:{}", res);
|
||||
// log.info(" autoEvaluation:{}", res);
|
||||
JSONObject resJson = JSONObject.parseObject(res);
|
||||
JSONObject response = resJson.getJSONObject("response");
|
||||
String content = response.getString("content");
|
||||
@ -222,36 +222,36 @@ public class TrainHttpService {
|
||||
|
||||
public ModelDeployRespVO modelDeploy (Map<String, String> headers, String url, AigcModelDeploySaveReq req) {
|
||||
try {
|
||||
log.info("开始部署模型,请求URL: {}", url + llmBackendProperties.getModelDeploy());
|
||||
// log.info("开始部署模型,请求URL: {}", url + llmBackendProperties.getModelDeploy());
|
||||
|
||||
// 记录请求参数
|
||||
log.info("请求参数: {}", JSON.toJSONString(req));
|
||||
// log.info("请求参数: {}", JSON.toJSONString(req));
|
||||
|
||||
// 发起 HTTP POST 请求
|
||||
String res = HttpUtils.post(url + llmBackendProperties.getModelDeploy(), headers, JSON.toJSONString(req));
|
||||
log.info("HTTP 请求完成。响应内容: {}", res);
|
||||
// log.info("HTTP 请求完成。响应内容: {}", res);
|
||||
|
||||
// 解析响应内容
|
||||
log.debug("正在解析响应内容...");
|
||||
// log.debug("正在解析响应内容...");
|
||||
JSONObject parseObject = JSON.parseObject(res);
|
||||
ModelDeployRespVO modelDeployRespVO = new ModelDeployRespVO();
|
||||
|
||||
// 检查响应是否包含错误
|
||||
if (parseObject.containsKey("error")) {
|
||||
log.error("模型部署失败。响应中包含错误信息: {}", parseObject.getString("error"));
|
||||
// log.error("模型部署失败。响应中包含错误信息: {}", parseObject.getString("error"));
|
||||
modelDeployRespVO.setMessage("error");
|
||||
return modelDeployRespVO;
|
||||
}
|
||||
|
||||
// 解析响应为 ModelDeployRespVO 对象
|
||||
modelDeployRespVO = JSON.parseObject(res.getBytes(), ModelDeployRespVO.class);
|
||||
log.info("模型部署成功。部署结果: {}", JSON.toJSONString(modelDeployRespVO));
|
||||
// log.info("模型部署成功。部署结果: {}", JSON.toJSONString(modelDeployRespVO));
|
||||
|
||||
// 返回结果
|
||||
return modelDeployRespVO;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("部署模型时发生异常。请求URL: {}", url + llmBackendProperties.getModelDeploy(), e);
|
||||
// log.error("部署模型时发生异常。请求URL: {}", url + llmBackendProperties.getModelDeploy(), e);
|
||||
ModelDeployRespVO errorResp = new ModelDeployRespVO();
|
||||
errorResp.setMessage("error");
|
||||
return errorResp;
|
||||
@ -260,28 +260,28 @@ public class TrainHttpService {
|
||||
|
||||
public AigcModelDeployVO modelUndeploy (Map<String, String> headers, String url, Long deployId) {
|
||||
try {
|
||||
log.info("开始卸载模型部署,部署ID: {}", deployId);
|
||||
// log.info("开始卸载模型部署,部署ID: {}", deployId);
|
||||
|
||||
// 构建请求 URL
|
||||
String modelDeploy = llmBackendProperties.getModelUndeploy();
|
||||
String requestUrl = url + modelDeploy + deployId;
|
||||
log.info("构建请求 URL: {}", requestUrl);
|
||||
// log.info("构建请求 URL: {}", requestUrl);
|
||||
|
||||
// 发起 HTTP POST 请求
|
||||
log.info("正在发起 HTTP POST 请求...");
|
||||
// log.info("正在发起 HTTP POST 请求...");
|
||||
String res = HttpUtils.post(requestUrl, headers, "");
|
||||
log.info("HTTP 请求完成。响应内容: {}", res);
|
||||
// log.info("HTTP 请求完成。响应内容: {}", res);
|
||||
|
||||
// 解析响应内容
|
||||
log.info("正在解析响应内容...");
|
||||
// log.info("正在解析响应内容...");
|
||||
AigcModelDeployVO modelDeployRespVO = JSON.parseObject(res, AigcModelDeployVO.class);
|
||||
log.info("响应解析完成。模型卸载结果: {}", JSON.toJSONString(modelDeployRespVO));
|
||||
// log.info("响应解析完成。模型卸载结果: {}", JSON.toJSONString(modelDeployRespVO));
|
||||
|
||||
// 返回结果
|
||||
return modelDeployRespVO;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("卸载模型部署时发生异常。部署ID: {}", deployId, e);
|
||||
// log.error("卸载模型部署时发生异常。部署ID: {}", deployId, e);
|
||||
throw new RuntimeException("模型卸载失败", e);
|
||||
}
|
||||
|
||||
@ -294,14 +294,14 @@ public class TrainHttpService {
|
||||
// login(headers);
|
||||
String modelDeploy = llmBackendProperties.getModelCreate();
|
||||
String res = HttpUtils.post(modelDeploy, headers, JSON.toJSONString(req));
|
||||
log.info(" modelDeploy:{}", res);
|
||||
// log.info(" modelDeploy:{}", res);
|
||||
AigcRespVO aigcRespVO = JSON.parseObject(res, AigcRespVO.class);
|
||||
if (aigcRespVO.isSuccess() && aigcRespVO.getData() != null) {
|
||||
AigcModelCreateRespVO aigcModelCreateRespVO = JSON.parseObject(aigcRespVO.getData().toString(), AigcModelCreateRespVO.class);
|
||||
log.info(" modelDeploy:{}", aigcModelCreateRespVO);
|
||||
// log.info(" modelDeploy:{}", aigcModelCreateRespVO);
|
||||
return aigcModelCreateRespVO;
|
||||
}
|
||||
log.info(" modelDeploy:{}", aigcRespVO);
|
||||
// log.info(" modelDeploy:{}", aigcRespVO);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -326,11 +326,11 @@ public class TrainHttpService {
|
||||
.field("file", inputStream, fileName)
|
||||
.field("purpose", "fine-tune")
|
||||
.asString();
|
||||
log.info("Response Body: " + uploadResponse.getBody());
|
||||
// log.info("Response Body: " + uploadResponse.getBody());
|
||||
AigcRespVO aigcRespVO = JSON.parseObject(uploadResponse.getBody(), AigcRespVO.class);
|
||||
if (aigcRespVO.isSuccess()) {
|
||||
AigcDatasetFileRespV0 aigcDatasetFileRespV0 = JSON.parseObject(aigcRespVO.getData().toString(), AigcDatasetFileRespV0.class);
|
||||
log.info("模型工厂上传文件 aigcDatasetFileRespV0:{}", aigcDatasetFileRespV0);
|
||||
// log.info("模型工厂上传文件 aigcDatasetFileRespV0:{}", aigcDatasetFileRespV0);
|
||||
return aigcDatasetFileRespV0;
|
||||
}
|
||||
return null;
|
||||
@ -345,9 +345,9 @@ public class TrainHttpService {
|
||||
String finetuningCancel = llmBackendProperties.getFinetuningCancel();
|
||||
String url = String.format(finetuningCancel, jobId);
|
||||
String res = HttpUtils.del(url, headers);
|
||||
log.info(" finetuningDelete:{}", res);
|
||||
// log.info(" finetuningDelete:{}", res);
|
||||
AigcRespVO aigcRespVO = JSON.parseObject(res, AigcRespVO.class);
|
||||
log.info(" finetuningDelete:{}", aigcRespVO);
|
||||
// log.info(" finetuningDelete:{}", aigcRespVO);
|
||||
return aigcRespVO;
|
||||
|
||||
}
|
||||
@ -358,8 +358,13 @@ public class TrainHttpService {
|
||||
}
|
||||
|
||||
public String getCheckFileList (String url, String name) {
|
||||
String checkFileList = llmBackendProperties.getCheckFileList();
|
||||
return HttpUtils.get(url + checkFileList + name, null);
|
||||
try {
|
||||
String checkFileList = llmBackendProperties.getCheckFileList();
|
||||
return HttpUtils.get(url + checkFileList + name, null);
|
||||
}catch (Exception e){
|
||||
log.error("获取文件列表失败:{}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getCheckFile (String url, String name, String path) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user