|
|
|
@@ -16,15 +16,11 @@ import org.springframework.core.io.AbstractResource;
|
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
import org.springframework.web.client.HttpClientErrorException;
|
|
|
|
|
import org.springframework.web.client.HttpServerErrorException;
|
|
|
|
|
import org.springframework.web.client.ResourceAccessException;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
@@ -112,8 +108,8 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR);
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}", response.getStatusCode());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败,HTTP状态码: " + response.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String responseBody = response.getBody();
|
|
|
|
@@ -127,27 +123,20 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
Object dataObj = responseMap.get("data");
|
|
|
|
|
return parseDocumentListResponse(dataObj, page, limit);
|
|
|
|
|
} else {
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 响应内容: {}", code, responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败,响应码: " + code);
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}", code);
|
|
|
|
|
// 获取错误消息,如果存在的话
|
|
|
|
|
String apiMessage = (String) responseMap.get("message");
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow响应失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档列表失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpServerErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档列表失败: " + e.getMessage());
|
|
|
|
|
} catch (ResourceAccessException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档列表失败: 网络连接错误 - " + e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("获取文档列表失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取文档列表失败: " + e.getMessage());
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
if (e instanceof RenException) {
|
|
|
|
|
throw (RenException) e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
} finally {
|
|
|
|
|
log.info("=== 获取文档列表操作结束 ===");
|
|
|
|
|
}
|
|
|
|
@@ -480,8 +469,11 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR);
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}", response.getStatusCode());
|
|
|
|
|
String responseBody = response.getBody();
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"RAGFlow API调用失败,HTTP状态码: " + response.getStatusCode() +
|
|
|
|
|
", 响应内容: " + (responseBody != null ? responseBody : "无响应内容"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String responseBody = response.getBody();
|
|
|
|
@@ -502,32 +494,20 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
}
|
|
|
|
|
throw new RenException(ErrorCode.Knowledge_Base_RECORD_NOT_EXISTS);
|
|
|
|
|
} else {
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 响应内容: {}", code, responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败,响应码: " + code);
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}", code);
|
|
|
|
|
// 获取错误消息,如果存在的话
|
|
|
|
|
String apiMessage = (String) responseMap.get("message");
|
|
|
|
|
String errorDetail = apiMessage != null ? apiMessage : "无详细错误信息";
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"解析RAGFlow响应失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
|
|
|
log.warn("文档不存在,documentId: {}, datasetId: {}", documentId, datasetId);
|
|
|
|
|
throw new RenException(ErrorCode.Knowledge_Base_RECORD_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpServerErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档失败: " + e.getMessage());
|
|
|
|
|
} catch (ResourceAccessException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档失败: 网络连接错误 - " + e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("根据documentId获取文档失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取文档失败: " + e.getMessage());
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
if (e instanceof RenException) {
|
|
|
|
|
throw (RenException) e;
|
|
|
|
|
}
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
} finally {
|
|
|
|
|
log.info("=== 根据documentId获取文档操作结束 ===");
|
|
|
|
|
}
|
|
|
|
@@ -583,8 +563,8 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR);
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}", response.getStatusCode());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败,HTTP状态码: " + response.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String responseBody = response.getBody();
|
|
|
|
@@ -615,25 +595,10 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
datasetId, status, pageData.getList().size());
|
|
|
|
|
return pageData;
|
|
|
|
|
} else {
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 响应内容: {}", code, responseBody);
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}", code);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败,响应码: " + code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"解析RAGFlow响应失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档列表失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpServerErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档列表失败: " + e.getMessage());
|
|
|
|
|
} catch (ResourceAccessException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "获取RAGFlow文档列表失败: 网络连接错误 - " + e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("根据状态查询文档列表失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "查询文档列表失败: " + e.getMessage());
|
|
|
|
@@ -722,7 +687,11 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("删除文档失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "删除文档失败: " + e.getMessage());
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
if (e instanceof RenException) {
|
|
|
|
|
throw (RenException) e;
|
|
|
|
|
}
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
} finally {
|
|
|
|
|
log.info("=== 根据documentId删除文档操作结束 ===");
|
|
|
|
|
}
|
|
|
|
@@ -842,7 +811,7 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
|
|
|
|
|
// 验证base_url是否存在且非空
|
|
|
|
|
if (StringUtils.isBlank(baseUrl)) {
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置缺少必要参数: base_url");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -939,44 +908,40 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
log.info("文档上传成功,documentId: {}", documentId);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果响应码不为0,说明API调用失败
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 响应内容: {}", code, responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败,响应码: " + code);
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}", code);
|
|
|
|
|
// 获取错误消息,如果存在的话
|
|
|
|
|
String apiMessage = (String) responseMap.get("message");
|
|
|
|
|
String errorDetail = apiMessage != null ? apiMessage : "无详细错误信息";
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("从RAGFlow API响应中解析出documentId: {}", documentId);
|
|
|
|
|
log.debug("完整响应内容: {}", responseBody);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("解析RAGFlow API响应失败: {}, 响应内容: {}", e.getMessage(), responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow响应失败: " + e.getMessage());
|
|
|
|
|
log.error("解析RAGFlow API响应失败: {}", e.getMessage());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR);
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}", response.getStatusCode());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"RAGFlow API调用失败,HTTP状态码: " + response.getStatusCode() +
|
|
|
|
|
", 响应内容: " + (responseBody != null ? responseBody : "无响应内容"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(documentId)) {
|
|
|
|
|
log.error("无法从RAGFlow API响应中获取documentId,响应内容: {}", responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API响应中未包含documentId");
|
|
|
|
|
log.error("无法从RAGFlow API响应中获取documentId");
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
log.info("RAGFlow文档上传成功,documentId: {},文档已开始自动解析切片", documentId);
|
|
|
|
|
return documentId;
|
|
|
|
|
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"上传RAGFlow文档失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString());
|
|
|
|
|
} catch (HttpServerErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"上传RAGFlow文档失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString());
|
|
|
|
|
} catch (ResourceAccessException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "上传RAGFlow文档失败: 网络连接错误 - " + e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 未知错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "上传RAGFlow文档失败: " + e.getMessage());
|
|
|
|
|
log.error("RAGFlow API调用失败: {}", e.getMessage(), e);
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
if (e instanceof RenException) {
|
|
|
|
|
throw (RenException) e;
|
|
|
|
|
}
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1093,8 +1058,9 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
String message = (String) responseMap.get("message");
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 消息: {}", code, message);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败: " + message);
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}", code);
|
|
|
|
|
String errorDetail = message != null ? message : "无详细错误信息";
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.warn("解析RAGFlow响应失败,但HTTP状态码成功,视为删除成功: {}", e.getMessage());
|
|
|
|
@@ -1106,26 +1072,19 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR);
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}", response.getStatusCode());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"RAGFlow API调用失败,HTTP状态码: " + response.getStatusCode() +
|
|
|
|
|
", 响应内容: " + (responseBody != null ? responseBody : "无响应内容"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"删除RAGFlow文档失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString());
|
|
|
|
|
} catch (HttpServerErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"删除RAGFlow文档失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString());
|
|
|
|
|
} catch (ResourceAccessException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "删除RAGFlow文档失败: 网络连接错误 - " + e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 未知错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "删除RAGFlow文档失败: " + e.getMessage());
|
|
|
|
|
log.error("RAGFlow API调用失败: {}", e.getMessage(), e);
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
if (e instanceof RenException) {
|
|
|
|
|
throw (RenException) e;
|
|
|
|
|
}
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1204,14 +1163,16 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
|
|
|
|
|
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String responseBody = response.getBody();
|
|
|
|
|
log.debug("RAGFlow API响应内容: {}", responseBody);
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}", response.getStatusCode());
|
|
|
|
|
String errorDetail = responseBody != null ? responseBody : "无响应内容";
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"RAGFlow API调用失败,HTTP状态码: " + response.getStatusCode() + ", 响应内容: " + errorDetail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析响应
|
|
|
|
|
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
|
|
|
|
|
Integer code = (Integer) responseMap.get("code");
|
|
|
|
@@ -1220,28 +1181,20 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
log.info("文档解析成功,datasetId: {}, documentIds: {}", datasetId, documentIds);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
// 获取错误消息,如果存在的话
|
|
|
|
|
String message = (String) responseMap.get("message");
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 消息: {}, 响应内容: {}", code, message, responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, response.getStatusCode().toString());
|
|
|
|
|
String errorDetail = message != null ? message : "无详细错误信息";
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 错误信息: {}", code, errorDetail);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow响应失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow文档失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpServerErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow文档失败: " + e.getMessage());
|
|
|
|
|
} catch (ResourceAccessException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow文档失败: 网络连接错误 - " + e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("解析文档失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析文档失败: " + e.getMessage());
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
if (e instanceof RenException) {
|
|
|
|
|
throw (RenException) e;
|
|
|
|
|
}
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
} finally {
|
|
|
|
|
log.info("=== 解析文档操作结束 ===");
|
|
|
|
|
}
|
|
|
|
@@ -1308,14 +1261,16 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
|
|
|
|
|
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "列出切片失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String responseBody = response.getBody();
|
|
|
|
|
log.debug("RAGFlow API响应内容: {}", responseBody);
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}", response.getStatusCode());
|
|
|
|
|
String errorDetail = responseBody != null ? responseBody : "无响应内容";
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"RAGFlow API调用失败,HTTP状态码: " + response.getStatusCode() + ", 响应内容: " + errorDetail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析响应
|
|
|
|
|
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
|
|
|
|
|
Integer code = (Integer) responseMap.get("code");
|
|
|
|
@@ -1326,28 +1281,24 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
// 解析切片数据并格式化返回
|
|
|
|
|
return parseChunkListResponse(responseMap);
|
|
|
|
|
} else {
|
|
|
|
|
// 获取错误消息,如果存在的话
|
|
|
|
|
String message = (String) responseMap.get("message");
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 消息: {}, 响应内容: {}", code, message, responseBody);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败: " + message);
|
|
|
|
|
String errorDetail = message != null ? message : "无详细错误信息";
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 错误信息: {}", code, errorDetail);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow响应失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "列出切片失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpServerErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "列出切片失败: " + e.getMessage());
|
|
|
|
|
} catch (ResourceAccessException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "列出切片失败: 网络连接错误 - " + e.getMessage());
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("列出切片失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "列出切片失败: " + e.getMessage());
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
if (e instanceof RenException) {
|
|
|
|
|
throw (RenException) e;
|
|
|
|
|
}
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
} finally {
|
|
|
|
|
log.info("=== 列出切片操作结束 ===");
|
|
|
|
|
}
|
|
|
|
@@ -1736,14 +1687,16 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
|
|
|
|
|
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String responseBody = response.getBody();
|
|
|
|
|
log.debug("RAGFlow API响应内容: {}", responseBody);
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
log.error("RAGFlow API调用失败,状态码: {}", response.getStatusCode());
|
|
|
|
|
String errorDetail = responseBody != null ? responseBody : "无响应内容";
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR,
|
|
|
|
|
"RAGFlow API调用失败,HTTP状态码: " + response.getStatusCode() + ", 响应内容: " + errorDetail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析响应
|
|
|
|
|
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
|
|
|
|
|
Integer code = (Integer) responseMap.get("code");
|
|
|
|
@@ -1755,32 +1708,24 @@ public class KnowledgeFilesServiceImpl implements KnowledgeFilesService {
|
|
|
|
|
log.info("召回测试成功,返回 {} 条切片", result.get("total"));
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
log.error("RAGFlow API响应格式错误,data字段不是Map类型: {}", dataObj);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API响应格式错误");
|
|
|
|
|
log.error("RAGFlow API响应格式错误,data字段不是Map类型");
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 获取错误消息,如果存在的话
|
|
|
|
|
String message = (String) responseMap.get("message");
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 错误信息: {}", code, message);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败: " + message);
|
|
|
|
|
String errorDetail = message != null ? message : "无详细错误信息";
|
|
|
|
|
log.error("RAGFlow API调用失败,响应码: {}, 错误信息: {}", code, errorDetail);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow响应失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpClientErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "召回测试失败: " + e.getMessage());
|
|
|
|
|
} catch (HttpServerErrorException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}",
|
|
|
|
|
e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "召回测试失败: " + e.getMessage());
|
|
|
|
|
} catch (ResourceAccessException e) {
|
|
|
|
|
log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "召回测试失败: 网络连接错误 - " + e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("召回测试失败: {}", e.getMessage(), e);
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, "召回测试失败: " + e.getMessage());
|
|
|
|
|
String errorMessage = e.getMessage() != null ? e.getMessage() : "未知错误";
|
|
|
|
|
if (e instanceof RenException) {
|
|
|
|
|
throw (RenException) e;
|
|
|
|
|
}
|
|
|
|
|
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
|
|
|
|
} finally {
|
|
|
|
|
log.info("=== 召回测试操作结束 ===");
|
|
|
|
|
}
|
|
|
|
|