Skip to content

Conversation

@mochow13
Copy link
Contributor

@mochow13 mochow13 commented Dec 7, 2025

Closes #3621

@DouweM DouweM changed the title #3621 - Pass s3:// file URLs directly to API in BedrockConverseModel Pass s3:// file URLs directly to API in BedrockConverseModel Dec 9, 2025
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']}}
image: ImageBlockTypeDef = {'format': format, 'source': cast(Any, source)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of casting this to Any, can we fix the source type hint to be DocumentSourceTypeDef?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

'name': name,
'format': item.format,
'source': {'bytes': downloaded_item['data']},
'source': cast(Any, source),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

format = downloaded_item['data_type']
source: dict[str, Any]
if item.url.startswith('s3://'):
source = {'s3Location': {'uri': item.url}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a bucketOwner field that users may want to set. Maybe we can tell them to encode it as a query param on the URL, and parse it out here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like s3://my-bucket/key?bucketOwner=owner?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's what I was thinking

if item.url.startswith('s3://'):
source = {'s3Location': {'uri': item.url}}
else:
downloaded_item = await download_item(item, data_format='bytes', type_format='extension')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

download_item currently has logic gating for gs:// URLs; let's check s3:// URLs there as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the existing code in download_item checks for gs:// and youtube URLs:

    if item.url.startswith('gs://'):
        raise UserError('Downloading from protocol "gs://" is not supported.')
    elif isinstance(item, VideoUrl) and item.is_youtube:
        raise UserError('Downloading YouTube videos is not supported.')

What check do you mean for s3:// here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same check raising an error saying that download_item does not support s3:// URLs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok need to stop supporting download altogether. Updated.
Kept the check pretty simple. Not sure whether we should go for a proper url parsing here since the expectation is just bucketOwner param.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not drastically more code, I'd prefer proper URL parsing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document this feature in input.md. At the bottom there's already a section on uploaded files to Google, can you mention S3 files + BedrockConverseModel there as well please?

Copy link
Contributor Author

@mochow13 mochow13 Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DouweM I have updated the doc. Added a paragraph for S3 + BedrockConverseModel. Also updated the section above to mention that S3 files will not be downloaded.

Looking at the doc, I am a bit confused. Given that we have updated download_item to skip downloading s3:// URLs altogether, won't it apply to all models? For example, if we pass a s3:// URL to a model that doesn't support downloading itself, because of our check, Pydantic AI will also stop downloading for that particular model, right?

Not sure if I question is clear enough. Basically, in this MR, we are passing the s3:// URL directly to BedrockConverseModel but we have updated downloaed_item function to raise an error if s3:// is passed. This would mean we will stop downloading from s3://URLs for other models, no?

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']}}
image: ImageBlockTypeDef = {'format': format, 'source': cast(DocumentSourceTypeDef, source)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need to cast if hint the type of source to be source: DocumentSourceTypeDef

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants