The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(lint): Partly fix LIT issues
KnyazSh5af54d26b81a
diff --git a/litellm/llms/gigachat/authenticator.py b/litellm/llms/gigachat/authenticator.pyindex 9b8ef3ec93f..a2e8030a2d1 100644--- a/litellm/llms/gigachat/authenticator.py+++ b/litellm/llms/gigachat/authenticator.py@@ -249,12 +249,12 @@ def _parse_token_response(response: httpx.Response) -> tuple[str, int]:message=f"Invalid token response: {data}",)- expires_at: int# expires_at is in milliseconds+ expires_at: int # rebind-ok: conditionally assigned from str or intif isinstance(expires_at_raw, str):- expires_at = int(expires_at_raw)+ expires_at = int(expires_at_raw) # rebind-ok: conditionally assigned from str or intelse:- expires_at = expires_at_raw # pyright: ignore[reportAssignmentType] # raw value is int or str; converted above+ expires_at = expires_at_raw # pyright: ignore[reportAssignmentType] # raw value is int or str; converted above; rebind-ok: conditionally assigned from str or intverbose_logger.debug("GigaChat access token obtained successfully")return access_token, expires_atdiff --git a/litellm/llms/gigachat/chat/streaming.py b/litellm/llms/gigachat/chat/streaming.pyindex 338d37d810a..64f3057a66f 100644--- a/litellm/llms/gigachat/chat/streaming.py+++ b/litellm/llms/gigachat/chat/streaming.py@@ -48,15 +48,15 @@ class GigaChatModelResponseIterator:# Extract text contenttext: Final = delta.get("content", "") or ""- usage_block: ChatCompletionUsageBlock | None = None- tool_use: ChatCompletionToolCallChunk | None = None+ usage_block: ChatCompletionUsageBlock | None = None # rebind-ok: conditionally assigned after stop detection+ tool_use: ChatCompletionToolCallChunk | None = None # rebind-ok: conditionally assigned on function_callfinish_reason: str | None = chunk_finish_reason# Handle function_call in streamif chunk_finish_reason == "function_call" and delta.get("function_call"):func_call: Final = delta["function_call"]args_raw: Final = func_call.get("arguments") or {}- args_str: str+ args_str: str # rebind-ok: conditionally assigned from dict or strif isinstance(args_raw, dict):args_str = json.dumps(args_raw, ensure_ascii=False) # rebind-ok: build from dictelse:@@ -76,7 +76,7 @@ class GigaChatModelResponseIterator:if chunk_finish_reason == "stop":usage_data: Final = chunk.get("usage") or {} # mutable-ok: empty dict defaultif usage_data:- usage: Final = convert_usage(usage_data)+ usage = convert_usage(usage_data) # rebind-ok: conditional usage assignmentusage_block = ChatCompletionUsageBlock(prompt_tokens=usage.prompt_tokens,completion_tokens=usage.completion_tokens,diff --git a/litellm/llms/gigachat/embedding/transformation.py b/litellm/llms/gigachat/embedding/transformation.pyindex 6aaf63297cb..2ec8324e33c 100644--- a/litellm/llms/gigachat/embedding/transformation.py+++ b/litellm/llms/gigachat/embedding/transformation.py@@ -114,12 +114,12 @@ class GigaChatEmbeddingConfig(BaseEmbeddingConfig):"""# Normalize input to listif isinstance(input, str):- input_list: list = [input]+ input_list: list = [input] # rebind-ok: locally scoped conversionelse:input_list = input# Remove gigachat/ prefix from model if present- model = model.removeprefix("gigachat/")+ model = model.removeprefix("gigachat/") # rebind-ok: parameter reassignment for normalizationreturn {"model": model,diff --git a/litellm/llms/gigachat/passthrough/transformation.py b/litellm/llms/gigachat/passthrough/transformation.pyindex 531a53792b3..fe65cf5561f 100644--- a/litellm/llms/gigachat/passthrough/transformation.py+++ b/litellm/llms/gigachat/passthrough/transformation.py@@ -92,7 +92,7 @@ class GigaChatPassthroughConfig(BasePassthroughConfig):if provider_chat_config is None:raise ValueError(f"No provider config found for model: {model}")- litellm_model_response: ModelResponse = provider_chat_config.transform_response(+ litellm_model_response: Final = provider_chat_config.transform_response(model=model,messages=request_data.get("messages", []), # mutable-ok: empty list default for transform_responseraw_response=httpx_response,diff --git a/litellm/llms/gigachat/utils.py b/litellm/llms/gigachat/utils.pyindex aa30552a7ec..b1db8f685e5 100644--- a/litellm/llms/gigachat/utils.py+++ b/litellm/llms/gigachat/utils.py@@ -17,9 +17,13 @@ def convert_usage(usage_data: Mapping[str, int]) -> Usage:prompt_tokens_total: Final = prompt_tokens + precached_prompt_tokenstotal_tokens_total: Final = total_tokens + precached_prompt_tokens- prompt_tokens_details: PromptTokensDetailsWrapper | None = None+ prompt_tokens_details: PromptTokensDetailsWrapper | None = (+ None # rebind-ok: conditionally assigned when cached tokens exist+ )if precached_prompt_tokens > 0:- prompt_tokens_details = PromptTokensDetailsWrapper(cached_tokens=precached_prompt_tokens)+ prompt_tokens_details = PromptTokensDetailsWrapper(+ cached_tokens=precached_prompt_tokens+ ) # rebind-ok: conditionally assigned when cached tokens existreturn Usage(prompt_tokens=prompt_tokens_total,diff --git a/litellm/passthrough/main.py b/litellm/passthrough/main.pyindex 956badfcfe1..a64aa894221 100644--- a/litellm/passthrough/main.py+++ b/litellm/passthrough/main.py@@ -101,7 +101,7 @@ class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):self._flush_scheduled = Truetry:- task = asyncio.create_task(+ task: Final = asyncio.create_task(self._litellm_logging_obj.async_flush_passthrough_collected_chunks(raw_bytes=self._raw_bytes,provider_config=self._provider_config,@@ -127,7 +127,7 @@ class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):if not self._initialized:await self # pyright: ignore[reportGeneralTypeIssues] # structural type check misses __await__try:- chunk = await anext(self._iterator)+ chunk: Final = await anext(self._iterator)self._raw_bytes.append(chunk)except Exception: # noqa: BLE001 # Safe catch-all for cleanup logicself._start_flush()@@ -205,7 +205,7 @@ class PassthroughStreamingResponse(Generator[Any, Any, Any]):def __next__(self) -> bytes:try:- chunk = next(self._iterator)+ chunk: Final = next(self._iterator)self._raw_bytes.append(chunk)except Exception: # noqa: BLE001 # Safe catch-all for cleanup logicself._start_flush()diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.pyindex 90eae550fe0..69a2ff53672 100644--- a/litellm/proxy/common_request_processing.py+++ b/litellm/proxy/common_request_processing.py@@ -1448,7 +1448,7 @@ class ProxyBaseLLMRequestProcessing:Proxy/custom headers win on key collisions."""- excluded_headers = { # mutable-ok: set of header names to exclude from forwarding+ excluded_headers: Final = { # mutable-ok: set of header names to exclude from forwarding"transfer-encoding","content-encoding","set-cookie",@@ -1461,7 +1461,7 @@ class ProxyBaseLLMRequestProcessing:"upgrade",}- merged_headers = { # mutable-ok: dict comprehension for merged headers forwarded to httpx+ merged_headers: Final = { # mutable-ok: dict comprehension for merged headers forwarded to httpxkey: value for key, value in dict(response_headers or {}).items() if key.lower() not in excluded_headers}merged_headers.update(custom_headers)@@ -2425,9 +2425,9 @@ class ProxyBaseLLMRequestProcessing:logging_obj._on_deferred_stream_complete = _on_deferred_stream_completeif route_type == "allm_passthrough_route":- streaming_headers = custom_headers+ streaming_headers = custom_headers # rebind-ok: initial assignment before header mergeif hasattr(response, "headers"):- streaming_headers = ProxyBaseLLMRequestProcessing._merge_passthrough_streaming_headers(+ streaming_headers = ProxyBaseLLMRequestProcessing._merge_passthrough_streaming_headers( # rebind-ok: merge result replaces initial assignmentresponse_headers=getattr(response, "headers", None),custom_headers=custom_headers,)diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.pyindex a3fe2911038..3b554f5b56a 100644--- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py+++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py@@ -76,9 +76,9 @@ if TYPE_CHECKING:from litellm.proxy.proxy_server import ProxyConfig as _ProxyConfigfrom litellm.router import Router- ProxyConfig = _ProxyConfig+ ProxyConfig = _ProxyConfig # rebind-ok: conditional type aliaselse:- ProxyConfig = Any+ ProxyConfig = Any # rebind-ok: runtime fallbackvertex_llm_base: Final = VertexBase()router: Final = APIRouter()@@ -508,8 +508,8 @@ async def milvus_proxy_route(status_code=400,detail=f"collectionName must be a string. Got {type(_raw_collection_name).__name__}",)- collection_name: str | None = _raw_collection_name- extra_headers = {}+ collection_name: str | None = _raw_collection_name # rebind-ok: locally scoped conversion+ extra_headers: Final = {} # mutable-ok: dict for extra headersbase_target_url: str | None = Noneif not collection_name:raise HTTPException(@@ -2839,12 +2839,14 @@ async def gigachat_proxy_route()## check for streaming- request_body = await get_request_body(request)- is_router_model = False+ request_body: Final = await get_request_body(request)+ is_router_model = False # rebind-ok: conditionally set to True when model uses router- model = request_body.get("model")+ model: Final = request_body.get("model")if model:- is_router_model = is_passthrough_request_using_router_model(request_body, llm_router)+ is_router_model = is_passthrough_request_using_router_model(+ request_body, llm_router+ ) # rebind-ok: conditionally set to Trueelif any(word in endpoint for word in ("completions", "embeddings")):raise HTTPException(status_code=400, detail={"error": "Model is required in request body"}@@ -2878,14 +2880,14 @@ async def gigachat_proxy_route("Gigachat passthrough: Using direct Gigachat model '%s' for endpoint '%s'", model, endpoint)- data: dict[str, Any] = {} # mutable-ok: request body mutated in place by proxy pipeline+ data: Final[dict[str, Any]] = {} # mutable-ok: request body mutated in place by proxy pipelinedata["method"] = request.methoddata["endpoint"] = endpointdata["json"] = request_bodydata["custom_llm_provider"] = "gigachat"- client = get_async_httpx_client(+ client: Final = get_async_httpx_client(llm_provider=LlmProviders.GIGACHAT,params={ # mutable-ok: httpx client params"timeout": httpx.Timeout(timeout=600.0, connect=5.0),@@ -2894,7 +2896,7 @@ async def gigachat_proxy_route()data["client"] = client- base_llm_response_processor = ProxyBaseLLMRequestProcessing(data=data)+ base_llm_response_processor: Final = ProxyBaseLLMRequestProcessing(data=data)try:return await base_llm_response_processor.base_passthrough_process_llm_request(@@ -2966,9 +2968,9 @@ async def handle_gigachat_passthrough_router_model(from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing# Detect streaming based on request body- is_streaming = request_body.get("stream", False)+ is_streaming: Final = request_body.get("stream", False)- data: dict[str, Any] = await _read_request_body(request=request)+ data: Final[dict[str, Any]] = await _read_request_body(request=request)if user_api_key_dict is not None:if data.get("metadata") is None:data["metadata"] = {} # mutable-ok: metadata dict mutated in place@@ -2995,7 +2997,7 @@ async def handle_gigachat_passthrough_router_model(data["custom_llm_provider"] = "gigachat"# Remove sensitive keys from data- keys = [ # mutable-ok: list of keys to remove from data+ keys: Final = [ # mutable-ok: list of keys to remove from data"gigachat_auth_url","gigachat_access_token","gigachat_scope",@@ -3005,7 +3007,7 @@ async def handle_gigachat_passthrough_router_model(for key in keys:data.pop(key, None)- client = get_async_httpx_client(+ client: Final = get_async_httpx_client(llm_provider=LlmProviders.GIGACHAT,params={ # mutable-ok: httpx client params"timeout": httpx.Timeout(timeout=600.0, connect=5.0),@@ -3014,12 +3016,12 @@ async def handle_gigachat_passthrough_router_model()data["client"] = client- base_llm_response_processor = ProxyBaseLLMRequestProcessing(data=data)+ base_llm_response_processor: Final = ProxyBaseLLMRequestProcessing(data=data)# Use the common passthrough processing to handle metadata and hooks# This also handles all response formatting (streaming/non-streaming) and exceptionstry:- result = await base_llm_response_processor.base_passthrough_process_llm_request(+ result: Final = await base_llm_response_processor.base_passthrough_process_llm_request(request=request,fastapi_response=fastapi_response,user_api_key_dict=user_api_key_dict,