mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat: 公司 LLM 改为提供商凭证加多模型勾选并支持探测目录
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
-- 公司 LLM:凭证(一套 base_url/key)+ 多模型勾选;从旧单表迁移
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `agent_company_llm_provider` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`base_url` varchar(500) NOT NULL COMMENT 'OpenAI Compatible Base URL',
|
||||
`api_key_encrypted` varchar(2000) NOT NULL COMMENT 'API Key 密文',
|
||||
`api_key_suffix` varchar(16) NOT NULL DEFAULT '' COMMENT 'Key 末几位(展示掩码)',
|
||||
`display_name` varchar(100) NULL COMMENT '展示名,如 DeepSeek',
|
||||
`extra_headers_json` json NULL COMMENT '可选额外请求头',
|
||||
`create_by` bigint UNSIGNED NULL COMMENT '创建人用户ID',
|
||||
`update_by` bigint UNSIGNED NULL COMMENT '更新人用户ID',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_agent_llm_provider_company` (`company_id`),
|
||||
CONSTRAINT `fk_agent_llm_provider_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='公司 Agent LLM 提供商凭证';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `agent_company_llm_model` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`model` varchar(200) NOT NULL COMMENT '提供商模型 id',
|
||||
`label` varchar(200) NULL COMMENT '展示名',
|
||||
`context_window` int UNSIGNED NULL COMMENT '上下文窗口 token,空则 Agent 估计',
|
||||
`is_default` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否默认聊天模型',
|
||||
`create_by` bigint UNSIGNED NULL,
|
||||
`update_by` bigint UNSIGNED NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_agent_llm_model_company_model` (`company_id`, `model`),
|
||||
KEY `idx_agent_llm_model_company_default` (`company_id`, `is_default`),
|
||||
CONSTRAINT `fk_agent_llm_model_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='公司已启用的 LLM 模型';
|
||||
|
||||
INSERT INTO `agent_company_llm_provider` (
|
||||
`company_id`, `base_url`, `api_key_encrypted`, `api_key_suffix`,
|
||||
`extra_headers_json`, `create_by`, `update_by`, `create_time`, `update_time`
|
||||
)
|
||||
SELECT
|
||||
`company_id`, `base_url`, `api_key_encrypted`, `api_key_suffix`,
|
||||
`extra_headers_json`, `create_by`, `update_by`, `create_time`, `update_time`
|
||||
FROM `agent_company_llm_settings` s
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `agent_company_llm_provider` p WHERE p.company_id = s.company_id
|
||||
);
|
||||
|
||||
-- 依赖 V20260920 已添加 context_window;若环境无该列请先执行 V20260920
|
||||
INSERT INTO `agent_company_llm_model` (
|
||||
`company_id`, `model`, `context_window`, `is_default`,
|
||||
`create_by`, `update_by`, `create_time`, `update_time`
|
||||
)
|
||||
SELECT
|
||||
`company_id`, `model`, `context_window`, 1,
|
||||
`create_by`, `update_by`, `create_time`, `update_time`
|
||||
FROM `agent_company_llm_settings` s
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `agent_company_llm_model` m
|
||||
WHERE m.company_id = s.company_id AND m.model = s.model
|
||||
);
|
||||
|
||||
RENAME TABLE `agent_company_llm_settings` TO `agent_company_llm_settings_deprecated`;
|
||||
Reference in New Issue
Block a user