diff --git a/litellm/llms/gigachat/authenticator.py b/litellm/llms/gigachat/authenticator.py index a2e8030a2d1..293176d8931 100644 --- a/litellm/llms/gigachat/authenticator.py +++ b/litellm/llms/gigachat/authenticator.py @@ -107,7 +107,7 @@ def get_access_token( return _token # Request new token - new_token, new_expires_at = _request_token_sync(effective_credentials, effective_scope, effective_auth_url) + new_token, new_expires_at = _request_token_sync(effective_credentials, effective_scope, effective_auth_url) # pyright: ignore[reportArgumentType] # credential keys may be broader than str if new_expires_at: # Cache token @@ -152,7 +152,7 @@ async def get_access_token_async( return _token # Request new token - new_token, new_expires_at = await _request_token_async(effective_credentials, effective_scope, effective_auth_url) + new_token, new_expires_at = await _request_token_async(effective_credentials, effective_scope, effective_auth_url) # pyright: ignore[reportArgumentType] # credential keys may be broader than str if new_expires_at: # Cache token @@ -187,7 +187,7 @@ def _request_token_sync( client: Final = _get_http_client() response: Final = client.post(auth_url, headers=headers, data=data, timeout=30) response.raise_for_status() - return _parse_token_response(response) + return _parse_token_response(response) # pyright: ignore[reportArgumentType] # httpx Response may be None at type level except httpx.HTTPStatusError as e: raise GigaChatAuthError( status_code=e.response.status_code, @@ -222,7 +222,7 @@ async def _request_token_async( ) response: Final = await client.post(auth_url, headers=headers, data=data, timeout=30) response.raise_for_status() - return _parse_token_response(response) + return _parse_token_response(response) # pyright: ignore[reportArgumentType] # httpx Response may be None at type level except httpx.HTTPStatusError as e: raise GigaChatAuthError( status_code=e.response.status_code, diff --git a/litellm/llms/gigachat/chat/streaming.py b/litellm/llms/gigachat/chat/streaming.py index 64f3057a66f..3ed31c62d7d 100644 --- a/litellm/llms/gigachat/chat/streaming.py +++ b/litellm/llms/gigachat/chat/streaming.py @@ -5,7 +5,7 @@ GigaChat Streaming Response Handler import json import uuid from collections.abc import Mapping, Sequence -from typing import Any, Final +from typing import Any, Final, cast from litellm.llms.gigachat.utils import convert_usage from litellm.types.llms.openai import ( @@ -76,7 +76,7 @@ class GigaChatModelResponseIterator: if chunk_finish_reason == "stop": usage_data: Final = chunk.get("usage") or {} # mutable-ok: empty dict default if usage_data: - usage = convert_usage(usage_data) # rebind-ok: conditional usage assignment + usage = convert_usage(cast("Mapping[str, int]", usage_data)) # cast-ok: dict from chunk has int values usage_block = ChatCompletionUsageBlock( prompt_tokens=usage.prompt_tokens, completion_tokens=usage.completion_tokens, @@ -90,7 +90,7 @@ class GigaChatModelResponseIterator: ) return GenericStreamingChunk( - text=text, + text=cast(str, text), tool_use=tool_use, is_finished=chunk_finish_reason is not None, finish_reason=finish_reason or "", diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py index 3b554f5b56a..c7c290dcd2d 100644 --- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py @@ -509,7 +509,7 @@ async def milvus_proxy_route( detail=f"collectionName must be a string. Got {type(_raw_collection_name).__name__}", ) collection_name: str | None = _raw_collection_name # rebind-ok: locally scoped conversion - extra_headers: Final = {} # mutable-ok: dict for extra headers + extra_headers = {} # mutable-ok: dict for extra headers; rebind-ok: reassigned later from credentials base_target_url: str | None = None if not collection_name: raise HTTPException( @@ -2839,10 +2839,10 @@ async def gigachat_proxy_route( ) ## check for streaming - request_body: Final = await get_request_body(request) + request_body: Final = await get_request_body(request) # pyright: ignore[reportUnknownVariableType] # get_request_body returns Unknown is_router_model = False # rebind-ok: conditionally set to True when model uses router - model: Final = request_body.get("model") + model: Final = request_body.get("model") # pyright: ignore[reportUnknownVariableType] # get_request_body returns Unknown if model: is_router_model = is_passthrough_request_using_router_model( request_body, llm_router @@ -2880,7 +2880,9 @@ async def gigachat_proxy_route( "Gigachat passthrough: Using direct Gigachat model '%s' for endpoint '%s'", model, endpoint ) - data: Final[dict[str, Any]] = {} # mutable-ok: request body mutated in place by proxy pipeline + data: dict[ + str, Any + ] = {} # mutable-ok: request body mutated in place by proxy pipeline; pyright: ignore[reportExplicitAny] # Any needed for proxy pipeline flexibility data["method"] = request.method data["endpoint"] = endpoint @@ -2968,9 +2970,11 @@ async def handle_gigachat_passthrough_router_model( from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing # Detect streaming based on request body - is_streaming: Final = request_body.get("stream", False) + is_streaming: Final = request_body.get("stream", False) # pyright: ignore[reportUnknownVariableType] # request_body is dict[Unknown, Unknown] - data: Final[dict[str, Any]] = await _read_request_body(request=request) + data: dict[str, Any] = await _read_request_body( + request=request + ) # mutable-ok: mutated in place by proxy pipeline; pyright: ignore[reportExplicitAny] # Any needed for proxy pipeline if user_api_key_dict is not None: if data.get("metadata") is None: data["metadata"] = {} # mutable-ok: metadata dict mutated in place @@ -3021,7 +3025,7 @@ async def handle_gigachat_passthrough_router_model( # Use the common passthrough processing to handle metadata and hooks # This also handles all response formatting (streaming/non-streaming) and exceptions try: - result: Final = await base_llm_response_processor.base_passthrough_process_llm_request( + result = await base_llm_response_processor.base_passthrough_process_llm_request( # rebind-ok: assigned once in try block request=request, fastapi_response=fastapi_response, user_api_key_dict=user_api_key_dict,