Skip to content

fix: normalize images in create message mappings - #775

Draft
er-s-an wants to merge 1 commit into
ollama:mainfrom
er-s-an:fix/create-message-images-20261022
Draft

er-s-an wants to merge 1 commit into
ollama:mainfrom
er-s-an:fix/create-message-images-20261022

Conversation

@er-s-an

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

Copy link
Copy Markdown

Passing raw image bytes or a Path inside a message dictionary to create() fails before sending the request; a string path is sent literally rather than as image data. chat() already normalizes these image inputs. The server's CreateRequest.Messages uses the same Message.Images structure.

Normalize image values in create message mappings for both clients using the existing image conversion. Preserve all other mapping fields, including empty content and extension fields, and keep existing Message instances and omitted/empty message lists unchanged. Input messages are not mutated.

Validation on Linux, Python 3.12.14, locked Pydantic 2.10.6 / HTTPX 0.28.1:

  • Added 32 cases across sync/async, streaming/non-streaming, bytes, Path/string paths, base64, Image and Message inputs, plus compatibility controls. Before: 12 failed / 20 passed. After: all pass.
  • NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 .venv/bin/python -m pytest ollama tests -q: 154 passed, including doctests.
  • .venv/bin/ruff check ., .venv/bin/ruff format --check . (47 files), uv lock --check, exact uv export comparison with requirements.txt, and git diff --check pass.
  • Independent localhost HTTP probe: before, TypeError: Object of type bytes is not JSON serializable; after, the server receives the expected base64 image and the SDK parses its success response.

The localhost probe is an HTTP fixture, not a real Ollama server or model inference. The full Hatch Python/OS matrix was not run; Python 3.8 syntax was checked, not its runtime. No dependency or lockfile changes.

Source-discovered on upstream 35d9667. Searched create/images and create/messages issues and PRs before publication; no matching implementation found. This does not implement bare-image handling in #734/#756, which changes how _copy_images interprets a scalar.

AI assistance: OpenAI Codex investigated, implemented, ran these checks, and inspected the final diff in a separate review pass. No human pre-review is claimed. Keeping this PR in draft for maintainer review and CI qualification.

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.

1 participant