Skip to content

Commit 5944452

Browse files
committed
fix(bedrock): normalize 3gp video format
1 parent 46ce50b commit 5944452

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/strands/models/bedrock.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
_DEFAULT_BEDROCK_MODEL_ID = "{}.anthropic.claude-sonnet-4-6"
4444
DEFAULT_BEDROCK_REGION = "us-west-2"
4545

46+
_BEDROCK_VIDEO_FORMAT_ALIASES = {
47+
"3gp": "three_gp",
48+
"3g2": "three_gp",
49+
"3gpp": "three_gp",
50+
}
51+
4652
BEDROCK_CONTEXT_WINDOW_OVERFLOW_MESSAGES = [
4753
"Input is too long for requested model",
4854
"input length and `max_tokens` exceed context limit",
@@ -702,7 +708,8 @@ def _format_request_message_content(self, content: ContentBlock) -> dict[str, An
702708
return None
703709
elif "bytes" in source:
704710
formatted_video_source = {"bytes": source["bytes"]}
705-
result = {"format": video["format"], "source": formatted_video_source}
711+
video_format = _BEDROCK_VIDEO_FORMAT_ALIASES.get(video["format"], video["format"])
712+
result = {"format": video_format, "source": formatted_video_source}
706713
return {"video": result}
707714

708715
# https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_CitationsContentBlock.html

tests/strands/models/test_bedrock.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,28 @@ def test_format_request_video_s3_location(model, model_id):
22542254
assert video_source == {"s3Location": {"uri": "s3://my-bucket/video.mp4"}}
22552255

22562256

2257+
@pytest.mark.parametrize("video_format", ["3gp", "3g2", "3gpp"])
2258+
def test_format_request_maps_3gp_video_formats(model, model_id, video_format):
2259+
messages = [
2260+
{
2261+
"role": "user",
2262+
"content": [
2263+
{
2264+
"video": {
2265+
"format": video_format,
2266+
"source": {"bytes": b"video_data"},
2267+
}
2268+
},
2269+
],
2270+
}
2271+
]
2272+
2273+
formatted_request = model._format_request(messages)
2274+
2275+
video_block = formatted_request["messages"][0]["content"][0]["video"]
2276+
assert video_block == {"format": "three_gp", "source": {"bytes": b"video_data"}}
2277+
2278+
22572279
def test_format_request_filters_document_content_blocks(model, model_id):
22582280
"""Test that format_request filters extra fields from document content blocks."""
22592281
messages = [

0 commit comments

Comments
 (0)