Skip to content

[BUG] receiving 'invalid start byte' when using ImageSource with Azure OpenAI #85

Open
@patrickpenn

Description

@patrickpenn

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

0.1.3

Python Version

3.12

Operating System

Windows 11

Installation Method

pip

Steps to Reproduce

  1. Generate image bytes
  2. Create a message with:
Message(role="user", content=[ContentBlock(image=ImageContent(format=ImageFormat[str(file_extension)], source=ImageSource(bytes=image_blob)))])
  1. run the agent against Azure OpenAI

Expected Behavior

The ability to use ImageSource optionally with an base64 encoded image.

Actual Behavior

Azure OpenAI expects base64 encoded format instead of bytes.

I tried using this code:

Message(role="user", content=[ContentBlock(image=ImageContent(format=ImageFormat[str(file_extension)], source=ImageSource(bytes=image_blob)))])

But i received the following error when running the agent with the message:
UnicodeDecodeError('utf-8', b'\xff\xd8\xff...
reason =
'invalid start byte'
start =
0

Additional Context

This works within a normal completion:

user_content = [
        {
            "type": "image_url",
            "image_url": {
                "url": f"data:image/jpeg;base64,{encoded_image}"
            }
        }
    ]

Possible Solution

Support base64 encoded string in ImageSource

Related Issues

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions