Files
app/wei_ai_app/supabase/migrations/004_create_llm_config.sql
2026-01-28 20:28:38 +08:00

60 lines
1.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =============================================
-- Wei AI App - LLM 配置表
-- 版本: 1.0.0
-- 日期: 2026-01-28
-- =============================================
-- LLM 配置表(简化版)
CREATE TABLE IF NOT EXISTS llm_config (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- 基本信息
name TEXT NOT NULL DEFAULT '默认配置',
is_active BOOLEAN DEFAULT true,
-- API 连接
api_base_url TEXT NOT NULL,
api_key TEXT NOT NULL,
model TEXT NOT NULL,
-- 模型参数
temperature REAL DEFAULT 0.7,
max_tokens INTEGER DEFAULT 2048,
stream BOOLEAN DEFAULT true,
-- 时间戳
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
-- 更新时间触发器
CREATE TRIGGER update_llm_config_updated_at
BEFORE UPDATE ON llm_config
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
-- RLS 策略
ALTER TABLE llm_config ENABLE ROW LEVEL SECURITY;
-- 允许读取(开发阶段)
CREATE POLICY "Allow anon read llm_config"
ON llm_config FOR SELECT
USING (true);
-- 注释
COMMENT ON TABLE llm_config IS 'LLM 全局配置表';
COMMENT ON COLUMN llm_config.api_key IS 'API 密钥(生产环境建议使用 Vault 或环境变量)';
-- 插入默认配置Grok
-- 注意:请替换 YOUR_GROK_API_KEY_HERE 为真实的 API Key
INSERT INTO llm_config (name, api_base_url, api_key, model, temperature, max_tokens, stream)
VALUES (
'默认配置',
'https://api.x.ai/v1',
'YOUR_GROK_API_KEY_HERE',
'grok-beta',
0.7,
2048,
true
) ON CONFLICT DO NOTHING;