Skip to content

fix: treat a bare str/bytes image as one image, not per-character - #756

Open
er-s-an wants to merge 1 commit into
ollama:mainfrom
er-s-an:fix/single-image-not-iterated
Open

er-s-an wants to merge 1 commit into
ollama:mainfrom
er-s-an:fix/single-image-not-iterated

Conversation

@er-s-an

@er-s-an er-s-an commented Oct 9, 2026

Copy link
Copy Markdown

Summary

Fixes #734.

_copy_images iterates its argument. A bare str / bytes / path-like / Image is a Sequence, so it was iterated character/byte-wise and each fragment became its own Image. That produced cryptic serialization errors for chat message images and exploded file paths for generate(..., images=...).

Wrap a single image value in a one-element list before iterating. List/tuple input is unchanged.

Validation

python -m venv .venv && .venv/bin/pip install -e . pytest pytest-anyio pytest-httpserver
.venv/bin/pytest tests/test_client.py -k 'single_image or chat_images or generate_with_image' -q
# 9 passed
.venv/bin/pytest tests/ -q
# 118 passed

New regression tests:

  • test_client_chat_single_image_not_in_list (parametrized over base64 string and raw bytes)
  • test_client_generate_single_image_not_in_list

Fixes ollama#734. str and bytes are Sequences, so _copy_images iterated them
character/byte-wise and each fragment became its own Image. Wrap a single
image value before iterating; list/tuple input is unchanged.

This branch has not been deployed

No deployments
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.

A single image passed as a bare string/bytes is iterated character-by-character

1 participant