* 更新 AI 模型
(model: AiModel)
| 133 | * 更新 AI 模型 |
| 134 | */ |
| 135 | public updateModel(model: AiModel): { success: boolean; error?: string } { |
| 136 | // 验证必填字段 |
| 137 | if (!model.id || !model.label || !model.apiUrl || !model.apiKey) { |
| 138 | return { success: false, error: '模型ID、名称、API地址和密钥不能为空' } |
| 139 | } |
| 140 | |
| 141 | const models = this.getAllModels() |
| 142 | |
| 143 | // 查找要更新的模型 |
| 144 | const index = models.findIndex((m: AiModel) => m.id === model.id) |
| 145 | if (index === -1) { |
| 146 | return { success: false, error: '未找到该模型' } |
| 147 | } |
| 148 | |
| 149 | // 更新模型 |
| 150 | models[index] = model |
| 151 | |
| 152 | // 保存到数据库(databaseAPI 会自动处理 _rev) |
| 153 | databaseAPI.dbPut(this.DB_KEY, models) |
| 154 | |
| 155 | return { success: true } |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * 删除 AI 模型 |
no test coverage detected