feat: 优化模型配置管理 - 动态使用优先级最高的Provider

## 主要改进

### 1. 数据库驱动的模型配置
- 新增 GetActiveProviderWithModel() 方法,从数据库获取优先级最高的 Provider 及其默认模型
- 支持多 Provider 配置,通过 priority 字段控制优先级
- 实现 5 分钟缓存机制,减少数据库查询

### 2. 应用模型配置优化
- 移除应用层硬编码模型配置
- 应用自动使用优先级最高的 Provider 的默认模型
- 支持应用级模型覆盖(可选)

### 3. 工具脚本
- check-providers: 查询数据库中的 Provider 和应用配置
- fix-providers: 修复 Provider 配置(补全 config 和 models 字段)
- clear-app-models: 清空应用硬编码模型配置

### 4. 代码质量
- 删除未使用的 getProvider() 方法
- 修复 fmt.Println 冗余换行警告
- 统一代码格式

## 技术细节

**降级策略**:
数据库 Provider (优先级) → 环境变量 Provider → 应用配置模型

**当前配置**:
- 优先级 110: 本地LLM (qwen2.5-7b-instruct)
- 优先级 100: 阿里云百炼 (qwen-plus)

所有 41 个应用现在自动使用本地模型,无需手动配置。
This commit is contained in:
selfrelease
2026-06-22 18:46:44 +08:00
parent 0c1a8544e8
commit 96930b585c
8 changed files with 468 additions and 65 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ func newRouter(cfg *config.Config, pool *pgxpool.Pool, rdb *redis.Client) http.H
// LLM Manager — direct model calls replacing Dify for chat
llmMgr := llm.NewManager()
llmMgr.SetPool(pool)
// 优先从数据库加载 providers(如果失败,回退到环境变量配置)
if err := llmMgr.LoadProvidersFromDB(context.Background()); err != nil {
// 回退:使用环境变量配置