[BugFix]: Fix bagel online inference bug (#1804)

Signed-off-by: princepride <wangzhipeng628@gmail.com>
This commit is contained in:
汪志鹏 authored and GitHub committed 2026-03-13 08:58:44 +00:00
1 parent 26b3ddee47
commit e0b71056ba
5 files changed
+115 -13

No files matched your search

+10 -5
View File
@@ -311,17 +311,21 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
negative_prompt = extra_body.get("negative_prompt")
engine_prompt_image: dict[str, Any] | None = None
is_img2img = False
if reference_images:
# Best-effort decode first reference image for i2i.
try:
img_bytes = base64.b64decode(reference_images[0])
img = Image.open(BytesIO(img_bytes))
engine_prompt_image = {"image": img}
engine_prompt_image = {"img2img": img}
is_img2img = True
except Exception:
engine_prompt_image = None
# Override the prompts produced by chat-template preprocessing.
tprompt: OmniTextPrompt = {"prompt": extracted_prompt}
if is_img2img:
tprompt["modalities"] = ["img2img"]
if negative_prompt is not None:
tprompt["negative_prompt"] = negative_prompt
# GLM-Image's _call_hf_processor expects target_h/target_w in mm_processor_kwargs
@@ -490,10 +494,11 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
)
# Preserve a clean text prompt for downstream stages (e.g., GLM-Image diffusion).
# For /v1/chat/completions, `request_prompt` is often the rendered chat template.
# Diffusion models generally want the raw user caption instead.
output_modalities = getattr(self.engine_client, "output_modalities", None)
if output_modalities and ("image" in output_modalities):
# For image generation, we want the raw user caption instead of a rendered template.
# But for multimodal comprehension (img2text), we MUST keep the rendered prompt
# containing image tokens.
req_modalities = getattr(request, "modalities", [])
if req_modalities and ("image" in req_modalities):
messages_as_dicts: list[dict[str, Any]] = []
for msg in messages:
if hasattr(msg, "model_dump"):