Skip to content

fix(python): scope VLM modality check to the current turn#1132

Closed
Mengsheng Wu (mengshengwu) wants to merge 1 commit into
mainfrom
fix/python-vlm-multi-turn-modality
Closed

fix(python): scope VLM modality check to the current turn#1132
Mengsheng Wu (mengshengwu) wants to merge 1 commit into
mainfrom
fix/python-vlm-multi-turn-modality

Conversation

@mengshengwu

Copy link
Copy Markdown
Contributor

Closes #1131

Summary

_messages_have_modality walked the full chat history when deciding whether the pre-generate() guard should fire; it now inspects only the last message, matching how the Go CLI / server extract media (only from the current turn).

Test plan

  • _messages_have_modality returns False when only prior turns hold {type: image} / {type: audio} blocks and the current turn is text-only (new test_messages_have_modality_ignores_prior_turns)
  • _messages_have_modality still fires on the current turn's media block (new test_messages_have_modality_detects_current_turn)
  • _messages_have_modality([], modality) returns False (new test_messages_have_modality_empty)
  • pytest bindings/python/tests/unit/test_error_messages.py -q → 25 passed

The pre-generate guard scanned the full history for image/audio blocks,
which broke any second turn of a VLM chat that started with media: the
prior turn's block was still present in messages, so generate(images=[])
raised even though the current user turn was text-only. Go CLI / server
already extract media only from the last message; align Python with
that.
@mengshengwu

Copy link
Copy Markdown
Contributor Author

Superseded by #1130 which fixes the same bug plus a related test ordering issue. Regression tests from this PR have been ported over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

python: multi-turn VLM raises on generate() when prior turn had media

1 participant