mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-24 08:03:53 +08:00
Merge pull request #2517 from xinnan-tech/knowledge-base-fix
Knowledge base fix
This commit is contained in:
@@ -205,8 +205,12 @@ public interface ErrorCode {
|
||||
int RAG_CONFIG_NOT_FOUND = 10164; // RAG配置未找到
|
||||
int RAG_CONFIG_TYPE_ERROR = 10165; // RAG配置类型错误
|
||||
int RAG_DEFAULT_CONFIG_NOT_FOUND = 10166; // 默认RAG配置未找到
|
||||
int RAG_API_ERROR = 10167; // RAG配置缺少必要参数
|
||||
int RAG_API_ERROR = 10167; // RAG调用失败
|
||||
int UPLOAD_FILE_ERROR = 10168; // 上传文件失败
|
||||
int NO_PERMISSION = 10169; // 没有权限
|
||||
int KNOWLEDGE_BASE_NAME_EXISTS = 10170; // 同名知识库已存在
|
||||
int RAG_API_ERROR_URL_NULL = 10171; // RAG配置中base_url为空,请完善配置
|
||||
int RAG_API_ERROR_API_KEY_NULL = 10172; // RAG配置中api_key为空,请完善配置
|
||||
int RAG_API_ERROR_API_KEY_INVALID = 10173; // RAG配置中api_key包含占位符,请替换为实际的API密钥
|
||||
int RAG_API_ERROR_URL_INVALID = 10174; // RAG配置中base_url格式不正确,请检查协议是否正确
|
||||
}
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ public class AgentPluginMappingServiceImpl extends ServiceImpl<AgentPluginMappin
|
||||
|
||||
String description = "如果用户询问与【"
|
||||
+ String.join(",", knowledgeBaseList.stream().map(KnowledgeBaseEntity::getName).toList())
|
||||
+ "】相关的问题应调用本方法,用于查询:" + String.join(",",
|
||||
+ "】涵盖的主体范围相关内容时应调用本方法,用于查询:" + String.join(",",
|
||||
knowledgeBaseList.stream().map(KnowledgeBaseEntity::getDescription).toList());
|
||||
paramInfo.put("description", description);
|
||||
agentPluginMapping.setParamInfo(JsonUtils.toJsonString(paramInfo));
|
||||
|
||||
+218
-75
@@ -1,5 +1,6 @@
|
||||
package xiaozhi.modules.knowledge.service.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -51,6 +52,7 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
private final ModelConfigDao modelConfigDao;
|
||||
private final RedisUtils redisUtils;
|
||||
private RestTemplate restTemplate = new RestTemplate();
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public KnowledgeBaseEntity selectById(Serializable datasetId) {
|
||||
@@ -108,7 +110,10 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
knowledgeBase.getRagModelId());
|
||||
knowledgeBase.setDocumentCount(documentCount);
|
||||
} catch (Exception e) {
|
||||
log.warn("获取知识库 {} 的文档数量失败: {}", knowledgeBase.getDatasetId(), e.getMessage());
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 获取知识库文档数量失败";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.warn("知识库 {} {}", knowledgeBase.getDatasetId(), errorMessage);
|
||||
knowledgeBase.setDocumentCount(0); // 设置默认值
|
||||
}
|
||||
}
|
||||
@@ -149,7 +154,7 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
knowledgeBaseDTO.getDescription(),
|
||||
ragConfig);
|
||||
} catch (Exception e) {
|
||||
// 如果RAG API调用失败,直接抛出异常,无需回滚(因为还没有插入本地数据库)
|
||||
// 如果RAG API调用失败,直接抛出异常
|
||||
throw e;
|
||||
}
|
||||
|
||||
@@ -162,7 +167,12 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
Map<String, Object> ragConfig = getValidatedRAGConfig(knowledgeBaseDTO.getRagModelId());
|
||||
deleteDatasetInRAGFlow(datasetId, ragConfig);
|
||||
} catch (Exception deleteException) {
|
||||
log.warn("删除重复datasetId的RAGFlow数据集失败: {}", deleteException.getMessage());
|
||||
// 提供更详细的错误信息,包括异常类型和消息
|
||||
String errorMessage = "删除重复datasetId的RAGFlow数据集失败: " + deleteException.getClass().getSimpleName();
|
||||
if (deleteException.getMessage() != null) {
|
||||
errorMessage += " - " + deleteException.getMessage();
|
||||
}
|
||||
log.warn(errorMessage, deleteException);
|
||||
}
|
||||
throw new RenException(ErrorCode.DB_RECORD_EXISTS);
|
||||
}
|
||||
@@ -201,6 +211,35 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
}
|
||||
}
|
||||
|
||||
boolean needRagValidation = StringUtils.isNotBlank(knowledgeBaseDTO.getDatasetId())
|
||||
&& StringUtils.isNotBlank(knowledgeBaseDTO.getRagModelId());
|
||||
|
||||
if (needRagValidation) {
|
||||
try {
|
||||
// 先校验RAG配置
|
||||
Map<String, Object> ragConfig = getValidatedRAGConfig(knowledgeBaseDTO.getRagModelId());
|
||||
|
||||
// 调用RAGFlow API更新数据集
|
||||
updateDatasetInRAGFlow(
|
||||
knowledgeBaseDTO.getDatasetId(),
|
||||
knowledgeBaseDTO.getName(),
|
||||
knowledgeBaseDTO.getDescription(),
|
||||
ragConfig);
|
||||
|
||||
log.info("RAGFlow API更新成功,datasetId: {}", knowledgeBaseDTO.getDatasetId());
|
||||
} catch (Exception e) {
|
||||
// 提供更详细的错误信息,包括异常类型和消息
|
||||
String errorMessage = "更新RAGFlow数据集失败: " + e.getClass().getSimpleName();
|
||||
if (e.getMessage() != null) {
|
||||
errorMessage += " - " + e.getMessage();
|
||||
}
|
||||
log.error(errorMessage, e);
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
log.warn("datasetId或ragModelId为空,跳过RAGFlow更新");
|
||||
}
|
||||
|
||||
KnowledgeBaseEntity entity = ConvertUtils.sourceToTarget(knowledgeBaseDTO, KnowledgeBaseEntity.class);
|
||||
knowledgeBaseDao.updateById(entity);
|
||||
|
||||
@@ -209,22 +248,6 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
redisUtils.delete(RedisKeys.getKnowledgeBaseCacheKey(entity.getId()));
|
||||
}
|
||||
|
||||
// 调用RAGFlow API更新数据集
|
||||
if (StringUtils.isNotBlank(knowledgeBaseDTO.getDatasetId())) {
|
||||
try {
|
||||
Map<String, Object> ragConfig = getValidatedRAGConfig(knowledgeBaseDTO.getRagModelId());
|
||||
updateDatasetInRAGFlow(
|
||||
knowledgeBaseDTO.getDatasetId(),
|
||||
knowledgeBaseDTO.getName(),
|
||||
knowledgeBaseDTO.getDescription(),
|
||||
ragConfig);
|
||||
} catch (Exception e) {
|
||||
// 如果RAG API调用失败,回滚本地数据库操作
|
||||
knowledgeBaseDao.updateById(existingEntity);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return ConvertUtils.sourceToTarget(entity, KnowledgeBaseDTO.class);
|
||||
}
|
||||
|
||||
@@ -265,22 +288,34 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
log.info("找到记录: ID={}, datasetId={}, ragModelId={}",
|
||||
entity.getId(), entity.getDatasetId(), entity.getRagModelId());
|
||||
|
||||
// 先删除本地数据库记录
|
||||
int deleteCount = knowledgeBaseDao.deleteById(entity.getId());
|
||||
log.info("本地数据库删除结果: {}", deleteCount > 0 ? "成功" : "失败");
|
||||
|
||||
// 调用RAGFlow API删除数据集
|
||||
// 先调用RAGFlow API删除数据集
|
||||
boolean apiDeleteSuccess = false;
|
||||
if (StringUtils.isNotBlank(entity.getDatasetId()) && StringUtils.isNotBlank(entity.getRagModelId())) {
|
||||
try {
|
||||
log.info("开始调用RAGFlow API删除数据集");
|
||||
// 在删除前进行RAG配置校验
|
||||
Map<String, Object> ragConfig = getValidatedRAGConfig(entity.getRagModelId());
|
||||
deleteDatasetInRAGFlow(entity.getDatasetId(), ragConfig);
|
||||
log.info("RAGFlow API删除调用完成");
|
||||
apiDeleteSuccess = true;
|
||||
} catch (Exception e) {
|
||||
log.warn("删除RAGFlow数据集失败: {}", e.getMessage());
|
||||
// 提供更详细的错误信息,包括异常类型和消息
|
||||
String errorMessage = "删除RAGFlow数据集失败: " + e.getClass().getSimpleName();
|
||||
if (e.getMessage() != null) {
|
||||
errorMessage += " - " + e.getMessage();
|
||||
}
|
||||
log.error(errorMessage, e);
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
log.warn("datasetId或ragModelId为空,跳过RAGFlow删除");
|
||||
apiDeleteSuccess = true; // 没有RAG数据集,视为成功
|
||||
}
|
||||
|
||||
// API删除成功后再删除本地记录
|
||||
if (apiDeleteSuccess) {
|
||||
int deleteCount = knowledgeBaseDao.deleteById(entity.getId());
|
||||
log.info("本地数据库删除结果: {}", deleteCount > 0 ? "成功" : "失败");
|
||||
}
|
||||
|
||||
log.info("=== 通过datasetId删除操作结束 ===");
|
||||
@@ -364,7 +399,7 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
*/
|
||||
private void validateRagConfig(Map<String, Object> config) {
|
||||
if (config == null) {
|
||||
throw new RenException(ErrorCode.RAG_CONFIG_NOT_FOUND);
|
||||
throw new RenException(ErrorCode.RAG_CONFIG_NOT_FOUND, "RAG配置为空,请检查配置");
|
||||
}
|
||||
|
||||
// 从配置中提取必要的参数
|
||||
@@ -373,7 +408,22 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
|
||||
// 验证base_url是否存在且非空
|
||||
if (StringUtils.isBlank(baseUrl)) {
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR_URL_NULL);
|
||||
}
|
||||
|
||||
// 验证api_key是否存在且非空
|
||||
if (StringUtils.isBlank(apiKey)) {
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR_API_KEY_NULL);
|
||||
}
|
||||
|
||||
// 检查api_key是否包含占位符
|
||||
if (apiKey.contains("你")) {
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR_API_KEY_INVALID);
|
||||
}
|
||||
|
||||
// 验证base_url格式
|
||||
if (!baseUrl.startsWith("http://") && !baseUrl.startsWith("https://")) {
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR_URL_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,14 +460,22 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
|
||||
// 发送POST请求
|
||||
log.info("发送POST请求到RAGFlow API...");
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
|
||||
ResponseEntity<String> response;
|
||||
try {
|
||||
response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
|
||||
} catch (Exception e) {
|
||||
String errorMessage = url + e.getMessage();
|
||||
log.error(errorMessage, e);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
|
||||
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
||||
log.debug("RAGFlow API响应内容: {}", response.getBody());
|
||||
|
||||
if (!response.getStatusCode().is2xxSuccessful()) {
|
||||
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, response.getStatusCode().toString());
|
||||
String errorMessage = response.getStatusCode() + ", 响应内容: " + response.getBody();
|
||||
log.error(errorMessage);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
|
||||
// 解析响应体,提取datasetId
|
||||
@@ -448,16 +506,31 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
}
|
||||
} else {
|
||||
// 如果响应码不为0,说明API调用失败
|
||||
log.error("RAGFlow API调用失败,响应码: {}, 响应内容: {}", code, message);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR,
|
||||
"RAGFlow API调用失败,响应码: " + code + ", 消息: " + message);
|
||||
String errorMessage = "RAGFlow API调用失败,响应码: " + code + ", 消息: "
|
||||
+ (message != null ? message : "未知错误");
|
||||
log.error(errorMessage);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
|
||||
log.info("从RAGFlow API响应中解析出datasetId: {}", datasetId);
|
||||
log.debug("完整响应内容: {}", responseBody);
|
||||
} catch (IOException e) {
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 解析RAGFlow API响应时发生IO异常";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.error(errorMessage, e);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API响应解析失败: " + errorMessage);
|
||||
} catch (Exception e) {
|
||||
log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, "解析响应失败: " + e.getMessage());
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 解析RAGFlow API响应失败";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.error(errorMessage, e);
|
||||
// 如果解析失败,但响应体不为空,尝试直接使用响应体作为错误信息
|
||||
String finalErrorMessage = responseBody;
|
||||
if (e.getMessage() != null) {
|
||||
finalErrorMessage += ",解析错误: " + errorMessage;
|
||||
}
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, finalErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,14 +576,56 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
|
||||
// 发送PUT请求
|
||||
log.info("发送PUT请求到RAGFlow API...");
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, String.class);
|
||||
ResponseEntity<String> response;
|
||||
try {
|
||||
response = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, String.class);
|
||||
} catch (Exception e) {
|
||||
String errorMessage = url + e.getMessage();
|
||||
log.error(errorMessage, e);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
|
||||
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
||||
log.debug("RAGFlow API响应内容: {}", response.getBody());
|
||||
|
||||
if (!response.getStatusCode().is2xxSuccessful()) {
|
||||
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR);
|
||||
String errorMessage = response.getStatusCode() + ", 响应内容: " + response.getBody();
|
||||
log.error(errorMessage);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
|
||||
// 解析响应体,验证操作是否真正成功
|
||||
String responseBody = response.getBody();
|
||||
if (responseBody != null) {
|
||||
try {
|
||||
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
|
||||
Integer code = (Integer) responseMap.get("code");
|
||||
String message = (String) responseMap.get("message");
|
||||
|
||||
if (code != null && code != 0) {
|
||||
String errorMessage = "RAGFlow API调用失败,响应码: " + code + ", 消息: "
|
||||
+ (message != null ? message : "未知错误");
|
||||
log.error(errorMessage);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 解析RAGFlow API响应时发生IO异常";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.error(errorMessage, e);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API响应解析失败: " + errorMessage);
|
||||
} catch (Exception e) {
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 解析RAGFlow API响应失败";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.error(errorMessage, e);
|
||||
// 如果解析失败,但响应体不为空,尝试直接使用响应体作为错误信息
|
||||
String finalErrorMessage = responseBody;
|
||||
if (e.getMessage() != null) {
|
||||
finalErrorMessage += ",解析错误: " + errorMessage;
|
||||
}
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, finalErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("RAGFlow数据集更新成功,datasetId: {}", datasetId);
|
||||
@@ -545,16 +660,58 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
|
||||
// 发送DELETE请求
|
||||
log.info("发送DELETE请求到RAGFlow API...");
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity,
|
||||
String.class);
|
||||
ResponseEntity<String> response;
|
||||
try {
|
||||
response = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, String.class);
|
||||
} catch (Exception e) {
|
||||
String errorMessage = url + e.getMessage();
|
||||
log.error(errorMessage, e);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
|
||||
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
||||
log.debug("RAGFlow API响应内容: {}", response.getBody());
|
||||
|
||||
if (!response.getStatusCode().is2xxSuccessful()) {
|
||||
log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody());
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR);
|
||||
String errorMessage = response.getStatusCode() + ", 响应内容: " + response.getBody();
|
||||
log.error(errorMessage);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
|
||||
// 解析响应体,验证操作是否真正成功
|
||||
String responseBody = response.getBody();
|
||||
if (responseBody != null) {
|
||||
try {
|
||||
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
|
||||
Integer code = (Integer) responseMap.get("code");
|
||||
String message = (String) responseMap.get("message");
|
||||
|
||||
if (code != null && code != 0) {
|
||||
String errorMessage = "RAGFlow API调用失败,响应码: " + code + ", 消息: "
|
||||
+ (message != null ? message : "未知错误");
|
||||
log.error(errorMessage);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, errorMessage);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 解析RAGFlow API响应时发生IO异常";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.error(errorMessage, e);
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API响应解析失败: " + errorMessage);
|
||||
} catch (Exception e) {
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 解析RAGFlow API响应失败";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.error(errorMessage, e);
|
||||
// 如果解析失败,但响应体不为空,尝试直接使用响应体作为错误信息
|
||||
String finalErrorMessage = responseBody;
|
||||
if (e.getMessage() != null) {
|
||||
finalErrorMessage += ",解析错误: " + errorMessage;
|
||||
}
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, finalErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("RAGFlow数据集删除成功,datasetId: {}", datasetId);
|
||||
|
||||
}
|
||||
@@ -570,41 +727,12 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
ragConfig = getDefaultRAGConfig();
|
||||
}
|
||||
|
||||
// 验证baseUrl和apiKey
|
||||
validateRAGConfigParameters(ragConfig);
|
||||
// 验证RAG配置参数
|
||||
validateRagConfig(ragConfig);
|
||||
|
||||
return ragConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证RAG配置参数
|
||||
*/
|
||||
private void validateRAGConfigParameters(Map<String, Object> ragConfig) {
|
||||
if (ragConfig == null) {
|
||||
throw new RenException(ErrorCode.RAG_CONFIG_NOT_FOUND, "RAG配置为空,请检查配置");
|
||||
}
|
||||
|
||||
// 从配置中提取必要的参数
|
||||
String baseUrl = (String) ragConfig.get("base_url");
|
||||
String apiKey = (String) ragConfig.get("api_key");
|
||||
|
||||
if (StringUtils.isBlank(baseUrl)) {
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置中base_url为空,请完善配置");
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(apiKey)) {
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置中api_key为空,请完善配置");
|
||||
}
|
||||
|
||||
if (apiKey.contains("你")) {
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置中api_key包含占位符'你',请替换为实际的API密钥");
|
||||
}
|
||||
|
||||
if (!baseUrl.startsWith("http://") && !baseUrl.startsWith("https://")) {
|
||||
throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置中base_url格式不正确,必须以http://或https://开头");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否存在同名知识库
|
||||
*
|
||||
@@ -660,7 +788,14 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
|
||||
// 发送GET请求
|
||||
log.info("发送GET请求到RAGFlow API获取文档数量...");
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
|
||||
ResponseEntity<String> response;
|
||||
try {
|
||||
response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
|
||||
} catch (Exception e) {
|
||||
String errorMessage = url + e.getMessage();
|
||||
log.error(errorMessage, e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log.info("RAGFlow API响应状态码: {}", response.getStatusCode());
|
||||
|
||||
@@ -696,8 +831,16 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
||||
} else {
|
||||
log.error("RAGFlow API调用失败,响应码: {}, 响应内容: {}", code, responseBody);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 解析RAGFlow API响应时发生IO异常";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.error(errorMessage, e);
|
||||
} catch (Exception e) {
|
||||
log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e);
|
||||
// 构建详细的错误信息,包含异常类型和消息
|
||||
String baseErrorMessage = e.getClass().getSimpleName() + " - 解析RAGFlow API响应失败";
|
||||
String errorMessage = baseErrorMessage + (e.getMessage() != null ? ": " + e.getMessage() : "");
|
||||
log.error(errorMessage, e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+124
-175
@@ -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,22 @@ 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");
|
||||
String errorDetail = apiMessage != null ? apiMessage : "无详细错误信息";
|
||||
log.error("RAGFlow API调用失败,响应码: {}, 错误详情: {}", 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("=== 获取文档列表操作结束 ===");
|
||||
}
|
||||
@@ -480,8 +471,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 +496,21 @@ 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 : "无详细错误信息";
|
||||
log.error("RAGFlow API调用失败详情: {}", 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) {
|
||||
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 +566,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 +598,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 +690,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 +814,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 +911,41 @@ 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 : "无详细错误信息";
|
||||
log.error("RAGFlow API调用失败详情: {}", errorDetail);
|
||||
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 +1062,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 +1076,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 +1167,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 +1185,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 +1265,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 +1285,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 +1691,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 +1712,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("=== 召回测试操作结束 ===");
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@
|
||||
10164=RAG\u914D\u7F6E\u672A\u627E\u5230
|
||||
10165=RAG\u914D\u7F6E\u7C7B\u578B\u9519\u8BEF
|
||||
10166=\u9ED8\u8BA4RAG\u914D\u7F6E\u672A\u627E\u5230
|
||||
10167=RAG\u63A5\u53E3\u9519\u8BEF\uFF0C{0}
|
||||
10167=\u0052\u0041\u0047\u8c03\u7528\u5931\u8d25\uFF0C{0}
|
||||
10168=\u4E0A\u4F20\u6587\u4EF6\u5931\u8D25
|
||||
10169=\u60A8\u6CA1\u6709\u6743\u9650\u64CD\u4F5C\u8BE5\u8BB0\u5F55
|
||||
10170=\u77E5\u8BC6\u5E93\u540D\u79F0\u91CD\u590D
|
||||
@@ -173,7 +173,11 @@
|
||||
10164=RAG configuration not found
|
||||
10165=RAG configuration type error
|
||||
10166=Default RAG configuration not found
|
||||
10167=RAG API interface error: {0}
|
||||
10167=RAG API call failed: {0}
|
||||
10168=Upload file failed
|
||||
10169=No permission to operate this knowledge base
|
||||
10170=Knowledge base name already exists
|
||||
10170=Knowledge base name already exists
|
||||
10171=RAG configuration base_url cannot be empty
|
||||
10172=RAG configuration api_key cannot be empty
|
||||
10173=RAG configuration api_key cannot contain placeholder, please replace with actual API key
|
||||
10174=RAG configuration base_url format error, must start with http or https
|
||||
|
||||
@@ -173,7 +173,11 @@
|
||||
10164=RAG\u914D\u7F6E\u672A\u627E\u5230
|
||||
10165=RAG\u914D\u7F6E\u7C7B\u578B\u9519\u8BEF
|
||||
10166=\u9ED8\u8BA4RAG\u914D\u7F6E\u672A\u627E\u5230
|
||||
10167=RAG\u63A5\u53E3\u9519\u8BEF\uFF0C{0}
|
||||
10167=\u0052\u0041\u0047\u8c03\u7528\u5931\u8d25\uFF0C{0}
|
||||
10168=\u4E0A\u4F20\u6587\u4EF6\u5931\u8D25
|
||||
10169=\u60A8\u6CA1\u6709\u6743\u9650\u64CD\u4F5C\u8BE5\u8BB0\u5F55
|
||||
10170=\u77E5\u8BC6\u5E93\u540D\u79F0\u91CD\u590D
|
||||
10170=\u77E5\u8BC6\u5E93\u540D\u79F0\u91CD\u590D
|
||||
10171=\u0052\u0041\u0047\u914D\u7F6E\u4F53\u7684base_url\u4E0D\u80FD\u4E3A\u7A7A
|
||||
10172=\u0052\u0041\u0047\u914D\u7F6E\u4F53\u7684api_key\u4E0D\u80FD\u4E3A\u7A7A
|
||||
10173=\u0052\u0041\u0047\u914D\u7F6E\u4F53\u7684api_key\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u8BF7\u66F4\u6362\u4E3A\u5728\u53D6\u7684API\u53C2\u6570
|
||||
10174=\u0052\u0041\u0047\u914D\u7F6E\u4F53\u7684base_url\u683C\u5F0F\u9519\u8BEF\uFF0C\u5FC5\u987B\u4EE5http\u6216https\u5F00\u5934
|
||||
@@ -173,7 +173,11 @@
|
||||
10164=RAG\u914D\u7F6E\u672A\u627E\u5230
|
||||
10165=RAG\u914D\u7F6E\u985E\u578B\u932F\u8AA4
|
||||
10166=\u9810\u8A2DRAG\u914D\u7F6E\u672A\u627E\u5230
|
||||
10167=RAG\u63A5\u53E3\u932F\u8AA4\uFF0C{0}
|
||||
10167=\u0052\u0041\u0047\u8abf\u7528\u5931\u6557\uFF0C{0}
|
||||
10168=\u4E0A\u50B3\u6587\u4EF6\u5931\u6557
|
||||
10169=\u60A8\u6C92\u6709\u6B0A\u9650\u64CD\u4F5C\u8A72\u8A18\u9304
|
||||
10170=\u77E5\u8B58\u5EAB\u540D\u7A31\u91CD\u8907
|
||||
10171=\u0052\u0041\u0047\u914D\u7F6E\u4F53\u7684base_url\u4E0D\u80FD\u4E3A\u7A7A
|
||||
10172=\u0052\u0041\u0047\u914D\u7F6E\u4F53\u7684api_key\u4E0D\u80FD\u4E3A\u7A7A
|
||||
10173=\u0052\u0041\u0047\u914D\u7F6E\u4F53\u7684api_key\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u8BF7\u66F4\u6362\u4E3A\u5728\u53D6\u7684API\u53C2\u6570
|
||||
10174=\u0052\u0041\u0047\u914D\u7F6E\u4F53\u7684base_url\u683C\u5F0F\u9519\u8BEF\uFF0C\u5FC5\u987B\u4EE5http\u6216https\u5F00\u5934
|
||||
|
||||
@@ -72,6 +72,11 @@ export default {
|
||||
}
|
||||
],
|
||||
description: [
|
||||
{
|
||||
required: true,
|
||||
message: this.$t("knowledgeBaseDialog.descriptionRequired"),
|
||||
trigger: "blur"
|
||||
},
|
||||
{
|
||||
max: 200,
|
||||
message: this.$t("knowledgeBaseDialog.descriptionLength"),
|
||||
|
||||
@@ -1183,7 +1183,7 @@ export default {
|
||||
'knowledgeBaseDialog.descriptionLengthLimit': 'Knowledge base description cannot exceed 200 characters',
|
||||
|
||||
// Knowledge Base Management page new view button text
|
||||
'knowledgeBaseManagement.view': 'View',
|
||||
'knowledgeBaseManagement.view': 'Manage Files',
|
||||
|
||||
// Knowledge File Upload page text
|
||||
'knowledgeFileUpload.back': 'Back',
|
||||
@@ -1215,7 +1215,7 @@ export default {
|
||||
'knowledgeFileUpload.statusProcessing': 'Processing',
|
||||
'knowledgeFileUpload.statusCancelled': 'Cancelled',
|
||||
'knowledgeFileUpload.statusCompleted': 'Completed',
|
||||
'knowledgeFileUpload.statusFailed': 'Parse Failed',
|
||||
'knowledgeFileUpload.statusFailed': 'Failed',
|
||||
'knowledgeFileUpload.uploadSuccess': 'Document upload successful',
|
||||
'knowledgeFileUpload.uploadFailed': 'Document upload failed',
|
||||
'knowledgeFileUpload.parseSuccess': 'Document parse successful',
|
||||
@@ -1259,4 +1259,5 @@ export default {
|
||||
'knowledgeFileUpload.comprehensiveSimilarity': 'Comprehensive Similarity',
|
||||
'knowledgeFileUpload.content': 'Content:',
|
||||
'knowledgeFileUpload.testQuestionRequired': 'Please enter test question',
|
||||
'knowledgeBaseDialog.descriptionRequired': 'Please enter knowledge base description',
|
||||
}
|
||||
@@ -1183,7 +1183,7 @@ export default {
|
||||
'knowledgeBaseDialog.descriptionLengthLimit': '知识库描述不能超过200个字符',
|
||||
|
||||
// 知识库管理页面新增查看按钮文本
|
||||
'knowledgeBaseManagement.view': '查看',
|
||||
'knowledgeBaseManagement.view': '管理文件',
|
||||
|
||||
// 上传文件页面文本
|
||||
'knowledgeFileUpload.back': '返回',
|
||||
@@ -1215,7 +1215,7 @@ export default {
|
||||
'knowledgeFileUpload.statusProcessing': '处理中',
|
||||
'knowledgeFileUpload.statusCancelled': '已取消',
|
||||
'knowledgeFileUpload.statusCompleted': '已完成',
|
||||
'knowledgeFileUpload.statusFailed': '解析失败',
|
||||
'knowledgeFileUpload.statusFailed': '失败',
|
||||
'knowledgeFileUpload.uploadSuccess': '文档上传成功',
|
||||
'knowledgeFileUpload.uploadFailed': '文档上传失败',
|
||||
'knowledgeFileUpload.parseSuccess': '文档解析成功',
|
||||
@@ -1259,4 +1259,5 @@ export default {
|
||||
'knowledgeFileUpload.comprehensiveSimilarity': '综合相似度',
|
||||
'knowledgeFileUpload.content': '内容:',
|
||||
'knowledgeFileUpload.testQuestionRequired': '请输入测试问题',
|
||||
'knowledgeBaseDialog.descriptionRequired': '请输入知识库描述',
|
||||
}
|
||||
@@ -1183,7 +1183,7 @@ export default {
|
||||
'knowledgeBaseDialog.descriptionLengthLimit': '知識庫描述不能超過200個字符',
|
||||
|
||||
// 知識庫管理頁面查看按鈕文本
|
||||
'knowledgeBaseManagement.view': '查看',
|
||||
'knowledgeBaseManagement.view': '管理文件',
|
||||
|
||||
// 知識庫文件上傳頁面文本
|
||||
'knowledgeFileUpload.back': '返回',
|
||||
@@ -1215,6 +1215,7 @@ export default {
|
||||
'knowledgeFileUpload.statusProcessing': '處理中',
|
||||
'knowledgeFileUpload.statusCancelled': '已取消',
|
||||
'knowledgeFileUpload.statusCompleted': '已完成',
|
||||
'knowledgeFileUpload.statusFailed': '失敗',
|
||||
'knowledgeFileUpload.uploadSuccess': '文檔上傳成功',
|
||||
'knowledgeFileUpload.uploadFailed': '文檔上傳失敗',
|
||||
'knowledgeFileUpload.parseSuccess': '文檔解析成功',
|
||||
@@ -1258,4 +1259,5 @@ export default {
|
||||
'knowledgeFileUpload.comprehensiveSimilarity': '綜合相似度',
|
||||
'knowledgeFileUpload.content': '內容:',
|
||||
'knowledgeFileUpload.testQuestionRequired': '請輸入測試問題',
|
||||
'knowledgeBaseDialog.descriptionRequired': '請輸入知识库描述',
|
||||
}
|
||||
@@ -273,11 +273,9 @@ export default {
|
||||
handleSubmit: function(form) {
|
||||
console.log('handleSubmit called with form:', form);
|
||||
if (form.id) {
|
||||
// 编辑 - 使用dataset_id作为路径参数,form作为请求体
|
||||
console.log('Editing knowledge base:', form.datasetId);
|
||||
Api.knowledgeBase.updateKnowledgeBase(form.datasetId, form, (res) => {
|
||||
console.log('Update response:', res);
|
||||
// 修复:检查 res.data.code 而不是 res.code
|
||||
if (res.data && res.data.code === 0) {
|
||||
this.dialogVisible = false;
|
||||
this.fetchKnowledgeBaseList();
|
||||
@@ -285,8 +283,15 @@ export default {
|
||||
} else {
|
||||
this.$message.error(res.data?.msg || this.$t('knowledgeBaseManagement.updateFailed'));
|
||||
}
|
||||
}, () => {
|
||||
this.$message.error(this.$t('knowledgeBaseManagement.updateFailed'));
|
||||
}, (err) => {
|
||||
console.log('Error callback received:', err);
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
console.log('后端返回错误消息:', err.data.msg || err.msg);
|
||||
this.$message.error(err.data.msg || err.msg || this.$t('knowledgeBaseManagement.updateFailed'));
|
||||
} else {
|
||||
this.$message.error(this.$t('knowledgeBaseManagement.updateFailed'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 新增 - 只传递必要的字段,不传递id
|
||||
@@ -303,6 +308,8 @@ export default {
|
||||
this.dialogVisible = false;
|
||||
this.fetchKnowledgeBaseList();
|
||||
this.$message.success(this.$t('knowledgeBaseManagement.addSuccess'));
|
||||
} else {
|
||||
this.$message.error(res.data?.msg || this.$t('knowledgeBaseManagement.addFailed'));
|
||||
}
|
||||
}, (err) => {
|
||||
console.log('Error callback received:', err);
|
||||
@@ -338,8 +345,15 @@ export default {
|
||||
} else {
|
||||
this.$message.error(res.data?.msg || this.$t('knowledgeBaseManagement.deleteFailed'));
|
||||
}
|
||||
}, () => {
|
||||
this.$message.error(this.$t('knowledgeBaseManagement.deleteFailed'));
|
||||
}, (err) => {
|
||||
console.log('Error callback received:', err);
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
console.log('后端返回错误消息:', err.data.msg || err.msg);
|
||||
this.$message.error(err.data.msg || err.msg || this.$t('knowledgeBaseManagement.deleteFailed'));
|
||||
} else {
|
||||
this.$message.error(this.$t('knowledgeBaseManagement.deleteFailed'));
|
||||
}
|
||||
});
|
||||
}).catch(() => {
|
||||
this.$message({
|
||||
@@ -365,8 +379,15 @@ export default {
|
||||
} else {
|
||||
this.$message.error(res.data?.msg || this.$t('knowledgeBaseManagement.deleteFailed'));
|
||||
}
|
||||
}, () => {
|
||||
this.$message.error(this.$t('knowledgeBaseManagement.deleteFailed'));
|
||||
}, (err) => {
|
||||
console.log('Error callback received:', err);
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
console.log('后端返回错误消息:', err.data.msg || err.msg);
|
||||
this.$message.error(err.data.msg || err.msg || this.$t('knowledgeBaseManagement.deleteFailed'));
|
||||
} else {
|
||||
this.$message.error(this.$t('knowledgeBaseManagement.deleteFailed'));
|
||||
}
|
||||
});
|
||||
}).catch(() => {
|
||||
this.$message({
|
||||
|
||||
@@ -401,7 +401,13 @@ export default {
|
||||
},
|
||||
(err) => {
|
||||
this.loading = false;
|
||||
this.$message.error(this.$t('knowledgeFileUpload.getListFailed'));
|
||||
console.log('Error callback received:', err);
|
||||
if (err && err.data) {
|
||||
console.log('后端返回错误消息:', err.data.msg || err.msg);
|
||||
this.$message.error(err.data.msg || err.msg || this.$t('knowledgeFileUpload.getListFailed'));
|
||||
} else {
|
||||
this.$message.error(this.$t('knowledgeFileUpload.getListFailed'));
|
||||
}
|
||||
console.error('获取文档列表失败:', err);
|
||||
this.fileList = [];
|
||||
this.total = 0;
|
||||
@@ -657,7 +663,12 @@ export default {
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
reject({ success: false, fileName: file.name, error: this.$t('knowledgeFileUpload.uploadFailed') });
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
reject({ success: false, fileName: file.name, error: err.data.msg || err.msg || this.$t('knowledgeFileUpload.uploadFailed') });
|
||||
} else {
|
||||
reject({ success: false, fileName: file.name, error: this.$t('knowledgeFileUpload.uploadFailed') });
|
||||
}
|
||||
console.error('上传文档失败:', err);
|
||||
}
|
||||
);
|
||||
@@ -718,7 +729,12 @@ export default {
|
||||
},
|
||||
(err) => {
|
||||
this.uploading = false;
|
||||
this.$message.error(this.$t('knowledgeFileUpload.uploadFailed'));
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
this.$message.error(err.data.msg || err.msg || this.$t('knowledgeFileUpload.uploadFailed'));
|
||||
} else {
|
||||
this.$message.error(this.$t('knowledgeFileUpload.uploadFailed'));
|
||||
}
|
||||
console.error('上传文档失败:', err);
|
||||
}
|
||||
);
|
||||
@@ -751,7 +767,12 @@ export default {
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
this.$message.error(this.$t('knowledgeFileUpload.parseFailed'));
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
this.$message.error(err.data.msg || err.msg || this.$t('knowledgeFileUpload.parseFailed'));
|
||||
} else {
|
||||
this.$message.error(this.$t('knowledgeFileUpload.parseFailed'));
|
||||
}
|
||||
console.error('解析文档失败:', err);
|
||||
}
|
||||
);
|
||||
@@ -784,7 +805,12 @@ export default {
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
this.$message.error(this.$t('knowledgeFileUpload.deleteFailed'));
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
this.$message.error(err.data.msg || err.msg || this.$t('knowledgeFileUpload.deleteFailed'));
|
||||
} else {
|
||||
this.$message.error(this.$t('knowledgeFileUpload.deleteFailed'));
|
||||
}
|
||||
console.error('删除文档失败:', err);
|
||||
}
|
||||
);
|
||||
@@ -829,7 +855,12 @@ export default {
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
reject(this.$t('knowledgeFileUpload.deleteFailed'));
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
reject(err.data.msg || err.msg || this.$t('knowledgeFileUpload.deleteFailed'));
|
||||
} else {
|
||||
reject(this.$t('knowledgeFileUpload.deleteFailed'));
|
||||
}
|
||||
console.error('删除文档失败:', err);
|
||||
}
|
||||
);
|
||||
@@ -938,7 +969,12 @@ export default {
|
||||
},
|
||||
(err) => {
|
||||
this.sliceLoading = false;
|
||||
this.$message.error('获取切片列表失败');
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
this.$message.error(err.data.msg || err.msg || '获取切片列表失败');
|
||||
} else {
|
||||
this.$message.error('获取切片列表失败');
|
||||
}
|
||||
console.error('获取切片列表失败:', err);
|
||||
this.sliceList = [];
|
||||
this.sliceTotal = 0;
|
||||
@@ -1055,7 +1091,12 @@ export default {
|
||||
},
|
||||
(err) => {
|
||||
this.retrievalTestLoading = false;
|
||||
this.$message.error('召回测试失败');
|
||||
// 错误回调处理后端返回的错误信息
|
||||
if (err && err.data) {
|
||||
this.$message.error(err.data.msg || err.msg || '召回测试失败');
|
||||
} else {
|
||||
this.$message.error('召回测试失败');
|
||||
}
|
||||
console.error('召回测试失败:', err);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
<div><strong>功能名称:</strong> {{ func.name }}</div>
|
||||
</div>
|
||||
<div class="icon-dot" :style="{ backgroundColor: getFunctionColor(func.name) }">
|
||||
{{ func.name.charAt(0) }}
|
||||
{{ getFunctionDisplayChar(func.name) }}
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<el-button class="edit-function-btn" @click="openFunctionDialog"
|
||||
@@ -432,6 +432,19 @@ export default {
|
||||
const hash = [...name].reduce((acc, char) => acc + char.charCodeAt(0), 0);
|
||||
return this.functionColorMap[hash % this.functionColorMap.length];
|
||||
},
|
||||
getFunctionDisplayChar(name) {
|
||||
if (!name || name.length === 0) return '';
|
||||
|
||||
for (let i = 0; i < name.length; i++) {
|
||||
const char = name[i];
|
||||
if (/[\u4e00-\u9fa5a-zA-Z0-9]/.test(char)) {
|
||||
return char;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有找到有效字符,返回第一个字符
|
||||
return name.charAt(0);
|
||||
},
|
||||
showFunctionIcons(type) {
|
||||
return type === 'Intent' &&
|
||||
this.form.model.intentModelId !== 'Intent_nointent';
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
- 查询**详细农历信息**(宜忌、八字、节气等)。
|
||||
- 除上述例外外的**任何其他信息或操作请求**(如查新闻、订闹钟、算数学、查非本地天气等)。
|
||||
- 我已经给你装了摄像头,如果用户说“拍照”,你需要调用self_camera_take_photo工具说一下你看到了什么。默认question的参数是“描述一下看到的物品”
|
||||
- 当工具列表包含search_from_ragflow,说明可以使用知识库,你应该结合用户上下文意图并结合知识库的使用描述,推断是否要调用调用知识库。
|
||||
</tool_calling>
|
||||
|
||||
<context>
|
||||
|
||||
@@ -224,7 +224,10 @@ def check_ffmpeg_installed() -> bool:
|
||||
error_msg.append("⚠️ 发现缺少依赖库:libiconv.so.2")
|
||||
error_msg.append("解决方法:在当前 conda 环境中执行:")
|
||||
error_msg.append(" conda install -c conda-forge libiconv\n")
|
||||
elif "no such file or directory" in stderr_output and "ffmpeg" in stderr_output.lower():
|
||||
elif (
|
||||
"no such file or directory" in stderr_output
|
||||
and "ffmpeg" in stderr_output.lower()
|
||||
):
|
||||
error_msg.append("⚠️ 系统未找到 ffmpeg 可执行文件。")
|
||||
error_msg.append("解决方法:在当前 conda 环境中执行:")
|
||||
error_msg.append(" conda install -c conda-forge ffmpeg\n")
|
||||
@@ -245,7 +248,9 @@ def extract_json_from_string(input_string):
|
||||
return None
|
||||
|
||||
|
||||
def audio_to_data_stream(audio_file_path, is_opus=True, callback: Callable[[Any], Any]=None) -> None:
|
||||
def audio_to_data_stream(
|
||||
audio_file_path, is_opus=True, callback: Callable[[Any], Any] = None
|
||||
) -> None:
|
||||
# 获取文件后缀名
|
||||
file_type = os.path.splitext(audio_file_path)[1]
|
||||
if file_type:
|
||||
@@ -262,6 +267,7 @@ def audio_to_data_stream(audio_file_path, is_opus=True, callback: Callable[[Any]
|
||||
raw_data = audio.raw_data
|
||||
pcm_to_data_stream(raw_data, is_opus, callback)
|
||||
|
||||
|
||||
def audio_to_data(audio_file_path: str, is_opus: bool = True) -> list[bytes]:
|
||||
"""
|
||||
将音频文件转换为Opus/PCM编码的帧列表
|
||||
@@ -313,7 +319,10 @@ def audio_to_data(audio_file_path: str, is_opus: bool = True) -> list[bytes]:
|
||||
|
||||
return datas
|
||||
|
||||
def audio_bytes_to_data_stream(audio_bytes, file_type, is_opus, callback: Callable[[Any], Any]) -> None:
|
||||
|
||||
def audio_bytes_to_data_stream(
|
||||
audio_bytes, file_type, is_opus, callback: Callable[[Any], Any]
|
||||
) -> None:
|
||||
"""
|
||||
直接用音频二进制数据转为opus/pcm数据,支持wav、mp3、p3
|
||||
"""
|
||||
@@ -357,6 +366,7 @@ def pcm_to_data_stream(raw_data, is_opus=True, callback: Callable[[Any], Any] =
|
||||
frame_data = chunk if isinstance(chunk, bytes) else bytes(chunk)
|
||||
callback(frame_data)
|
||||
|
||||
|
||||
def opus_datas_to_wav_bytes(opus_datas, sample_rate=16000, channels=1):
|
||||
"""
|
||||
将opus帧列表解码为wav字节流
|
||||
@@ -383,6 +393,7 @@ def opus_datas_to_wav_bytes(opus_datas, sample_rate=16000, channels=1):
|
||||
wf.writeframes(pcm_bytes)
|
||||
return wav_buffer.getvalue()
|
||||
|
||||
|
||||
def check_vad_update(before_config, new_config):
|
||||
if (
|
||||
new_config.get("selected_module") is None
|
||||
@@ -456,6 +467,17 @@ def filter_sensitive_info(config: dict) -> dict:
|
||||
filtered[k] = _filter_dict(v)
|
||||
elif isinstance(v, list):
|
||||
filtered[k] = [_filter_dict(i) if isinstance(i, dict) else i for i in v]
|
||||
elif isinstance(v, str):
|
||||
try:
|
||||
json_data = json.loads(v)
|
||||
if isinstance(json_data, dict):
|
||||
filtered[k] = json.dumps(
|
||||
_filter_dict(json_data), ensure_ascii=False
|
||||
)
|
||||
else:
|
||||
filtered[k] = v
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
filtered[k] = v
|
||||
else:
|
||||
filtered[k] = v
|
||||
return filtered
|
||||
|
||||
@@ -76,7 +76,7 @@ services:
|
||||
- MYSQL_INITDB_ARGS="--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci"
|
||||
# redis模块
|
||||
xiaozhi-esp32-server-redis:
|
||||
image: redis
|
||||
image: redis:8.0
|
||||
expose:
|
||||
- 6379
|
||||
container_name: xiaozhi-esp32-server-redis
|
||||
|
||||
@@ -84,11 +84,12 @@ def search_from_ragflow(conn, question=None):
|
||||
else:
|
||||
contents.append(str(content))
|
||||
|
||||
# 构建适合大模型的上下文内容(每段前加编号,段间两个换行)
|
||||
context_text = "\n\n".join(
|
||||
f"{i+1}. {c.strip()}" for i, c in enumerate(contents[:5])
|
||||
)
|
||||
if not context_text:
|
||||
if contents:
|
||||
# 组织知识库内容为引用模式
|
||||
context_text = f"# 关于问题【{question}】查到知识库如下\n"
|
||||
context_text += "```\n\n\n".join(contents[:5])
|
||||
context_text += "\n```"
|
||||
else:
|
||||
context_text = "根据知识库查询结果,没有相关信息。"
|
||||
return ActionResponse(Action.REQLLM, context_text, None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user