mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Validation error when providing a base64 string to Image(value=...) in Message(images=...)
#185
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @daniel-iliesh on GitHub (Dec 12, 2024).
Originally assigned to: @ParthSareen on GitHub.
I am encountering a validation error while trying to create a
Messageobject with an attached image using theollama._types.Messageandollama._types.Imageclasses.According to the documentation, the
Messageconstructor’s images parameter should accept aSequence[Image], and the Image constructor should accept astr,bytes, orPath.I am passing a single base64-encoded image string directly to the
Image(value=...)constructor, but I receive a validation error indicating that the input is being interpreted as anImageobject rather than a rawstring/bytes/path.What I did:
Imageobject withImage(value=my_base64_string).Imageobjects intoMessage(images=...).Expected behavior:
The
Messageobject should be successfully created with the providedImageobjects, each initialized from a raw base64 string.Actual behavior:
A pydantic validation error is raised:
Full error:
The error suggests that the
Imageconstructor is somehow receiving anotherImageobject instead of a base64 string.Additional details:
Environment:
Python version: 3.10.14
ollama version: 0.5.1
OS: Fedora 41
Code for reference
@ParthSareen commented on GitHub (Dec 12, 2024):
Hey @daniel-iliesh. Dug into this a bit - I think it is to be expected. I think the fix here would be passing in
This is since the generate function accepts a sequence of string or bytes:
Please lmk if you still run into it after this!
@daniel-iliesh commented on GitHub (Dec 13, 2024):
Hey @ParthSareen, thank you for the response.
I did not quite understood the resolution.
I've checked the
Messageclass and it seems that it requires a sequence ofImageobjects forimages:So when i try to do this:
i get this when trying to create a
Message:Also the
generatefunction acceptsNot this
ImageKindbeing just an internal type of mine, it is not related to the problem as i use only the values from thedictwhich arebase64strings.@ggozad commented on GitHub (Dec 29, 2024):
I also see the same issue. I have a list of base64 encoded images.
Constructing a message by
leads to a model validation error not during the contraction of the message but rather later when calling
chat. The culprit is_copy_messages()which seems to be constructing images again.#386 seems to fix the problem.
@ParthSareen commented on GitHub (Jan 21, 2025):
Closed with https://github.com/ollama/ollama-python/pull/390