@@ -1787,8 +1787,8 @@ def test_format_request_filters_image_content_blocks(model, model_id):
17871787 assert "metadata" not in image_block
17881788
17891789
1790- def test_format_request_filters_nested_image_s3_fields (model , model_id ):
1791- """Test that s3Location is filtered out and only bytes source is preserved ."""
1790+ def test_format_request_image_s3_location_only (model , model_id ):
1791+ """Test that image with only s3Location is properly formatted ."""
17921792 messages = [
17931793 {
17941794 "role" : "user" ,
@@ -1797,10 +1797,41 @@ def test_format_request_filters_nested_image_s3_fields(model, model_id):
17971797 "image" : {
17981798 "format" : "png" ,
17991799 "source" : {
1800- "bytes" : b"image_data" ,
1801- "s3Location" : {"bucket" : "my-bucket" , "key" : "image.png" , "extraField" : "filtered" },
1800+ "s3Location" : {"uri" : "s3://my-bucket/image.png" },
18021801 },
18031802 }
1803+ },
1804+ {
1805+ "image" : {
1806+ "format" : "png" ,
1807+ "source" : {
1808+ "s3Location" : {"uri" : "s3://my-bucket/image.png" , "bucketOwner" : "12345" },
1809+ },
1810+ }
1811+ },
1812+ ],
1813+ }
1814+ ]
1815+
1816+ formatted_request = model ._format_request (messages )
1817+ image_source = formatted_request ["messages" ][0 ]["content" ][0 ]["image" ]["source" ]
1818+ image_source_with_bucket_owner = formatted_request ["messages" ][0 ]["content" ][1 ]["image" ]["source" ]
1819+
1820+ assert image_source == {"s3Location" : {"uri" : "s3://my-bucket/image.png" }}
1821+ assert image_source_with_bucket_owner == {"s3Location" : {"uri" : "s3://my-bucket/image.png" , "bucketOwner" : "12345" }}
1822+
1823+
1824+ def test_format_request_image_bytes_only (model , model_id ):
1825+ """Test that image with only bytes source is properly formatted."""
1826+ messages = [
1827+ {
1828+ "role" : "user" ,
1829+ "content" : [
1830+ {
1831+ "image" : {
1832+ "format" : "png" ,
1833+ "source" : {"bytes" : b"image_data" },
1834+ }
18041835 }
18051836 ],
18061837 }
@@ -1810,7 +1841,79 @@ def test_format_request_filters_nested_image_s3_fields(model, model_id):
18101841 image_source = formatted_request ["messages" ][0 ]["content" ][0 ]["image" ]["source" ]
18111842
18121843 assert image_source == {"bytes" : b"image_data" }
1813- assert "s3Location" not in image_source
1844+
1845+
1846+ def test_format_request_document_s3_location (model , model_id ):
1847+ """Test that document with s3Location is properly formatted."""
1848+ messages = [
1849+ {
1850+ "role" : "user" ,
1851+ "content" : [
1852+ {
1853+ "document" : {
1854+ "name" : "report.pdf" ,
1855+ "format" : "pdf" ,
1856+ "source" : {
1857+ "s3Location" : {"uri" : "s3://my-bucket/report.pdf" },
1858+ },
1859+ }
1860+ },
1861+ {
1862+ "document" : {
1863+ "name" : "report.pdf" ,
1864+ "format" : "pdf" ,
1865+ "source" : {
1866+ "s3Location" : {"uri" : "s3://my-bucket/report.pdf" , "bucketOwner" : "123456789012" },
1867+ },
1868+ }
1869+ },
1870+ ],
1871+ }
1872+ ]
1873+
1874+ formatted_request = model ._format_request (messages )
1875+ document = formatted_request ["messages" ][0 ]["content" ][0 ]["document" ]
1876+ document_with_bucket_owner = formatted_request ["messages" ][0 ]["content" ][1 ]["document" ]
1877+
1878+ assert document ["source" ] == {"s3Location" : {"uri" : "s3://my-bucket/report.pdf" }}
1879+
1880+ assert document_with_bucket_owner ["source" ] == {
1881+ "s3Location" : {"uri" : "s3://my-bucket/report.pdf" , "bucketOwner" : "123456789012" }
1882+ }
1883+
1884+
1885+ def test_format_request_video_s3_location (model , model_id ):
1886+ """Test that video with s3Location is properly formatted."""
1887+ messages = [
1888+ {
1889+ "role" : "user" ,
1890+ "content" : [
1891+ {
1892+ "video" : {
1893+ "format" : "mp4" ,
1894+ "source" : {
1895+ "s3Location" : {"uri" : "s3://my-bucket/video.mp4" },
1896+ },
1897+ }
1898+ },
1899+ {
1900+ "video" : {
1901+ "format" : "mp4" ,
1902+ "source" : {
1903+ "s3Location" : {"uri" : "s3://my-bucket/video.mp4" , "bucketOwner" : "12345" },
1904+ },
1905+ }
1906+ },
1907+ ],
1908+ }
1909+ ]
1910+
1911+ formatted_request = model ._format_request (messages )
1912+ video_source = formatted_request ["messages" ][0 ]["content" ][0 ]["video" ]["source" ]
1913+ video_source_with_bucket_owner = formatted_request ["messages" ][0 ]["content" ][1 ]["video" ]["source" ]
1914+
1915+ assert video_source == {"s3Location" : {"uri" : "s3://my-bucket/video.mp4" }}
1916+ assert video_source_with_bucket_owner == {"s3Location" : {"uri" : "s3://my-bucket/video.mp4" , "bucketOwner" : "12345" }}
18141917
18151918
18161919def test_format_request_filters_document_content_blocks (model , model_id ):
0 commit comments