mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-07-20 20:21:50 +08:00
fix(llm): sanitize model endpoint errors (#6021)
This commit is contained in:
@@ -48,7 +48,7 @@ class LlmProviderAuthStartRequest(BaseModel):
|
||||
method: str
|
||||
|
||||
|
||||
def _sanitize_llm_test_error(message: str, api_key: Optional[str] = None) -> str:
|
||||
def _sanitize_llm_error(message: str, api_key: Optional[str] = None) -> str:
|
||||
"""
|
||||
清理错误信息中的敏感字段,避免回显密钥。
|
||||
"""
|
||||
@@ -70,11 +70,14 @@ def _sanitize_llm_test_error(message: str, api_key: Optional[str] = None) -> str
|
||||
)
|
||||
|
||||
normalized_message = sanitized.lower().replace("_", "").replace(" ", "")
|
||||
if "str" in normalized_message and "modeldump" in normalized_message:
|
||||
if "str" in normalized_message and (
|
||||
"modeldump" in normalized_message
|
||||
or "setprivateattributes" in normalized_message
|
||||
):
|
||||
return (
|
||||
"服务返回内容不是兼容的模型响应,"
|
||||
"请检查基础地址是否填写为 API Base URL,不要填写网页地址或完整的 "
|
||||
"chat/completions 路径"
|
||||
"服务返回内容不是兼容的模型响应,请检查基础地址是否填写为 "
|
||||
"API Base URL,如果服务要求 /v1 等版本路径,请包含在基础地址中,"
|
||||
"不要填写网页地址或完整的 chat/completions 路径"
|
||||
)
|
||||
return sanitized
|
||||
|
||||
@@ -113,7 +116,10 @@ async def get_llm_models(
|
||||
},
|
||||
)
|
||||
except Exception as err:
|
||||
return schemas.Response(success=False, message=str(err))
|
||||
return schemas.Response(
|
||||
success=False,
|
||||
message=_sanitize_llm_error(str(err), api_key),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/providers", summary="获取LLM提供商目录", response_model=schemas.Response)
|
||||
@@ -312,5 +318,5 @@ async def llm_test(
|
||||
except Exception as err:
|
||||
return schemas.Response(
|
||||
success=False,
|
||||
message=_sanitize_llm_test_error(str(err), payload.api_key),
|
||||
message=_sanitize_llm_error(str(err), payload.api_key),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user