8787 ),
8888)
8989
90+ FILE_URI_TEST_CASES = [
91+ pytest .param ("gs://bucket/document.pdf" , "application/pdf" , id = "pdf" ),
92+ pytest .param ("gs://bucket/data.json" , "application/json" , id = "json" ),
93+ ]
9094
9195STREAMING_MODEL_RESPONSE = [
9296 ModelResponse (
@@ -1088,15 +1092,7 @@ def test_content_to_message_param_user_message():
10881092 assert message ["content" ] == "Test prompt"
10891093
10901094
1091- @pytest .mark .parametrize (
1092- "file_uri,mime_type" ,
1093- [
1094- ("gs://bucket/document.pdf" , "application/pdf" ),
1095- ("gs://bucket/data.json" , "application/json" ),
1096- ("gs://bucket/spreadsheet.csv" , "text/csv" ),
1097- ],
1098- ids = ["pdf" , "json" , "csv" ],
1099- )
1095+ @pytest .mark .parametrize ("file_uri,mime_type" , FILE_URI_TEST_CASES )
11001096def test_content_to_message_param_user_message_with_file_uri (
11011097 file_uri , mime_type
11021098):
@@ -1119,10 +1115,11 @@ def test_content_to_message_param_user_message_with_file_uri(
11191115 assert message ["content" ][1 ]["file" ]["format" ] == mime_type
11201116
11211117
1122- def test_content_to_message_param_user_message_file_uri_only ():
1123- file_part = types .Part .from_uri (
1124- file_uri = "gs://bucket/only.pdf" , mime_type = "application/pdf"
1125- )
1118+ @pytest .mark .parametrize ("file_uri,mime_type" , FILE_URI_TEST_CASES )
1119+ def test_content_to_message_param_user_message_file_uri_only (
1120+ file_uri , mime_type
1121+ ):
1122+ file_part = types .Part .from_uri (file_uri = file_uri , mime_type = mime_type )
11261123 content = types .Content (
11271124 role = "user" ,
11281125 parts = [
@@ -1134,8 +1131,8 @@ def test_content_to_message_param_user_message_file_uri_only():
11341131 assert message ["role" ] == "user"
11351132 assert isinstance (message ["content" ], list )
11361133 assert message ["content" ][0 ]["type" ] == "file"
1137- assert message ["content" ][0 ]["file" ]["file_id" ] == "gs://bucket/only.pdf"
1138- assert message ["content" ][0 ]["file" ]["format" ] == "application/pdf"
1134+ assert message ["content" ][0 ]["file" ]["file_id" ] == file_uri
1135+ assert message ["content" ][0 ]["file" ]["format" ] == mime_type
11391136
11401137
11411138def test_content_to_message_param_multi_part_function_response ():
@@ -1316,17 +1313,28 @@ def test_get_content_pdf():
13161313 assert content [0 ]["file" ]["format" ] == "application/pdf"
13171314
13181315
1319- def test_get_content_file_uri ():
1316+ def test_get_content_json ():
13201317 parts = [
1321- types .Part .from_uri (
1322- file_uri = "gs://bucket/document.pdf" ,
1323- mime_type = "application/pdf" ,
1318+ types .Part .from_bytes (
1319+ data = b'{"hello":"world"}' , mime_type = "application/json"
13241320 )
13251321 ]
13261322 content = _get_content (parts )
13271323 assert content [0 ]["type" ] == "file"
1328- assert content [0 ]["file" ]["file_id" ] == "gs://bucket/document.pdf"
1329- assert content [0 ]["file" ]["format" ] == "application/pdf"
1324+ assert (
1325+ content [0 ]["file" ]["file_data" ]
1326+ == "data:application/json;base64,eyJoZWxsbyI6IndvcmxkIn0="
1327+ )
1328+ assert content [0 ]["file" ]["format" ] == "application/json"
1329+
1330+
1331+ @pytest .mark .parametrize ("file_uri,mime_type" , FILE_URI_TEST_CASES )
1332+ def test_get_content_file_uri (file_uri , mime_type ):
1333+ parts = [types .Part .from_uri (file_uri = file_uri , mime_type = mime_type )]
1334+ content = _get_content (parts )
1335+ assert content [0 ]["type" ] == "file"
1336+ assert content [0 ]["file" ]["file_id" ] == file_uri
1337+ assert content [0 ]["file" ]["format" ] == mime_type
13301338
13311339
13321340def test_get_content_audio ():
0 commit comments