Skip to content

Pass s3:// file URLs directly to API in BedrockConverseModel #3621

@DouweM

Description

@DouweM

See https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference-call.html, under Request > messages > video:

You can also specify an Amazon S3 URI instead of passing the bytes directly in the request body. The following shows a sample Message object with a content array containing the source passed through an Amazon S3 URI.

{
    "role": "user",
    "content": [
        {
            "video": {
                "format": "mp4",
                "source": {
                    "s3Location": {
                        "uri": "s3://amzn-s3-demo-bucket/myVideo",
                        "bucketOwner": "111122223333"
                    }
                }
            }
        }
    ]
}

The assumed role must have the s3:GetObject permission to the Amazon S3 URI. The bucketOwner field is optional but must be specified if the account making the request does not own the bucket the Amazon S3 URI is found in. For more information, see Configure access to Amazon S3 buckets.

We’d just need to edit this:

elif isinstance(item, ImageUrl | DocumentUrl | VideoUrl):
downloaded_item = await download_item(item, data_format='bytes', type_format='extension')
format = downloaded_item['data_type']
if item.kind == 'image-url':
format = item.media_type.split('/')[1]
assert format in ('jpeg', 'png', 'gif', 'webp'), f'Unsupported image format: {format}'
image: ImageBlockTypeDef = {'format': format, 'source': {'bytes': downloaded_item['data']}}
content.append({'image': image})

We already support gs:// URLs with GoogleModel as well, as documented on https://ai.pydantic.dev/input.

Also related to:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions