refactor(llm): 优化 getCheckFileList 方法的日志记录和异常处理
- 增加方法开始时的日志记录,包括 URL 和 Name 参数 -捕获异常时增加详细的错误日志,包括 URL、Name 和错误详情 - 在正常执行时增加请求完整路径的日志记录 - 增加 HTTP 请求完成后的日志记录,包括耗时、结果长度和结果摘要 -优化代码格式,调整缩进和空格
This commit is contained in:
parent
8cd7ced108
commit
bf65145394
@ -11,23 +11,17 @@ import kong.unirest.HttpResponse;
|
||||
import kong.unirest.Unirest;
|
||||
import kong.unirest.UnirestException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 训练相关接口
|
||||
*/
|
||||
@ -359,10 +353,24 @@ public class TrainHttpService {
|
||||
|
||||
public String getCheckFileList (String url, String name) {
|
||||
try {
|
||||
log.info("开始获取文件列表 | URL参数: {}, Name参数: {}", url, name);
|
||||
String checkFileList = llmBackendProperties.getCheckFileList();
|
||||
return HttpUtils.get(url + checkFileList + name, null);
|
||||
}catch (Exception e){
|
||||
log.error("获取文件列表失败:{}", e.getMessage());
|
||||
String fullUrl = url + checkFileList + name;
|
||||
log.info("请求完整路径: {}", fullUrl);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
String result = HttpUtils.get(fullUrl, null);
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
|
||||
log.info("HTTP请求完成 | 耗时: {}ms | 结果长度: {}", duration, (result != null ? result.length() : 0));
|
||||
if (result != null) {
|
||||
log.info("结果摘要: {}", result.substring(0, Math.min(result.length(), 50)));
|
||||
} else {
|
||||
log.warn("返回空值");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("获取文件列表异常 | URL: {} | Name: {} | 错误详情: {}", url, name, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user