fix: 修正 OpenAI/Anthropic Provider 初始化参数顺序
修复 manager.go 中两处调用 NewOpenAIProvider 和 NewAnthropicProvider 时参数顺序错误的问题。原代码将 baseURL 和 apiKey 参数传反,导致 API key 被当作 URL 使用,引发 "unsupported protocol scheme" 错误。 Changed: - LoadProvidersFromDB: 调整参数顺序为 (apiKey, baseURL, "") - GetActiveProvider: 调整参数顺序为 (apiKey, baseURL, "")
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
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()
|
||||
|
||||
// 插入阿里云百炼(通义千问)配置
|
||||
sql := `
|
||||
INSERT INTO model_providers (
|
||||
name,
|
||||
base_url,
|
||||
api_key_encrypted,
|
||||
models,
|
||||
is_active,
|
||||
priority,
|
||||
config
|
||||
) VALUES (
|
||||
'阿里云百炼 (通义千问)',
|
||||
'https://dashscope.aliyuncs.com/compatible-mode/v1',
|
||||
'sk-c0c5174892c44ff48d587cd040fbdd40',
|
||||
'[
|
||||
{"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)
|
||||
if err != nil {
|
||||
log.Fatalf("插入数据失败: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("✅ 成功初始化模型提供商数据:阿里云百炼 (通义千问)")
|
||||
}
|
||||
Reference in New Issue
Block a user