fix:增加RAG配置验证

This commit is contained in:
rainv123
2025-11-05 16:03:19 +08:00
parent 4cde66e7de
commit 1792bf299b
4 changed files with 53 additions and 12 deletions
@@ -595,10 +595,49 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
* 获取RAG配置并验证
*/
private Map<String, Object> getValidatedRAGConfig(String ragModelId) {
Map<String, Object> ragConfig;
if (StringUtils.isNotBlank(ragModelId)) {
return getRAGConfig(ragModelId);
ragConfig = getRAGConfig(ragModelId);
} else {
return getDefaultRAGConfig();
ragConfig = getDefaultRAGConfig();
}
// 验证baseUrl和apiKey
validateRAGConfigParameters(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");
// 验证base_url是否存在且非空
if (StringUtils.isBlank(baseUrl)) {
throw new RenException(ErrorCode.RAG_CONFIG_MISSING_PARAMS, "RAG配置中base_url为空,请完善配置");
}
// 验证apiKey是否存在且非空
if (StringUtils.isBlank(apiKey)) {
throw new RenException(ErrorCode.RAG_CONFIG_MISSING_PARAMS, "RAG配置中api_key为空,请完善配置");
}
// 验证apiKey是否包含"你"字(可能是占位符)
if (apiKey.contains("")) {
throw new RenException(ErrorCode.RAG_CONFIG_MISSING_PARAMS, "RAG配置中api_key包含占位符'你',请替换为实际的API密钥");
}
// 验证baseUrl格式(基本验证)
if (!baseUrl.startsWith("http://") && !baseUrl.startsWith("https://")) {
throw new RenException(ErrorCode.RAG_CONFIG_MISSING_PARAMS, "RAG配置中base_url格式不正确,必须以http://或https://开头");
}
}
@@ -8,7 +8,7 @@ INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `f
-- 添加RAG模型配置
delete from `ai_model_config` where id = 'RAG_RAGFlow';
INSERT INTO `ai_model_config` VALUES ('RAG_RAGFlow', 'RAG', 'ragflow', 'RAGFlow', 1, 1, '{"type": "ragflow", "base_url": "http://localhost", "api_key": "your_api_key_here"}', 'https://github.com/infiniflow/ragflow/blob/main/README_zh.md', 'RAGFlow配置说明:
INSERT INTO `ai_model_config` VALUES ('RAG_RAGFlow', 'RAG', 'ragflow', 'RAGFlow', 1, 1, '{"type": "ragflow", "base_url": "http://localhost", "api_key": "你的RAG密钥"}', 'https://github.com/infiniflow/ragflow/blob/main/README_zh.md', 'RAGFlow配置说明:
docker部署
1.$ sysctl vm.max_map_count
2.$ sysctl -w vm.max_map_count=262144
@@ -403,12 +403,12 @@ databaseChangeLog:
encoding: utf8
path: classpath:db/changelog/202510191042.sql
- changeSet:
id: 202510250955
id: 202510250956
author: rainv123
changes:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202510250955.sql
path: classpath:db/changelog/202510250956.sql
- changeSet:
id: 202510251150
author: rainv123