[VLM] Support request level max_dynamic_patch for OpenAI request (#16268)

Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
This commit is contained in:
Yuan Luo
2026-01-04 13:04:43 +08:00
committed by GitHub
parent 229938805f
commit 5f3eb377e0
6 changed files with 98 additions and 7 deletions

View File

@@ -154,18 +154,34 @@ def process_content_for_template_format(
chunk_type = chunk.get("type")
if chunk_type == "image_url":
image_obj = chunk.get("image_url") or {}
mdp = image_obj.get("max_dynamic_patch", None)
# Also allow flat style: chunk["max_dynamic_patch"]
image_data.append(
ImageData(
url=chunk["image_url"]["url"],
detail=chunk["image_url"].get("detail", "auto"),
url=image_obj["url"],
detail=image_obj.get("detail", "auto"),
max_dynamic_patch=mdp,
)
)
if chunk.get("modalities"):
modalities.append(chunk.get("modalities"))
# Normalize to simple 'image' type for template compatibility
processed_content_parts.append({"type": "image"})
elif chunk_type == "video_url":
video_data.append(chunk["video_url"]["url"])
video_obj = chunk.get("video_url") or {}
mdp = video_obj.get("max_dynamic_patch", None)
if mdp is None:
video_data.append(chunk["video_url"]["url"])
else:
# Keep structured info for backend, but template only sees {"type":"video"}
video_data.append(
{
"url": video_obj["url"],
"max_dynamic_patch": mdp,
}
)
if chunk.get("modalities"):
modalities.append(chunk.get("modalities"))
# Normalize to simple 'video' type for template compatibility