fix(xai): drop banned typing.Any from image and video transforms

This commit is contained in:
hx 2026-09-18 15:32:00 +08:00
parent d6bb450932
commit 6ab547e35a
4 changed files with 33 additions and 34 deletions

View file

@ -1,6 +1,6 @@
import base64
from io import BufferedReader, BytesIO
from typing import Any, Final
from typing import TYPE_CHECKING, Final
import httpx
from httpx._types import RequestFiles
@ -15,6 +15,9 @@ from litellm.types.images.main import ImageEditOptionalRequestParams
from litellm.types.router import GenericLiteLLMParams
from litellm.types.utils import FileTypes, ImageObject, ImageResponse
if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
_SIZE_TO_ASPECT_RATIO: Final = {
"1024x1024": "1:1",
"1792x1024": "16:9",
@ -167,7 +170,7 @@ class XAIImageEditConfig(BaseImageEditConfig):
self,
model: str,
raw_response: httpx.Response,
logging_obj: Any,
logging_obj: "LiteLLMLoggingObj",
) -> ImageResponse:
try:
response_data: Final = raw_response.json()

View file

@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Any, Final
from typing import TYPE_CHECKING, Final
import httpx
@ -16,11 +16,8 @@ from litellm.types.llms.openai import (
from litellm.types.utils import ImageObject, ImageResponse
if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj
LiteLLMLoggingObj = _LiteLLMLoggingObj
else:
LiteLLMLoggingObj = Any
import tiktoken
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
_SIZE_TO_ASPECT_RATIO: Final = {
"1024x1024": "1:1",
@ -156,11 +153,11 @@ class XAIImageGenerationConfig(BaseImageGenerationConfig):
model: str,
raw_response: httpx.Response,
model_response: ImageResponse,
logging_obj: LiteLLMLoggingObj,
logging_obj: "LiteLLMLoggingObj",
request_data: dict,
optional_params: dict,
litellm_params: dict,
encoding: Any,
encoding: "tiktoken.Encoding | None",
api_key: str | None = None,
json_mode: bool | None = None,
) -> ImageResponse:

View file

@ -1,5 +1,5 @@
import time
from typing import TYPE_CHECKING, Any, Final
from typing import TYPE_CHECKING, Final
import httpx
from httpx._types import RequestFiles
@ -25,11 +25,7 @@ from litellm.types.videos.utils import (
)
if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj
LiteLLMLoggingObj = _LiteLLMLoggingObj
else:
LiteLLMLoggingObj = Any
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
_SIZE_TO_ASPECT_RATIO: Final = {
"1024x1024": "1:1",
@ -225,7 +221,7 @@ class XAIVideoConfig(BaseVideoConfig):
self,
model: str,
raw_response: httpx.Response,
logging_obj: LiteLLMLoggingObj,
logging_obj: "LiteLLMLoggingObj",
custom_llm_provider: str | None = None,
request_data: dict | None = None,
) -> VideoObject:
@ -268,7 +264,7 @@ class XAIVideoConfig(BaseVideoConfig):
def transform_video_status_retrieve_response(
self,
raw_response: httpx.Response,
logging_obj: LiteLLMLoggingObj,
logging_obj: "LiteLLMLoggingObj",
custom_llm_provider: str | None = None,
) -> VideoObject:
response_data: Final = raw_response.json()
@ -328,7 +324,7 @@ class XAIVideoConfig(BaseVideoConfig):
def transform_video_content_response(
self,
raw_response: httpx.Response,
logging_obj: LiteLLMLoggingObj,
logging_obj: "LiteLLMLoggingObj",
) -> bytes:
url: Final = self._video_cdn_url(raw_response)
if url is None:
@ -341,7 +337,7 @@ class XAIVideoConfig(BaseVideoConfig):
async def async_transform_video_content_response(
self,
raw_response: httpx.Response,
logging_obj: LiteLLMLoggingObj,
logging_obj: "LiteLLMLoggingObj",
) -> bytes:
url: Final = self._video_cdn_url(raw_response)
if url is None:
@ -360,14 +356,14 @@ class XAIVideoConfig(BaseVideoConfig):
api_base: str,
litellm_params: GenericLiteLLMParams,
headers: dict,
extra_body: dict[str, Any] | None = None,
extra_body: dict[str, object] | None = None,
) -> tuple[str, dict]:
raise NotImplementedError("Video remix is not supported by xAI Imagine API")
def transform_video_remix_response(
self,
raw_response: httpx.Response,
logging_obj: LiteLLMLoggingObj,
logging_obj: "LiteLLMLoggingObj",
custom_llm_provider: str | None = None,
) -> VideoObject:
raise NotImplementedError("Video remix is not supported by xAI Imagine API")
@ -380,14 +376,14 @@ class XAIVideoConfig(BaseVideoConfig):
after: str | None = None,
limit: int | None = None,
order: str | None = None,
extra_query: dict[str, Any] | None = None,
extra_query: dict[str, object] | None = None,
) -> tuple[str, dict]:
raise NotImplementedError("Video listing is not supported by xAI Imagine API")
def transform_video_list_response(
self,
raw_response: httpx.Response,
logging_obj: LiteLLMLoggingObj,
logging_obj: "LiteLLMLoggingObj",
custom_llm_provider: str | None = None,
) -> dict[str, str]:
raise NotImplementedError("Video listing is not supported by xAI Imagine API")
@ -404,6 +400,6 @@ class XAIVideoConfig(BaseVideoConfig):
def transform_video_delete_response(
self,
raw_response: httpx.Response,
logging_obj: LiteLLMLoggingObj,
logging_obj: "LiteLLMLoggingObj",
) -> VideoObject:
raise NotImplementedError("Video delete is not supported by xAI Imagine API")

View file

@ -1,4 +1,5 @@
from typing import Any, Final, Protocol
from collections.abc import Mapping, Sequence
from typing import Final, Protocol
import orjson
@ -35,12 +36,14 @@ def resolve_video_request_model(
return None
def extract_model_from_target_model_names(target_model_names: Any) -> str | None:
def extract_model_from_target_model_names(target_model_names: object) -> str | None:
if isinstance(target_model_names, str):
target_model_names = [m.strip() for m in target_model_names.split(",") if m.strip()]
elif not isinstance(target_model_names, list):
return None
return target_model_names[0] if target_model_names else None
names: Final = tuple(m.strip() for m in target_model_names.split(",") if m.strip())
return names[0] if names else None
if isinstance(target_model_names, Sequence) and not isinstance(target_model_names, (str, bytes)):
first: Final = target_model_names[0] if target_model_names else None
return first if isinstance(first, str) else None
return None
def video_reference_to_id(video_ref: object) -> str:
@ -55,9 +58,9 @@ def video_reference_to_id(video_ref: object) -> str:
return parsed_ref.get("id", "") if isinstance(parsed_ref, dict) else video_ref
def get_custom_provider_from_data(data: dict[str, Any]) -> str | None:
def get_custom_provider_from_data(data: Mapping[str, object]) -> str | None:
custom_llm_provider: Final = data.get("custom_llm_provider")
if custom_llm_provider:
if isinstance(custom_llm_provider, str) and custom_llm_provider:
return custom_llm_provider
extra_body = data.get("extra_body")
@ -77,7 +80,7 @@ def get_custom_provider_from_data(data: dict[str, Any]) -> str | None:
return None
def encode_character_id_in_response(response: Any, custom_llm_provider: str, model_id: str | None) -> Any:
def encode_character_id_in_response(response: object, custom_llm_provider: str, model_id: str | None) -> object:
if isinstance(response, dict) and response.get("id"):
response["id"] = encode_character_id_with_provider(
character_id=response["id"],