A single image passed as a bare string/bytes is iterated character-by-character
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.5k
- Forks
- 1.2k
- Avg merge
- 4m
- Merged PRs (30d)
- 1
Description
Actual behavior
chat/generate accept images as a sequence, but a bare str or bytes is itself a Sequence, so _copy_images iterates it element-wise and wraps each character/byte in its own Image:
client.chat(model='m', messages=[{'role': 'user', 'content': 'hi', 'images': 'aW1hZ2U='}])
# 6 "images" ('a', 'W', '1', ...) -> PydanticSerializationError:
# ValueError: Invalid image data, expected base64 string or path to image file
client.generate(model='m', prompt='hi', images='/tmp/photo.png')
# '/tmp/photo.png' becomes 14 one-character image values, starting with '/'
# (which happens to exist as a directory -> IsADirectoryError)
Expected behavior
A single image value (str, bytes, path-like, or Image) is treated as one image, producing images: [<value>] in the request — matching what callers intend and what the API expects.
Environment
- ollama-python: main @ fa8509936be08809bd15ca90a371165eb9abeb50
- pydantic 2.10.6, Python 3.11
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the _copy_images helper and trace how chat and generate pass their image arguments into the request. Add coverage for bare str, bytes, path-like, and Image values, and verify each is serialized as one image rather than iterated element-by-element.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100