diff --git a/admin.py b/admin.py index 31f2d15..3562dae 100644 --- a/admin.py +++ b/admin.py @@ -686,7 +686,10 @@ def llm_config(): 'timeout': DynamicConfig.get('llm_timeout', LLM_CONFIG.get('timeout')), } - return render_template('admin/llm_config.html', config=config) + # 获取备用大模型配置 + backup_configs = BackupLLMConfig.query.order_by(BackupLLMConfig.sort_order).all() + + return render_template('admin/llm_config.html', config=config, backup_configs=[c.to_dict() for c in backup_configs]) @admin_bp.route('/llm_config/save', methods=['POST']) @@ -1224,92 +1227,72 @@ def get_all_membership_plans(): @admin_bp.route('/backup-llm') @admin_required def backup_llm_list(): - """备用大模型接口列表""" - configs = BackupLLMConfig.query.order_by(BackupLLMConfig.sort_order).all() - - # 如果数据库中没有数据,初始化默认配置 - if not configs: - init_default_backup_llm() - configs = BackupLLMConfig.query.order_by(BackupLLMConfig.sort_order).all() - - return render_template('admin/backup_llm.html', configs=configs) + """备用大模型接口列表 - 重定向到大模型配置页""" + return redirect(url_for('admin.llm_config')) -@admin_bp.route('/backup-llm/add', methods=['GET', 'POST']) +@admin_bp.route('/backup-llm/add', methods=['POST']) @admin_required def add_backup_llm(): """添加备用大模型接口""" - if request.method == 'POST': - data = request.json if request.is_json else request.form - - config = BackupLLMConfig( - provider_name=data.get('provider_name'), - api_base=data.get('api_base'), - api_key=data.get('api_key'), - model=data.get('model'), - is_active=data.get('is_active', True) if isinstance(data.get('is_active'), bool) else data.get('is_active') == 'true', - sort_order=int(data.get('sort_order', 0)), - description=data.get('description'), - ) - - db.session.add(config) - db.session.commit() - - # 记录日志 - log = OperationLog( - user_id=session.get('user_id'), - username='admin', - action='add_backup_llm', - target=config.provider_name, - detail=json.dumps(config.to_dict(), ensure_ascii=False) - ) - db.session.add(log) - db.session.commit() - - if request.is_json: - return jsonify({'success': True, 'config': config.to_dict()}) - flash('备用大模型接口已添加', 'success') - return redirect(url_for('admin.backup_llm_list')) + data = request.json - return render_template('admin/backup_llm_form.html', config=None) + config = BackupLLMConfig( + provider_name=data.get('provider_name'), + api_base=data.get('api_base'), + api_key=data.get('api_key'), + model=data.get('model'), + is_active=data.get('is_active', True), + sort_order=int(data.get('sort_order', 0)), + description=data.get('description'), + ) + + db.session.add(config) + db.session.commit() + + # 记录日志 + log = OperationLog( + user_id=session.get('user_id'), + username='admin', + action='add_backup_llm', + target=config.provider_name, + detail=json.dumps(config.to_dict(), ensure_ascii=False) + ) + db.session.add(log) + db.session.commit() + + return jsonify({'success': True, 'config': config.to_dict()}) -@admin_bp.route('/backup-llm//edit', methods=['GET', 'POST']) +@admin_bp.route('/backup-llm//edit', methods=['POST']) @admin_required def edit_backup_llm(config_id): """编辑备用大模型接口""" config = BackupLLMConfig.query.get_or_404(config_id) + data = request.json - if request.method == 'POST': - data = request.json if request.is_json else request.form - - config.provider_name = data.get('provider_name', config.provider_name) - config.api_base = data.get('api_base', config.api_base) - config.api_key = data.get('api_key', config.api_key) - config.model = data.get('model', config.model) - config.is_active = data.get('is_active', True) if isinstance(data.get('is_active'), bool) else data.get('is_active') == 'true' - config.sort_order = int(data.get('sort_order', config.sort_order)) - config.description = data.get('description', config.description) - - db.session.commit() - - # 记录日志 - log = OperationLog( - user_id=session.get('user_id'), - username='admin', - action='edit_backup_llm', - target=config.provider_name, - detail=json.dumps(config.to_dict(), ensure_ascii=False) - ) - db.session.add(log) - db.session.commit() - - if request.is_json: - return jsonify({'success': True, 'config': config.to_dict()}) - flash('备用大模型接口已更新', 'success') - return redirect(url_for('admin.backup_llm_list')) + config.provider_name = data.get('provider_name', config.provider_name) + config.api_base = data.get('api_base', config.api_base) + config.api_key = data.get('api_key', config.api_key) + config.model = data.get('model', config.model) + config.is_active = data.get('is_active', True) + config.sort_order = int(data.get('sort_order', config.sort_order)) + config.description = data.get('description', config.description) - return render_template('admin/backup_llm_form.html', config=config) + db.session.commit() + + # 记录日志 + log = OperationLog( + user_id=session.get('user_id'), + username='admin', + action='edit_backup_llm', + target=config.provider_name, + detail=json.dumps(config.to_dict(), ensure_ascii=False) + ) + db.session.add(log) + db.session.commit() + + return jsonify({'success': True, 'config': config.to_dict()}) @admin_bp.route('/backup-llm//delete', methods=['POST']) diff --git a/templates/admin/backup_llm.html b/templates/admin/backup_llm.html deleted file mode 100644 index eb7d70f..0000000 --- a/templates/admin/backup_llm.html +++ /dev/null @@ -1,176 +0,0 @@ - - - - - 备用大模型接口 - 后台管理 - - - - - - - - -
-
-
备用大模型接口
-
- 新增接口 - -
-
- -
-
- - - - - - - - - - - - - {% for config in configs %} - - - - - - - - - {% endfor %} - -
#服务商API地址模型状态操作
{{ config.sort_order }} - {{ config.provider_name }} - {% if config.description %} -
{{ config.description }} - {% endif %} -
{{ config.api_base }}{{ config.model or '默认' }} - {% if config.is_active %} - 启用 - {% else %} - 禁用 - {% endif %} - - - - - - - -
- - {% if not configs %} -
- -

暂无备用大模型配置

- -
- {% endif %} -
-
- - -
- - - - \ No newline at end of file diff --git a/templates/admin/backup_llm_form.html b/templates/admin/backup_llm_form.html deleted file mode 100644 index 6a412e5..0000000 --- a/templates/admin/backup_llm_form.html +++ /dev/null @@ -1,191 +0,0 @@ - - - - - {{ config ? '编辑' : '添加' }}备用大模型接口 - 后台管理 - - - - - - - - -
-
-
-
{{ config ? '编辑备用大模型接口' : '添加备用大模型接口' }}
-
-
-
-
- - - 显示名称,方便识别 -
- -
- - - LLM服务的API endpoint -
- -
- - - 如果不需要可留空 -
- -
- - - 推荐使用的模型ID -
- -
- - -
- -
-
- - -
-
- - -
-
- -
- - - 返回 -
-
- - -
-
-
- - - - \ No newline at end of file diff --git a/templates/admin/cache.html b/templates/admin/cache.html index 7a6ab46..67cd7a1 100644 --- a/templates/admin/cache.html +++ b/templates/admin/cache.html @@ -28,7 +28,6 @@ - diff --git a/templates/admin/dashboard.html b/templates/admin/dashboard.html index 45d1969..395c0b2 100644 --- a/templates/admin/dashboard.html +++ b/templates/admin/dashboard.html @@ -70,7 +70,6 @@ - diff --git a/templates/admin/llm_config.html b/templates/admin/llm_config.html index e388735..342a074 100644 --- a/templates/admin/llm_config.html +++ b/templates/admin/llm_config.html @@ -12,6 +12,8 @@ .sidebar .nav-link { color: #adb5bd; padding: 12px 20px; } .sidebar .nav-link:hover, .sidebar .nav-link.active { color: #fff; background: rgba(255,255,255,0.1); } .main-content { margin-left: 250px; padding: 20px; } + .table th, .table td { font-size: 0.9rem; } + .status-badge { font-size: 0.75rem; } @@ -28,7 +30,6 @@ - @@ -39,9 +40,10 @@
+
-
大模型接口配置
+
主大模型接口配置
@@ -67,59 +69,145 @@
- 每次翻译最大输出长度
- PDF文本分块大小
- API请求超时时间
- +
- + +
备用大模型接口
- - 管理备用接口 - +
-

备用大模型接口用于主接口不可用时切换备用服务。支持手动新增、编辑、测试连接。

- - 查看所有备用接口 - + + + + + + + + + + + + + {% for item in backup_configs %} + + + + + + + + + {% else %} + + {% endfor %} + +
#服务商API地址模型状态操作
{{ item.sort_order }} + {{ item.provider_name }} + {% if item.description %}
{{ item.description }}{% endif %} +
{{ item.api_base }}{{ item.model or '默认' }} + {% if item.is_active %} + 启用 + {% else %} + 禁用 + {% endif %} + + + + + +
暂无备用大模型配置
+ +
+ + + +