chore: fix pre commit format and pipeline issue (#1144)

This commit is contained in:
Wendong-Fan 2026-02-04 00:06:29 +00:00 committed by GitHub
parent 2256497dff
commit 893f51fc82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
970 changed files with 11235 additions and 9533 deletions

View file

@ -16,7 +16,9 @@ import json
import re
def normalize_error_to_openai_format(exception: Exception) -> tuple[str, str | None, dict | None]:
def normalize_error_to_openai_format(
exception: Exception,
) -> tuple[str, str | None, dict | None]:
"""
Normalize error to OpenAI-style error structure.
@ -55,7 +57,12 @@ def normalize_error_to_openai_format(exception: Exception) -> tuple[str, str | N
# Heuristics if not parsed
if error_obj is None:
lower = raw_msg.lower()
if "invalid_api_key" in lower or "incorrect api key" in lower or "unauthorized" in lower or " 401" in lower:
if (
"invalid_api_key" in lower
or "incorrect api key" in lower
or "unauthorized" in lower
or " 401" in lower
):
error_code = "invalid_api_key"
message = "Invalid key. Validation failed."
error_obj = {
@ -64,7 +71,11 @@ def normalize_error_to_openai_format(exception: Exception) -> tuple[str, str | N
"param": None,
"code": "invalid_api_key",
}
elif "model_not_found" in lower or "does not exist" in lower or " 404" in lower:
elif (
"model_not_found" in lower
or "does not exist" in lower
or " 404" in lower
):
error_code = "model_not_found"
message = "Invalid model name. Validation failed."
error_obj = {
@ -73,9 +84,16 @@ def normalize_error_to_openai_format(exception: Exception) -> tuple[str, str | N
"param": None,
"code": "model_not_found",
}
elif "insufficient_quota" in lower or "quota" in lower or " 429" in lower:
elif (
"insufficient_quota" in lower
or "quota" in lower
or " 429" in lower
):
error_code = "insufficient_quota"
message = "You exceeded your current quota, please check your plan and billing details."
message = (
"You exceeded your current quota, "
"please check your plan and billing details."
)
error_obj = {
"message": message,
"type": "insufficient_quota",