Browse Source

中移除 AI 大模型配置相关的初始化数据

dev-mcp
wanghanlin 4 weeks ago
parent
commit
f73aee1616
  1. 73
      src/main/java/com/wok/supportbot/config/DatabaseInitConfig.java
  2. 67
      src/main/resources/init-database.sql

73
src/main/java/com/wok/supportbot/config/DatabaseInitConfig.java

@ -3,7 +3,6 @@ package com.wok.supportbot.config;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
@ -18,9 +17,6 @@ public class DatabaseInitConfig {
@Autowired
private JdbcTemplate jdbcTemplate;
@Value("${spring.ai.dashscope.api-key:}")
private String dashscopeApiKey;
@PostConstruct
public void init() {
try {
@ -79,9 +75,6 @@ public class DatabaseInitConfig {
syncDefaultCustomerServiceRoles();
syncDefaultCustomerAccounts();
createAiModelConfigTable();
seedDefaultAiModelConfigs();
log.info("数据库初始化完成");
} catch (Exception e) {
log.error("数据库初始化失败", e);
@ -355,70 +348,4 @@ public class DatabaseInitConfig {
}
}
private void createAiModelConfigTable() {
String sql = """
CREATE TABLE IF NOT EXISTS ai_model_config (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
app_type VARCHAR(50) NOT NULL,
provider VARCHAR(50) NOT NULL DEFAULT 'dashscope',
api_key VARCHAR(512) NOT NULL,
model_name VARCHAR(100) NOT NULL,
temperature DOUBLE PRECISION DEFAULT 0.7,
max_tokens INTEGER DEFAULT 2000,
base_url VARCHAR(512),
extra_config JSONB DEFAULT '{}' NOT NULL,
is_active BOOLEAN DEFAULT FALSE NOT NULL,
priority INTEGER DEFAULT 0 NOT NULL,
description TEXT,
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
is_delete BOOLEAN DEFAULT FALSE NOT NULL
)
""";
jdbcTemplate.execute(sql);
jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_ai_model_config_app_type ON ai_model_config (app_type)");
jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_ai_model_config_is_active ON ai_model_config (is_active)");
jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_ai_model_config_provider ON ai_model_config (provider)");
}
private void seedDefaultAiModelConfigs() {
Integer count = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM ai_model_config WHERE is_delete = false",
Integer.class);
if (count != null && count > 0) {
return;
}
// yml 未配置 api-key 时种子值留空不影响启动用户需在前端AI 大模型配置管理页面填入 api_key 后才能调用 AI 功能
if (dashscopeApiKey == null || dashscopeApiKey.isBlank()) {
log.warn("未检测到 spring.ai.dashscope.api-key,已写入空 api_key 的默认配置;" +
"请在前端「AI 大模型配置管理」页面为各应用类型填入 API Key 后再使用 AI 功能");
}
insertDefaultModelConfig("Chat Default", "CHAT", "dashscope",
dashscopeApiKey, "qwen-turbo", 0.7, 2000,
true, 100, "Default chat model config");
insertDefaultModelConfig("Product Extract Default", "PRODUCT_EXTRACT", "dashscope",
dashscopeApiKey, "qwen-turbo", 0.3, 2000,
true, 90, "Default product extraction model config");
insertDefaultModelConfig("Embedding Default", "EMBEDDING", "dashscope",
dashscopeApiKey, "text-embedding-v2", null, null,
true, 80, "Default embedding model config");
insertDefaultModelConfig("RAG Rewrite Default", "RAG_REWRITE", "dashscope",
dashscopeApiKey, "qwen-turbo", 0.5, 1000,
true, 70, "Default RAG rewrite model config");
}
private void insertDefaultModelConfig(String name, String appType, String provider,
String apiKey, String modelName, Double temperature,
Integer maxTokens, boolean isActive, int priority,
String description) {
jdbcTemplate.update("""
INSERT INTO ai_model_config (name, app_type, provider, api_key, model_name, temperature, max_tokens, is_active, priority, description)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", name, appType, provider, apiKey, modelName, temperature, maxTokens, isActive, priority, description);
}
}

67
src/main/resources/init-database.sql

@ -255,68 +255,7 @@ COMMENT ON COLUMN conversation_session.create_time IS '创建时间';
COMMENT ON COLUMN conversation_session.update_time IS '更新时间';
-- ============================================================
-- 表 8: ai_model_config — AI 大模型配置表
-- ============================================================
CREATE TABLE IF NOT EXISTS ai_model_config (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
app_type VARCHAR(50) NOT NULL,
provider VARCHAR(50) NOT NULL DEFAULT 'dashscope',
api_key VARCHAR(512) NOT NULL,
model_name VARCHAR(100) NOT NULL,
temperature DOUBLE PRECISION DEFAULT 0.7,
max_tokens INTEGER DEFAULT 2000,
base_url VARCHAR(512),
extra_config JSONB NOT NULL DEFAULT '{}',
is_active BOOLEAN NOT NULL DEFAULT FALSE,
priority INTEGER NOT NULL DEFAULT 0,
description TEXT,
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
is_delete BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE INDEX IF NOT EXISTS idx_ai_model_config_app_type ON ai_model_config (app_type);
CREATE INDEX IF NOT EXISTS idx_ai_model_config_is_active ON ai_model_config (is_active);
CREATE INDEX IF NOT EXISTS idx_ai_model_config_provider ON ai_model_config (provider);
COMMENT ON TABLE ai_model_config IS 'AI 大模型配置表';
COMMENT ON COLUMN ai_model_config.id IS '主键';
COMMENT ON COLUMN ai_model_config.name IS '配置名称';
COMMENT ON COLUMN ai_model_config.app_type IS '应用类型: CHAT / PRODUCT_EXTRACT / EMBEDDING / RAG_REWRITE';
COMMENT ON COLUMN ai_model_config.provider IS '模型提供商';
COMMENT ON COLUMN ai_model_config.api_key IS 'API Key';
COMMENT ON COLUMN ai_model_config.model_name IS '模型名称';
COMMENT ON COLUMN ai_model_config.temperature IS '温度参数';
COMMENT ON COLUMN ai_model_config.max_tokens IS '最大Token数';
COMMENT ON COLUMN ai_model_config.base_url IS 'API 基础地址';
COMMENT ON COLUMN ai_model_config.extra_config IS '扩展配置(JSON,如向量维度等)';
COMMENT ON COLUMN ai_model_config.is_active IS '是否活跃(同类型互斥)';
COMMENT ON COLUMN ai_model_config.priority IS '优先级';
COMMENT ON COLUMN ai_model_config.description IS '描述';
COMMENT ON COLUMN ai_model_config.create_time IS '创建时间';
COMMENT ON COLUMN ai_model_config.update_time IS '更新时间';
COMMENT ON COLUMN ai_model_config.is_delete IS '逻辑删除';
-- 默认模型配置种子数据(api_key 占位,部署后在前端修改)
INSERT INTO ai_model_config (name, app_type, provider, api_key, model_name, temperature, max_tokens, is_active, description)
VALUES ('Chat Default', 'CHAT', 'dashscope', 'sk-placeholder', 'qwen-turbo', 0.7, 2000, TRUE, '默认对话模型配置')
ON CONFLICT DO NOTHING;
INSERT INTO ai_model_config (name, app_type, provider, api_key, model_name, temperature, max_tokens, is_active, description)
VALUES ('Product Extract Default', 'PRODUCT_EXTRACT', 'dashscope', 'sk-placeholder', 'qwen-turbo', 0.1, 2000, TRUE, '默认产品信息提取模型配置')
ON CONFLICT DO NOTHING;
INSERT INTO ai_model_config (name, app_type, provider, api_key, model_name, temperature, max_tokens, is_active, extra_config, description)
VALUES ('Embedding Default', 'EMBEDDING', 'dashscope', 'sk-placeholder', 'text-embedding-v2', 0.0, 2000, TRUE, '{"dimensions": 1024}', '默认向量化模型配置')
ON CONFLICT DO NOTHING;
INSERT INTO ai_model_config (name, app_type, provider, api_key, model_name, temperature, max_tokens, is_active, description)
VALUES ('RAG Rewrite Default', 'RAG_REWRITE', 'dashscope', 'sk-placeholder', 'qwen-turbo', 0.3, 2000, TRUE, '默认 RAG 查询重写模型配置')
ON CONFLICT DO NOTHING;
-- ============================================================
-- 表 9: vector_store — 向量存储表
-- 表 8: vector_store — 向量存储表
-- 注意: Spring AI PgVectorStore 配置了 initializeSchema(true),
-- 应用启动时会自动建表。此处手动建表作为备份方案。
-- 向量维度默认 1024,如使用不同维度的 Embedding 模型
@ -350,7 +289,5 @@ COMMENT ON COLUMN vector_store.update_time IS '更新时间';
-- ============================================================
-- 完成!
-- 共创建 9 张表及对应索引。
-- 默认 api-key 为占位符,请在前端
-- 「AI 大模型配置管理」页面修改为真实值。
-- 共创建 8 张表及对应索引。
-- ============================================================
Loading…
Cancel
Save