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
refactor(guardrails): satisfy the type-discipline gate in the video handler
yucheng652bddfdc60a
diff --git a/litellm/llms/openai/videos/guardrail_translation/__init__.py b/litellm/llms/openai/videos/guardrail_translation/__init__.pyindex 6540ba994e4..7bd869612d6 100644--- a/litellm/llms/openai/videos/guardrail_translation/__init__.py+++ b/litellm/llms/openai/videos/guardrail_translation/__init__.py@@ -7,7 +7,7 @@ from litellm.llms.openai.videos.guardrail_translation.handler import ()from litellm.types.utils import CallTypes-guardrail_translation_mappings: Final = {+guardrail_translation_mappings: Final = { # mutable-ok: discover_guardrail_translation_mappings only accepts isinstance(mappings, dict)CallTypes.video_generation: OpenAIVideoGenerationHandler,CallTypes.avideo_generation: OpenAIVideoGenerationHandler,CallTypes.create_video: OpenAIVideoGenerationHandler,@@ -20,4 +20,4 @@ guardrail_translation_mappings: Final = {CallTypes.avideo_extension: OpenAIVideoGenerationHandler,}-__all__ = ["OpenAIVideoGenerationHandler", "guardrail_translation_mappings"]+__all__ = ("OpenAIVideoGenerationHandler", "guardrail_translation_mappings")diff --git a/litellm/llms/openai/videos/guardrail_translation/handler.py b/litellm/llms/openai/videos/guardrail_translation/handler.pyindex 74fafb4bcfe..3735094c87b 100644--- a/litellm/llms/openai/videos/guardrail_translation/handler.py+++ b/litellm/llms/openai/videos/guardrail_translation/handler.py@@ -14,19 +14,20 @@ class OpenAIVideoGenerationHandler(BaseTranslation):async def process_input_messages(self,- data: dict[str, object],+ data: dict[str, object], # mutable-ok: BaseTranslation contract passes the proxy's request dict throughguardrail_to_apply: "CustomGuardrail",litellm_logging_obj: "LiteLLMLoggingObj | None" = None,- ) -> dict[str, object]:+ ) -> dict[str, object]: # mutable-ok: BaseTranslation contract returns the proxy's request dictprompt: Final = data.get("prompt")if not isinstance(prompt, str):return datamodel: Final = data.get("model")+ texts: Final = [prompt] # mutable-ok: GenericGuardrailAPIInputs.texts is declared list[str]inputs: Final = (- GenericGuardrailAPIInputs(texts=[prompt], model=model)+ GenericGuardrailAPIInputs(texts=texts, model=model)if isinstance(model, str)- else GenericGuardrailAPIInputs(texts=[prompt])+ else GenericGuardrailAPIInputs(texts=texts))guardrailed_inputs: Final = await guardrail_to_apply.apply_guardrail( # pyright: ignore[reportUnknownMemberType] # request_data is a bare dictinputs=inputs,@@ -34,8 +35,9 @@ class OpenAIVideoGenerationHandler(BaseTranslation):input_type="request",logging_obj=litellm_logging_obj,)- guardrailed_texts: Final = guardrailed_inputs.get("texts", [])- return {**data, "prompt": guardrailed_texts[0] if guardrailed_texts else prompt}+ guardrailed_texts: Final = guardrailed_inputs.get("texts")+ guardrailed_prompt: Final = guardrailed_texts[0] if guardrailed_texts else prompt+ return {**data, "prompt": guardrailed_prompt} # mutable-ok: BaseTranslation contract returns a dictasync def process_output_response(self,@@ -43,6 +45,6 @@ class OpenAIVideoGenerationHandler(BaseTranslation):guardrail_to_apply: "CustomGuardrail",litellm_logging_obj: "LiteLLMLoggingObj | None" = None,user_api_key_dict: "UserAPIKeyAuth | None" = None,- request_data: dict[str, object] | None = None,+ request_data: dict[str, object] | None = None, # mutable-ok: BaseTranslation contract) -> object:return response