| 289 | if len(configs) <= 1: |
| 290 | return jsonify({'status': 'error', 'message': '至少需要保留一个配置'}), 400 |
| 291 | |
| 292 | new_configs = [c for c in configs if c.get('id') != config_id] |
| 293 | if len(new_configs) == len(configs): |
| 294 | return jsonify({'status': 'error', 'message': f'配置 {config_id} 不存在'}), 404 |
| 295 | |
| 296 | data['configs'] = new_configs |
| 297 | if data.get('active_id') == config_id: |
| 298 | data['active_id'] = new_configs[0]['id'] |
| 299 | |
| 300 | save_config_file(data) |
| 301 | return jsonify({'status': 'success', 'message': '配置已删除', 'active_id': data['active_id']}) |
| 302 | except Exception as e: |
| 303 | logger.error(f"删除 LLM 配置失败:{str(e)}") |
| 304 | return jsonify({'status': 'error', 'message': f'删除配置失败:{str(e)}'}), 500 |
| 305 | |
| 306 | @app.route('/set_active_config/<config_id>', methods=['POST']) |
| 307 | def set_active_config(config_id): |
| 308 | try: |
| 309 | data = load_config_file() |