Skip to content

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

Open

Description

@betacatsling

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 @ fa85099
  • pydantic 2.10.6, Python 3.11

Activity

  1. ZYZ666-RGB commented on Nov 25, 2026

    @ZYZ666-RGB

    I'd like to take this. Plan: treat a bare str, bytes, or Image passed as images as a single image in _copy_images (and message image fields), instead of iterating characters or bytes. I'll add unit tests. A PR will follow shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions