fix: treat a single image value as one image instead of iterating it - #737
Open
betacatsling wants to merge 1 commit into
Open
betacatsling wants to merge 1 commit into
betacatsling wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #734.
_copy_imagesiterates whatever it is given. When a caller passes a single image value instead of a list — e.g.client.chat(..., messages=[{'role': 'user', 'images': 'aW1hZ2U='}])orclient.generate(..., images='aW1hZ2U=')— thestr/bytesvalue is aSequence, so it is iterated one character/byte at a time and each element is wrapped in its ownImage. A single base64 string becomes dozens of one-character images and serialization fails with a crypticPydanticSerializationError: ValueError: Invalid image data, expected base64 string or path to image file; a file path string similarly explodes into per-character paths.This wraps a bare
str,bytes,os.PathLike, orImagein a single-element list before iterating, so one image value produces one image in the request. List/tuple input is unchanged.Validation
tests/test_client.py(pytest-httpserver asserts the exact request body sent):test_client_chat_single_image_not_in_list(parametrized over base64 string and raw bytes)test_client_generate_single_image_not_in_listImageand request serialization raisesPydanticSerializationError.pytest tests/test_client.py -k 'single_image or chat_images'— 8 passed; full suitepytest tests/— 100 passed.ruff checkandruff format --checkpass on changed files.