f7a720204a
- 移除 GovAI, nomifun-tauri, 算力盒子 的 submodule 引用 - 添加所有子项目的完整源代码 - 保留原始 .git 为 .git.bak 备份
114 lines
2.9 KiB
Go
114 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
func main() {
|
|
// 加载环境变量
|
|
_ = godotenv.Load("../../.env")
|
|
|
|
dbURL := os.Getenv("DATABASE_URL")
|
|
if dbURL == "" {
|
|
dbURL = "postgres://freedak:@localhost:5432/govai_portal?sslmode=disable"
|
|
}
|
|
|
|
pool, err := pgxpool.New(context.Background(), dbURL)
|
|
if err != nil {
|
|
log.Fatalf("无法连接数据库: %v", err)
|
|
}
|
|
defer pool.Close()
|
|
|
|
fmt.Println("=== 开始修复数据库配置 ===")
|
|
|
|
// 1. 修复本地模型配置
|
|
fmt.Println("【任务1】修复本地模型配置...")
|
|
result, err := pool.Exec(context.Background(), `
|
|
UPDATE model_providers
|
|
SET config = '{
|
|
"provider": "openai",
|
|
"default_model": "qwen2.5-7b-instruct",
|
|
"supports_streaming": true,
|
|
"supports_function_calling": false
|
|
}'::jsonb,
|
|
models = '[
|
|
{"id": "qwen2.5-7b-instruct", "name": "Qwen2.5-7B-Instruct", "type": "chat"}
|
|
]'::jsonb
|
|
WHERE name = '本地LLM (Qwen2.5-7B)'
|
|
`)
|
|
if err != nil {
|
|
log.Printf("❌ 修复本地模型失败: %v", err)
|
|
} else {
|
|
rowsAffected := result.RowsAffected()
|
|
if rowsAffected > 0 {
|
|
fmt.Printf("✅ 成功修复本地模型配置 (影响 %d 行)\n\n", rowsAffected)
|
|
} else {
|
|
fmt.Println("⚠️ 未找到本地模型记录")
|
|
}
|
|
}
|
|
|
|
// 2. 为未配置模型的应用设置默认模型
|
|
fmt.Println("【任务2】为未配置模型的应用设置默认模型...")
|
|
result, err = pool.Exec(context.Background(), `
|
|
UPDATE applications
|
|
SET app_config = jsonb_set(
|
|
COALESCE(app_config, '{}'::jsonb),
|
|
'{model}',
|
|
'"qwen2.5-7b-instruct"'
|
|
)
|
|
WHERE (app_config->>'model' IS NULL OR app_config->>'model' = '')
|
|
AND status = 'approved'
|
|
`)
|
|
if err != nil {
|
|
log.Printf("❌ 更新应用配置失败: %v", err)
|
|
} else {
|
|
rowsAffected := result.RowsAffected()
|
|
if rowsAffected > 0 {
|
|
fmt.Printf("✅ 成功为 %d 个应用设置默认模型\n\n", rowsAffected)
|
|
} else {
|
|
fmt.Println("ℹ️ 所有应用已配置模型")
|
|
}
|
|
}
|
|
|
|
// 3. 验证修复结果
|
|
fmt.Println("【验证】检查修复结果...")
|
|
|
|
var localConfig, localModels string
|
|
err = pool.QueryRow(context.Background(), `
|
|
SELECT
|
|
COALESCE(config::text, 'null') as config,
|
|
COALESCE(models::text, 'null') as models
|
|
FROM model_providers
|
|
WHERE name = '本地LLM (Qwen2.5-7B)'
|
|
`).Scan(&localConfig, &localModels)
|
|
|
|
if err != nil {
|
|
log.Printf("查询验证失败: %v", err)
|
|
} else {
|
|
fmt.Printf("本地模型 config: %s\n", localConfig)
|
|
fmt.Printf("本地模型 models: %s\n\n", localModels)
|
|
}
|
|
|
|
var unconfiguredCount int
|
|
err = pool.QueryRow(context.Background(), `
|
|
SELECT COUNT(*)
|
|
FROM applications
|
|
WHERE (app_config->>'model' IS NULL OR app_config->>'model' = '')
|
|
AND status = 'approved'
|
|
`).Scan(&unconfiguredCount)
|
|
|
|
if err != nil {
|
|
log.Printf("查询未配置应用数量失败: %v", err)
|
|
} else {
|
|
fmt.Printf("未配置模型的应用数量: %d\n", unconfiguredCount)
|
|
}
|
|
|
|
fmt.Println("\n=== 修复完成 ===")
|
|
}
|