[BugFix][Diffusion] Preserve image payloads with reasoning metadata (#5238)

Signed-off-by: akshatvishu <akshatnayak197@gmail.com>
This commit is contained in:
akshatvishu authored and GitHub committed 2026-07-22 00:49:18 +08:00
1 parent 9ca98009b2
commit d34b91722f
2 files changed
+38 -4

No files matched your search

@@ -241,6 +241,41 @@ def test_formatter_preserves_text_envelope_metadata(monkeypatch: pytest.MonkeyPa
}
@pytest.mark.parametrize(
"text_metadata",
[
pytest.param({"think_text": "reasoning"}, id="sensenova-bagel-thinking"),
pytest.param({"ar_generated_text": "reasoning"}, id="hunyuan-image3-cot"),
],
)
def test_formatter_preserves_image_with_reasoning_metadata(
monkeypatch: pytest.MonkeyPatch,
text_metadata: dict[str, str],
) -> None:
monkeypatch.setattr(output_formatter, "supports_audio_output", lambda _: False)
metadata = {"text": text_metadata}
postprocess_output = normalize_diffusion_postprocess_output(
{
"payload": {"image": "image-0"},
"metadata": metadata,
}
)
[result] = format_diffusion_outputs(
request=_request("generate an image"),
od_config=_config(),
diffusion_output=DiffusionOutput(output=None),
output_data=None,
postprocess_output=postprocess_output,
timings=_timings(),
)
assert postprocess_output.primary_key == "image"
assert result.images == ["image-0"]
assert result.final_output_type == "image"
assert result.multimodal_output == {"metadata": metadata}
def test_formatter_preserves_audio_output_with_model_sample_rate_fallback(
monkeypatch: pytest.MonkeyPatch,
) -> None:
+3 -4
View File
@@ -149,10 +149,9 @@ def format_diffusion_outputs(
"postprocess_time_ms": timings.postprocess_time_s * 1000,
}
# Detect text output: when the pipeline returns a string (e.g.,
# SenseNova-U1 / BAGEL single-stage img2text / text2text), wrap it
# as a text-type response instead of an image.
is_text_output = postprocess_output.primary_key == "text" or "text" in postprocess_output.metadata
# Only the primary payload determines the response type. Some image models
# include reasoning text in metadata, but their final output is still an image.
is_text_output = postprocess_output.primary_key == "text"
is_audio_output = supports_audio_output(od_config.model_class_name)
audio_sample_rate = _metadata_audio_sample_rate(postprocess_output.metadata)