ollama / ollama/ollama-python

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

Open Beginner friendly
#734 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.