[Feature] Align MiniMax H3 official input matrix (#5752)

Signed-off-by: david6666666 <530634352@qq.com>
This commit is contained in:
WeiQing Chen authored and GitHub committed 2026-08-05 07:12:01 +00:00
1 parent 6a604be610
commit ae7bee0c43
21 files changed
+1887 -331

No files matched your search

+56 -16
View File
@@ -8,6 +8,8 @@ from __future__ import annotations
import base64
import binascii
import os
import tempfile
from io import BytesIO
from typing import Any, Literal
@@ -36,10 +38,17 @@ from vllm_omni.entrypoints.openai.protocol.videos import (
class VideoFrames(list[Image.Image]):
"""Decoded video frames plus source metadata."""
def __init__(self, frames: list[Image.Image] | None = None, *, fps: float | None = None) -> None:
def __init__(
self,
frames: list[Image.Image] | None = None,
*,
fps: float | None = None,
source_path: str | None = None,
) -> None:
super().__init__(frames or [])
self.fps = fps
self.frame_rate = fps
self.source_path = source_path
def positive_float(value: Any) -> float | None:
@@ -93,6 +102,7 @@ def _decode_video_bytes(
source: str,
max_frames: int | None = None,
keep: Literal["first", "last"] = "first",
source_path: str | None = None,
) -> VideoFrames:
if keep not in {"first", "last"}:
raise InvalidInputReferenceError(f"Invalid {source}: video frame selection must be 'first' or 'last'.")
@@ -116,8 +126,7 @@ def _decode_video_bytes(
frames = [Image.fromarray(f, "RGB") for f in frames_array]
if not frames:
raise InvalidInputReferenceError(f"Invalid {source}: provided content is not a valid video.")
return VideoFrames(frames, fps=fps)
return VideoFrames(frames, fps=fps, source_path=source_path)
def _decode_media_bytes(
@@ -182,6 +191,7 @@ def _decode_base64_video(
source: str,
max_frames: int | None = None,
keep: Literal["first", "last"] = "first",
source_path: str | None = None,
) -> VideoFrames:
if video_reference:
if video_reference.startswith("data:video"):
@@ -193,7 +203,16 @@ def _decode_base64_video(
video_bytes = base64.b64decode(b64_data)
except (binascii.Error, ValueError) as exc: # pragma: no cover - malformed base64
raise InvalidInputReferenceError(f"Invalid {source}: video data is not valid base64.") from exc
return _decode_video_bytes(video_bytes, source=source, max_frames=max_frames, keep=keep)
if source_path is not None:
with open(source_path, "wb") as output:
output.write(video_bytes)
return _decode_video_bytes(
video_bytes,
source=source,
max_frames=max_frames,
keep=keep,
source_path=source_path,
)
raise InvalidInputReferenceError(f"Invalid {source}: video data is empty.")
@@ -204,12 +223,19 @@ async def decode_video_url(
keep: Literal["first", "last"] = "first",
) -> VideoFrames:
if video_url.startswith("data:video"):
return _decode_base64_video(
video_url,
source="video_reference.video_url",
max_frames=max_frames,
keep=keep,
)
path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
try:
return _decode_base64_video(
video_url,
source="video_reference.video_url",
max_frames=max_frames,
keep=keep,
source_path=path,
)
except Exception:
if os.path.exists(path):
os.unlink(path)
raise
if video_url.startswith(("http://", "https://")):
async with httpx.AsyncClient(timeout=60) as client:
@@ -220,12 +246,26 @@ async def decode_video_url(
raise InvalidInputReferenceError(
"Invalid video_reference.video_url: failed to download video."
) from exc
return _decode_video_bytes(
response.content,
source="video_reference.video_url",
max_frames=max_frames,
keep=keep,
)
path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
try:
with open(path, "wb") as output:
output.write(response.content)
except Exception:
if os.path.exists(path):
os.unlink(path)
raise
try:
return _decode_video_bytes(
response.content,
source="video_reference.video_url",
max_frames=max_frames,
keep=keep,
source_path=path,
)
except Exception:
if os.path.exists(path):
os.unlink(path)
raise
raise InvalidInputReferenceError("Invalid video_reference.video_url: must be an http(s) URL or data URL.")