Files
GovAI/server/cmd/seed-providers/main.go
T
freedakgmail d31bdd1261 feat: 增强聊天功能和 markdown 渲染
- 优化聊天 UI 组件交互体验
- 扩展 markdown 渲染功能支持
- 更新类型定义
- 重构 LLM 聊天处理逻辑
- 更新模型提供商种子数据
2026-06-23 00:46:08 +08:00

73 lines
1.5 KiB
Go

package main
import (
"context"
"fmt"
"log"
"os"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/joho/godotenv"
)
func main() {
_ = godotenv.Load("../../.env")
databaseURL := os.Getenv("DATABASE_URL")
if databaseURL == "" {
log.Fatal("DATABASE_URL 环境变量未设置")
}
ctx := context.Background()
pool, err := pgxpool.New(ctx, databaseURL)
if err != nil {
log.Fatalf("连接数据库失败: %v", err)
}
defer pool.Close()
// 插入阿里云百炼(通义千问)配置
apiKey := os.Getenv("QWEN_API_KEY")
if apiKey == "" {
log.Println("⚠️ QWEN_API_KEY 未设置,跳过初始化千问")
return
}
sql := `
INSERT INTO model_providers (
name,
base_url,
api_key_encrypted,
models,
is_active,
priority,
config
) VALUES (
'阿里云百炼 (通义千问)',
'https://dashscope.aliyuncs.com/compatible-mode/v1',
$1,
'[
{"id": "qwen-plus", "name": "通义千问-Plus", "type": "chat"},
{"id": "qwen-turbo", "name": "通义千问-Turbo", "type": "chat"},
{"id": "qwen-max", "name": "通义千问-Max", "type": "chat"},
{"id": "qwen-long", "name": "通义千问-Long", "type": "chat"}
]'::jsonb,
true,
100,
'{
"provider": "openai",
"default_model": "qwen-plus",
"supports_function_calling": true,
"supports_streaming": true
}'::jsonb
)
ON CONFLICT DO NOTHING
`
_, err = pool.Exec(ctx, sql, apiKey)
if err != nil {
log.Fatalf("插入数据失败: %v", err)
}
fmt.Println("✅ 成功初始化模型提供商数据:阿里云百炼 (通义千问)")
}