fix: satisfy strict ruff gate (BLE001, C901)

- catch pydantic ValidationError instead of blind Exception in
  OpenRouter rerank error-message extraction
- keep get_provider_rerank_config at base complexity by collapsing
  the cohere branch into a tuple check with a conditional expression
This commit is contained in:
parijat1222q 2026-10-22 04:21:07 +05:30
parent 59a1ce74f9
commit 5813929e43
2 changed files with 8 additions and 7 deletions

View file

@ -13,7 +13,7 @@ from collections.abc import Mapping
from typing import Final
import httpx
from pydantic import ConfigDict, TypeAdapter
from pydantic import ConfigDict, TypeAdapter, ValidationError
from litellm._uuid import uuid
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
@ -201,7 +201,7 @@ class OpenRouterRerankConfig(BaseRerankConfig):
# OpenRouter errors are OpenAI-shaped: {"error": {"message": "...", "code": ...}}
try:
parsed: Final = _JSON_OBJECT.validate_json(error_message)
except Exception:
except ValidationError:
return error_message
error_obj: Final = parsed.get("error")
if isinstance(error_obj, Mapping):

View file

@ -9567,11 +9567,12 @@ class ProviderConfigManager:
api_base: str | None,
present_version_params: list[str],
) -> BaseRerankConfig:
if litellm.LlmProviders.COHERE == provider or litellm.LlmProviders.COHERE_CHAT == provider:
if should_use_cohere_v1_client(api_base, present_version_params):
return litellm.CohereRerankConfig()
else:
return litellm.CohereRerankV2Config()
if provider in (litellm.LlmProviders.COHERE, litellm.LlmProviders.COHERE_CHAT):
return (
litellm.CohereRerankConfig()
if should_use_cohere_v1_client(api_base, present_version_params)
else litellm.CohereRerankV2Config()
)
elif litellm.LlmProviders.AZURE_AI == provider:
return litellm.AzureAIRerankConfig()
elif litellm.LlmProviders.INFINITY == provider: