修改difyconfig值
This commit is contained in:
@@ -50,6 +50,8 @@ SOURCE createTableSensitive.sql;
|
||||
-- 12. 插入菜单和权限相关数据
|
||||
SOURCE initMenuData.sql;
|
||||
|
||||
SOURCE initConfigData.sql;
|
||||
|
||||
SOURCE initAllData.sql;
|
||||
|
||||
SOURCE initCrontabMetaData.sql
|
||||
|
||||
@@ -24,11 +24,6 @@ INSERT INTO `tb_tag` (id, tag_id, name, color, description, tag_type, creator, c
|
||||
('tag204', 'tag_task_004', '实践任务', '#f7b731', '实践类学习任务', 3, '1', now()),
|
||||
('tag205', 'tag_task_005', '阶段任务', '#2d98da', '阶段性学习任务', 3, '1', now());
|
||||
|
||||
-- 插入系统配置数据
|
||||
INSERT INTO `tb_sys_config` (`id`, `config_key`, `config_name`, `config_value`, `config_type`, `render_type`, `config_group`, `description`, `placeholder`, `remark`, `rows`, `min_value`, `max_value`, `unit`, `options`, `order_num`, `is_system`, `creator`, `create_time`) VALUES
|
||||
('1', 'crawler.pythonPath', 'Python路径', 'F:/Environment/Conda/envs/schoolNewsCrawler/python.exe', 'string', 'input', '爬虫配置', 'Python可执行文件路径', '请输入Python可执行文件完整路径', '爬虫使用的Python解释器路径', NULL, NULL, NULL, NULL, NULL, 1, 1, '1', now()),
|
||||
('2', 'crawler.basePath', '爬虫根目录', 'F:/Project/schoolNews/schoolNewsCrawler', 'string', 'input', '爬虫配置', '爬虫脚本根目录', '请输入爬虫脚本根目录路径', '爬虫脚本文件的根目录', NULL, NULL, NULL, NULL, NULL, 2, 1, '1', now());
|
||||
|
||||
-- 注意:默认superadmin用户已在 initMenuData.sql 中创建,此处无需重复创建
|
||||
|
||||
-- =====================================================
|
||||
|
||||
22
schoolNewsServ/.bin/mysql/sql/initConfigData.sql
Normal file
22
schoolNewsServ/.bin/mysql/sql/initConfigData.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- 插入系统配置数据
|
||||
INSERT INTO `tb_sys_config` (`id`, `config_key`, `config_name`, `config_value`, `config_type`, `render_type`, `config_group`, `description`, `placeholder`, `remark`, `rows`, `min_value`, `max_value`, `unit`, `options`, `order_num`, `is_system`, `creator`, `create_time`) VALUES
|
||||
-- 爬虫配置
|
||||
('1', 'crawler.pythonPath', 'Python路径', 'F:/Environment/Conda/envs/schoolNewsCrawler/python.exe', 'string', 'input', '爬虫配置', 'Python可执行文件路径', '请输入Python可执行文件完整路径', '爬虫使用的Python解释器路径', NULL, NULL, NULL, NULL, NULL, 1, 1, '1', now()),
|
||||
('2', 'crawler.basePath', '爬虫根目录', 'F:/Project/schoolNews/schoolNewsCrawler', 'string', 'input', '爬虫配置', '爬虫脚本根目录', '请输入爬虫脚本根目录路径', '爬虫脚本文件的根目录', NULL, NULL, NULL, NULL, NULL, 2, 1, '1', now()),
|
||||
|
||||
-- Dify基础配置
|
||||
('10', 'dify.apiBaseUrl', 'Dify API地址', 'http://192.168.130.131/v1', 'string', 'input', 'Dify配置', 'Dify API基础地址', '请输入Dify API完整地址', 'Dify服务的API基础地址', NULL, NULL, NULL, NULL, NULL, 10, 1, '1', now()),
|
||||
('11', 'dify.apiKey', 'Dify API密钥', 'app-6VXXDHRC8fiTijeRfnwzOyGn', 'string', 'password', 'Dify配置', 'Dify API密钥', '请输入Dify API密钥', '用于调用Dify API的默认密钥,可被智能体的密钥覆盖', NULL, NULL, NULL, NULL, NULL, 11, 1, '1', now()),
|
||||
('12', 'dify.knowledgeApiKey', '知识库API密钥', 'dataset-nupqKP4LONpzdXmGthIrbjeJ', 'string', 'password', 'Dify配置', '知识库API密钥', '请输入知识库API密钥', '用于访问Dify知识库的API密钥', NULL, NULL, NULL, NULL, NULL, 12, 1, '1', now()),
|
||||
('13', 'dify.timeout', '请求超时时间', '60', 'integer', 'input', 'Dify配置', '请求超时时间(秒)', '请输入超时时间', 'API请求的超时时间', NULL, 10, 600, '秒', NULL, 13, 1, '1', now()),
|
||||
('14', 'dify.connectTimeout', '连接超时时间', '10', 'integer', 'input', 'Dify配置', '连接超时时间(秒)', '请输入连接超时时间', 'API连接的超时时间', NULL, 5, 60, '秒', NULL, 14, 1, '1', now()),
|
||||
('15', 'dify.readTimeout', '读取超时时间', '60', 'integer', 'input', 'Dify配置', '读取超时时间(秒)', '请输入读取超时时间', 'API读取响应的超时时间', NULL, 10, 600, '秒', NULL, 15, 1, '1', now()),
|
||||
('16', 'dify.streamTimeout', '流式响应超时时间', '300', 'integer', 'input', 'Dify配置', '流式响应超时时间(秒)', '请输入流式响应超时时间', '流式API响应的超时时间', NULL, 30, 1800, '秒', NULL, 16, 1, '1', now()),
|
||||
|
||||
-- Dify上传配置
|
||||
('20', 'dify.upload.allowedTypes', '允许的文件类型', 'pdf,txt,docx,doc,md,html,htm', 'string', 'input', 'Dify配置', '上传文件允许的类型', '请输入文件类型,用逗号分隔', '支持上传的文件类型列表', NULL, NULL, NULL, NULL, NULL, 20, 1, '1', now()),
|
||||
('21', 'dify.upload.maxSize', '最大文件大小', '50', 'integer', 'input', 'Dify配置', '最大文件大小(MB)', '请输入最大文件大小', '单个文件上传的最大大小限制', NULL, 1, 500, 'MB', NULL, 21, 1, '1', now()),
|
||||
|
||||
-- Dify知识库配置
|
||||
('30', 'dify.dataset.defaultIndexingTechnique', '默认索引方式', 'high_quality', 'string', 'select', 'Dify配置', '默认索引方式', NULL, '知识库文档的默认索引方式', NULL, NULL, NULL, NULL, 'high_quality,economy', 30, 1, '1', now()),
|
||||
('31', 'dify.dataset.defaultEmbeddingModel', '默认Embedding模型', 'text-embedding-ada-002', 'string', 'input', 'Dify配置', '默认Embedding模型', '请输入Embedding模型名称', '知识库使用的默认Embedding模型', NULL, NULL, NULL, NULL, NULL, 31, 1, '1', now());
|
||||
@@ -1,12 +1,14 @@
|
||||
package org.xyzh.ai.config;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.xyzh.api.system.config.SysConfigService;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @description Dify配置类
|
||||
* @filename DifyConfig.java
|
||||
@@ -14,9 +16,9 @@ import org.xyzh.api.system.config.SysConfigService;
|
||||
* @copyright xyzh
|
||||
* @since 2025-11-04
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "dify")
|
||||
public class DifyConfig {
|
||||
|
||||
@Autowired
|
||||
@@ -55,21 +57,6 @@ public class DifyConfig {
|
||||
*/
|
||||
private Integer streamTimeout = 300;
|
||||
|
||||
/**
|
||||
* 最大重试次数
|
||||
*/
|
||||
private Integer maxRetries = 3;
|
||||
|
||||
/**
|
||||
* 重试间隔(毫秒)
|
||||
*/
|
||||
private Long retryInterval = 1000L;
|
||||
|
||||
/**
|
||||
* 是否启用Dify集成
|
||||
*/
|
||||
private Boolean enabled = true;
|
||||
|
||||
/**
|
||||
* 上传文件配置
|
||||
*/
|
||||
@@ -81,9 +68,69 @@ public class DifyConfig {
|
||||
private Dataset dataset = new Dataset();
|
||||
|
||||
/**
|
||||
* 对话配置
|
||||
* 初始化配置,从数据库加载
|
||||
*/
|
||||
private Chat chat = new Chat();
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
try {
|
||||
log.info("开始从数据库加载Dify配置...");
|
||||
|
||||
// 基础配置
|
||||
loadStringConfig("dify.apiBaseUrl", val -> this.apiBaseUrl = val);
|
||||
loadStringConfig("dify.apiKey", val -> this.apiKey = val);
|
||||
loadStringConfig("dify.knowledgeApiKey", val -> this.knowledgeApiKey = val);
|
||||
loadIntegerConfig("dify.timeout", val -> this.timeout = val);
|
||||
loadIntegerConfig("dify.connectTimeout", val -> this.connectTimeout = val);
|
||||
loadIntegerConfig("dify.readTimeout", val -> this.readTimeout = val);
|
||||
loadIntegerConfig("dify.streamTimeout", val -> this.streamTimeout = val);
|
||||
|
||||
// Upload配置
|
||||
loadStringConfig("dify.upload.allowedTypes", val -> {
|
||||
if (val != null && !val.trim().isEmpty()) {
|
||||
this.upload.allowedTypes = val.split(",");
|
||||
}
|
||||
});
|
||||
loadIntegerConfig("dify.upload.maxSize", val -> this.upload.maxSize = val);
|
||||
|
||||
// Dataset配置
|
||||
loadStringConfig("dify.dataset.defaultIndexingTechnique", val -> this.dataset.defaultIndexingTechnique = val);
|
||||
loadStringConfig("dify.dataset.defaultEmbeddingModel", val -> this.dataset.defaultEmbeddingModel = val);
|
||||
|
||||
log.info("Dify配置加载完成 - API地址: {}", apiBaseUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("加载Dify配置失败,将使用默认值", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载字符串配置
|
||||
*/
|
||||
private void loadStringConfig(String key, java.util.function.Consumer<String> setter) {
|
||||
try {
|
||||
String value = sysConfigService.getStringConfig(key);
|
||||
if (value != null && !value.trim().isEmpty()) {
|
||||
setter.accept(value);
|
||||
log.debug("加载配置: {} = {}", key, value);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("加载配置失败: {}, 错误: {}", key, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载整数配置
|
||||
*/
|
||||
private void loadIntegerConfig(String key, java.util.function.Consumer<Integer> setter) {
|
||||
try {
|
||||
Integer value = sysConfigService.getIntConfig(key);
|
||||
if (value != null) {
|
||||
setter.accept(value);
|
||||
log.debug("加载配置: {} = {}", key, value);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("加载配置失败: {}, 错误: {}", key, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Upload {
|
||||
@@ -96,11 +143,6 @@ public class DifyConfig {
|
||||
* 最大文件大小(MB)
|
||||
*/
|
||||
private Integer maxSize = 50;
|
||||
|
||||
/**
|
||||
* 批量上传最大文件数
|
||||
*/
|
||||
private Integer batchMaxCount = 10;
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -114,56 +156,13 @@ public class DifyConfig {
|
||||
* 默认Embedding模型
|
||||
*/
|
||||
private String defaultEmbeddingModel = "text-embedding-ada-002";
|
||||
|
||||
/**
|
||||
* 文档分段策略
|
||||
*/
|
||||
private String segmentationStrategy = "automatic";
|
||||
|
||||
/**
|
||||
* 分段最大长度
|
||||
*/
|
||||
private Integer maxSegmentLength = 1000;
|
||||
|
||||
/**
|
||||
* 分段重叠长度
|
||||
*/
|
||||
private Integer segmentOverlap = 50;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Chat {
|
||||
/**
|
||||
* 默认温度值
|
||||
*/
|
||||
private Double defaultTemperature = 0.7;
|
||||
|
||||
/**
|
||||
* 默认最大Token数
|
||||
*/
|
||||
private Integer defaultMaxTokens = 2000;
|
||||
|
||||
/**
|
||||
* 默认Top P值
|
||||
*/
|
||||
private Double defaultTopP = 1.0;
|
||||
|
||||
/**
|
||||
* 是否启用流式响应
|
||||
*/
|
||||
private Boolean enableStream = true;
|
||||
|
||||
/**
|
||||
* 对话上下文最大消息数
|
||||
*/
|
||||
private Integer maxContextMessages = 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证配置是否有效
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return enabled && apiBaseUrl != null && !apiBaseUrl.trim().isEmpty();
|
||||
return apiBaseUrl != null && !apiBaseUrl.trim().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user