I have a valid PIL image (size 1654 x 2339) that I try to include in my query, to no avail.
The code is the following (with langchain):
buffer = BytesIO()
image.save(buffer, format=“JPEG”)
img_str = base64.b64encode(buffer.getvalue())orders = model.invoke(
[
HumanMessage(
content=[
{“type”: “text”, “text”: my_prompt},
{
“type”: “image_url”,
“image_url”: {“url”: f"data:image/jpeg;base64,{img_str}"},
},
]
)
])
I get the following error:
BadRequestError: Error code: 400 - {'error': {'message': "You uploaded an unsupported image. Please make sure your image has of one the following formats: ['png', 'jpeg', 'gif', 'webp'].", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_image_format'}}
Reading the answers that have been posted on this forum, I have tried to reduce the size of the image to 760 x 1075 but in this case I receive another error:
BadRequestError: Error code: 400 - {'error': {'message': 'Invalid base64 image_url.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_base64'}}
Though the encoding looks valid to me: ‘/9j/4AAQSkZJRgABAQAA…’.
What’s the problem?