refactor(yudao-module-llm): 优化模型部署功能的日志记录和异常处理

-增加了更多的日志记录,包括请求 URL、请求参数、响应内容等
- 优化了异常处理,捕获并记录了可能发生的异常
- 改进了错误处理逻辑,当响应中包含错误信息时进行记录并返回错误响应
This commit is contained in:
Liuyang 2025-02-26 15:47:50 +08:00
parent aeb0ee56f8
commit 84562ba94d

View File

@ -221,22 +221,41 @@ public class TrainHttpService {
}
public ModelDeployRespVO modelDeploy (Map<String, String> headers, String url, AigcModelDeploySaveReq req) {
// login(headers);
String modelDeploy = llmBackendProperties.getModelDeploy();
log.info(" modelDeploy request:{}", JSON.toJSONString(req));
String res = HttpUtils.post(url + modelDeploy, headers, JSON.toJSONString(req));
log.info(" modelDeploy:{}", res);
JSONObject parseObject = JSON.parseObject(res);
ModelDeployRespVO modelDeployRespVO = new ModelDeployRespVO();
try {
log.info("开始部署模型请求URL: {}", url + llmBackendProperties.getModelDeploy());
log.info("--- {}", parseObject);
if (parseObject.containsKey("error")) {
modelDeployRespVO.setMessage("error");
// 记录请求参数
log.info("请求参数: {}", JSON.toJSONString(req));
// 发起 HTTP POST 请求
String res = HttpUtils.post(url + llmBackendProperties.getModelDeploy(), headers, JSON.toJSONString(req));
log.info("HTTP 请求完成。响应内容: {}", res);
// 解析响应内容
log.debug("正在解析响应内容...");
JSONObject parseObject = JSON.parseObject(res);
ModelDeployRespVO modelDeployRespVO = new ModelDeployRespVO();
// 检查响应是否包含错误
if (parseObject.containsKey("error")) {
log.error("模型部署失败。响应中包含错误信息: {}", parseObject.getString("error"));
modelDeployRespVO.setMessage("error");
return modelDeployRespVO;
}
// 解析响应为 ModelDeployRespVO 对象
modelDeployRespVO = JSON.parseObject(res.getBytes(), ModelDeployRespVO.class);
log.info("模型部署成功。部署结果: {}", JSON.toJSONString(modelDeployRespVO));
// 返回结果
return modelDeployRespVO;
}
modelDeployRespVO = JSON.parseObject(res.getBytes(), ModelDeployRespVO.class);
return modelDeployRespVO;
} catch (Exception e) {
log.error("部署模型时发生异常。请求URL: {}", url + llmBackendProperties.getModelDeploy(), e);
ModelDeployRespVO errorResp = new ModelDeployRespVO();
errorResp.setMessage("error");
return errorResp;
}
}
public AigcModelDeployVO modelUndeploy (Map<String, String> headers, String url, Long deployId) {