Skip to content

Commit 2e47315

Browse files
committed
Add s3 location tests including video
1 parent 57144d4 commit 2e47315

File tree

13 files changed

+81
-109
lines changed

13 files changed

+81
-109
lines changed

src/strands/models/bedrock.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ def _format_request_message_content(self, content: ContentBlock) -> dict[str, An
494494
source = document["source"]
495495
if "s3Location" in source:
496496
s3_loc = source["s3Location"]
497-
formatted_s3: dict[str, Any] = {"uri": s3_loc["uri"]}
497+
formatted_document_s3: dict[str, Any] = {"uri": s3_loc["uri"]}
498498
if "bucketOwner" in s3_loc:
499-
formatted_s3["bucketOwner"] = s3_loc["bucketOwner"]
500-
result["source"] = {"s3Location": formatted_s3}
499+
formatted_document_s3["bucketOwner"] = s3_loc["bucketOwner"]
500+
result["source"] = {"s3Location": formatted_document_s3}
501501
elif "bytes" in source:
502502
result["source"] = {"bytes": source["bytes"]}
503503

@@ -520,16 +520,16 @@ def _format_request_message_content(self, content: ContentBlock) -> dict[str, An
520520
if "image" in content:
521521
image = content["image"]
522522
source = image["source"]
523-
formatted_source: dict[str, Any] = {}
523+
formatted_image_source: dict[str, Any] = {}
524524
if "s3Location" in source:
525525
s3_loc = source["s3Location"]
526-
formatted_s3: dict[str, Any] = {"uri": s3_loc["uri"]}
526+
formatted_image_s3: dict[str, Any] = {"uri": s3_loc["uri"]}
527527
if "bucketOwner" in s3_loc:
528-
formatted_s3["bucketOwner"] = s3_loc["bucketOwner"]
529-
formatted_source = {"s3Location": formatted_s3}
528+
formatted_image_s3["bucketOwner"] = s3_loc["bucketOwner"]
529+
formatted_image_source = {"s3Location": formatted_image_s3}
530530
elif "bytes" in source:
531-
formatted_source = {"bytes": source["bytes"]}
532-
result = {"format": image["format"], "source": formatted_source}
531+
formatted_image_source = {"bytes": source["bytes"]}
532+
result = {"format": image["format"], "source": formatted_image_source}
533533
return {"image": result}
534534

535535
# https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ReasoningContentBlock.html
@@ -591,16 +591,16 @@ def _format_request_message_content(self, content: ContentBlock) -> dict[str, An
591591
if "video" in content:
592592
video = content["video"]
593593
source = video["source"]
594-
formatted_source: dict[str, Any] = {}
594+
formatted_video_source: dict[str, Any] = {}
595595
if "s3Location" in source:
596596
s3_loc = source["s3Location"]
597-
formatted_s3: dict[str, Any] = {"uri": s3_loc["uri"]}
597+
formatted_video_s3: dict[str, Any] = {"uri": s3_loc["uri"]}
598598
if "bucketOwner" in s3_loc:
599-
formatted_s3["bucketOwner"] = s3_loc["bucketOwner"]
600-
formatted_source = {"s3Location": formatted_s3}
599+
formatted_video_s3["bucketOwner"] = s3_loc["bucketOwner"]
600+
formatted_video_source = {"s3Location": formatted_video_s3}
601601
elif "bytes" in source:
602-
formatted_source = {"bytes": source["bytes"]}
603-
result = {"format": video["format"], "source": formatted_source}
602+
formatted_video_source = {"bytes": source["bytes"]}
603+
result = {"format": video["format"], "source": formatted_video_source}
604604
return {"video": result}
605605

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

src/strands/models/gemini.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,12 @@ def _format_request_content(self, messages: Messages) -> list[genai.types.Conten
242242
continue
243243
parts.append(self._format_request_content_part(content, tool_use_id_to_name))
244244

245-
if parts:
246-
contents.append(
247-
genai.types.Content(
248-
parts=parts,
249-
role="user" if message["role"] == "user" else "model",
250-
)
245+
contents.append(
246+
genai.types.Content(
247+
parts=parts,
248+
role="user" if message["role"] == "user" else "model",
251249
)
250+
)
252251

253252
return contents
254253

tests/strands/models/test__validation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Tests for model validation helper functions."""
22

3-
import pytest
4-
53
from strands.models._validation import _has_s3_source
64

75

tests/strands/tools/mcp/test_mcp_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def test_call_tool_sync_embedded_nested_base64_textual_mime(mock_transport, mock
632632
def test_call_tool_sync_embedded_image_blob(mock_transport, mock_session):
633633
"""EmbeddedResource.resource (blob with image MIME) should map to image content."""
634634
# Read yellow.png file
635-
with open("tests_integ/yellow.png", "rb") as image_file:
635+
with open("tests_integ/resources/yellow.png", "rb") as image_file:
636636
png_data = image_file.read()
637637
payload = base64.b64encode(png_data).decode()
638638

tests/strands/types/test_media.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
"""Tests for media type definitions."""
22

33
from strands.types.media import (
4-
DocumentFormat,
54
DocumentSource,
6-
ImageFormat,
75
ImageSource,
86
S3Location,
9-
VideoFormat,
107
VideoSource,
118
)
129

tests_integ/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,21 @@ def pytest_sessionstart(session):
133133

134134
@pytest.fixture
135135
def yellow_img(pytestconfig):
136-
path = pytestconfig.rootdir / "tests_integ/yellow.png"
136+
path = pytestconfig.rootdir / "tests_integ/resources/yellow.png"
137137
with open(path, "rb") as fp:
138138
return fp.read()
139139

140140

141141
@pytest.fixture
142142
def letter_pdf(pytestconfig):
143-
path = pytestconfig.rootdir / "tests_integ/letter.pdf"
143+
path = pytestconfig.rootdir / "tests_integ/resources/letter.pdf"
144+
with open(path, "rb") as fp:
145+
return fp.read()
146+
147+
148+
@pytest.fixture
149+
def blue_video(pytestconfig):
150+
path = pytestconfig.rootdir / "tests_integ/resources/blue.mp4"
144151
with open(path, "rb") as fp:
145152
return fp.read()
146153

tests_integ/mcp/echo_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def get_weather(location: Literal["New York", "London", "Tokyo"] = "New York"):
9090
]
9191
elif location.lower() == "tokyo":
9292
# Read yellow.png file for weather icon
93-
with open("tests_integ/yellow.png", "rb") as image_file:
93+
with open("tests_integ/resources/yellow.png", "rb") as image_file:
9494
png_data = image_file.read()
9595
return [
9696
EmbeddedResource(

tests_integ/mcp/test_mcp_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def calculator(x: int, y: int) -> int:
4343
@mcp.tool(description="Generates a custom image")
4444
def generate_custom_image() -> MCPImageContent:
4545
try:
46-
with open("tests_integ/yellow.png", "rb") as image_file:
46+
with open("tests_integ/resources/yellow.png", "rb") as image_file:
4747
encoded_image = base64.b64encode(image_file.read())
4848
return MCPImageContent(type="image", data=encoded_image, mimeType="image/png")
4949
except Exception as e:

tests_integ/resources/blue.mp4

5.08 KB
Binary file not shown.

0 commit comments

Comments
 (0)