Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/strands/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
_DEFAULT_BEDROCK_MODEL_ID = "{}.anthropic.claude-sonnet-4-6"
DEFAULT_BEDROCK_REGION = "us-west-2"

_BEDROCK_VIDEO_FORMAT_ALIASES = {
"3gp": "three_gp",
"3g2": "three_gp",
"3gpp": "three_gp",
}

BEDROCK_CONTEXT_WINDOW_OVERFLOW_MESSAGES = [
"Input is too long for requested model",
"input length and `max_tokens` exceed context limit",
Expand Down Expand Up @@ -702,7 +708,8 @@ def _format_request_message_content(self, content: ContentBlock) -> dict[str, An
return None
elif "bytes" in source:
formatted_video_source = {"bytes": source["bytes"]}
result = {"format": video["format"], "source": formatted_video_source}
video_format = _BEDROCK_VIDEO_FORMAT_ALIASES.get(video["format"], video["format"])
result = {"format": video_format, "source": formatted_video_source}
return {"video": result}

# https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_CitationsContentBlock.html
Expand Down
22 changes: 22 additions & 0 deletions tests/strands/models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,28 @@ def test_format_request_video_s3_location(model, model_id):
assert video_source == {"s3Location": {"uri": "s3://my-bucket/video.mp4"}}


@pytest.mark.parametrize("video_format", ["3gp", "3g2", "3gpp"])
def test_format_request_maps_3gp_video_formats(model, model_id, video_format):
messages = [
{
"role": "user",
"content": [
{
"video": {
"format": video_format,
"source": {"bytes": b"video_data"},
}
},
],
}
]

formatted_request = model._format_request(messages)

video_block = formatted_request["messages"][0]["content"][0]["video"]
assert video_block == {"format": "three_gp", "source": {"bytes": b"video_data"}}


def test_format_request_filters_document_content_blocks(model, model_id):
"""Test that format_request filters extra fields from document content blocks."""
messages = [
Expand Down