From 5cd15cdd1e03ed6aebd74bdb5ced497a798d076f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Sat, 13 Dec 2025 18:38:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=AA=8C=E8=AF=81=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=B7=B2=E5=88=A0=E9=99=A4=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=95=86=E7=9A=84=E6=A8=A1=E5=9E=8B=E5=BC=95=E7=94=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/webui/config_routes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/webui/config_routes.py b/src/webui/config_routes.py index 25127fe5..438683b6 100644 --- a/src/webui/config_routes.py +++ b/src/webui/config_routes.py @@ -368,6 +368,18 @@ async def update_model_config_section(section_name: str, section_data: SectionBo try: APIAdapterConfig.from_dict(config_data) except Exception as e: + logger.error(f"配置数据验证失败,详细错误: {str(e)}") + # 特殊处理:如果是更新 api_providers,检查是否有模型引用了已删除的provider + if section_name == "api_providers" and "api_provider" in str(e): + provider_names = {p.get("name") for p in section_data if isinstance(p, dict)} + models = config_data.get("models", []) + orphaned_models = [ + m.get("name") for m in models + if isinstance(m, dict) and m.get("api_provider") not in provider_names + ] + if orphaned_models: + error_msg = f"以下模型引用了已删除的提供商: {', '.join(orphaned_models)}。请先在模型管理页面删除这些模型,或重新分配它们的提供商。" + raise HTTPException(status_code=400, detail=error_msg) from e raise HTTPException(status_code=400, detail=f"配置数据验证失败: {str(e)}") from e # 保存配置(格式化数组为多行,保留注释)