From a665811e45e9c67264778a57eb2ce56e135756ed Mon Sep 17 00:00:00 2001 From: Liuyang <2746366019@qq.com> Date: Mon, 3 Mar 2025 10:47:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(module-llm):=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了多处不必要的日志打印语句,减少生产环境中的日志噪音 - 在 getCheckFileList 方法中添加了异常捕获,提高了代码的健壮性 - 优化了部分代码格式,提高了可读性 --- .../llm/service/http/TrainHttpService.java | 77 ++++++++++--------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/TrainHttpService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/TrainHttpService.java index 12309ad4b..cd1a68112 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/TrainHttpService.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/TrainHttpService.java @@ -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 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 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 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 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 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) {