refactor: centralize llm backend configuration

This commit is contained in:
liuwei
2026-04-08 13:43:41 +08:00
parent df1939d60b
commit aecb62cb4d
19 changed files with 945 additions and 792 deletions

View File

@@ -10,6 +10,7 @@ import psutil
from collections import deque
import gzip
import json
import yaml
# 创建系统信息蓝图
system_bp = Blueprint('system', __name__)
@@ -156,6 +157,52 @@ def get_current_user_info():
return jsonify(result)
@system_bp.route('/api/system/config/raw', methods=['GET'])
@login_required
def get_system_config_raw():
try:
server = current_app.dashboard_server
config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'config.yaml'))
with open(config_path, 'r', encoding='utf-8') as f:
config_text = f.read()
robot_config = getattr(getattr(server, "robot", None), "config", None)
llm_config = getattr(robot_config, "llm", {}) if robot_config else {}
llm_backends = (llm_config or {}).get("backends", {})
return jsonify({
"success": True,
"data": config_text,
"path": config_path,
"llm_backends": list((llm_backends or {}).keys()),
})
except Exception as e:
logger.error(f"读取系统配置失败: {e}")
return jsonify({"success": False, "message": str(e)}), 500
@system_bp.route('/api/system/config/update', methods=['POST'])
@login_required
def update_system_config():
try:
server = current_app.dashboard_server
data = request.get_json() or {}
config_text = data.get("config_text")
if config_text is None:
return jsonify({"success": False, "message": "缺少配置内容"}), 400
yaml.safe_load(config_text)
config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'config.yaml'))
with open(config_path, 'w', encoding='utf-8') as f:
f.write(config_text)
if getattr(server, "robot", None) and getattr(server.robot, "config", None):
server.robot.config.reload()
return jsonify({"success": True, "message": "全局配置已保存"})
except Exception as e:
logger.error(f"保存系统配置失败: {e}")
return jsonify({"success": False, "message": str(e)}), 500
@system_bp.route('/api/restart_service', methods=['POST'])
@login_required
def restart_service():