@@ -276,22 +276,21 @@ private static function get_content_transformers(): array {
276
276
$ parts = array ();
277
277
foreach ( $ content ->get_parts () as $ part ) {
278
278
if ( $ part instanceof Text_Part ) {
279
- $ data = $ part ->to_array ();
280
- $ parts [] = array ( 'text ' => $ data ['text ' ] );
279
+ $ parts [] = array ( 'text ' => $ part ->get_text () );
281
280
} elseif ( $ part instanceof Inline_Data_Part ) {
282
- $ data = $ part ->to_array ();
281
+ $ mime_type = $ part ->get_mime_type ();
283
282
if (
284
- str_starts_with ( $ data [ ' inlineData ' ][ ' mimeType ' ] , 'image/ ' )
285
- || str_starts_with ( $ data [ ' inlineData ' ][ ' mimeType ' ] , 'audio/ ' )
283
+ str_starts_with ( $ mime_type , 'image/ ' )
284
+ || str_starts_with ( $ mime_type , 'audio/ ' )
286
285
) {
287
286
$ parts [] = array (
288
287
'inlineData ' => array (
289
- 'mimeType ' => $ data [ ' inlineData ' ][ ' mimeType ' ] ,
288
+ 'mimeType ' => $ mime_type ,
290
289
// The Google AI API expects inlineData blobs to be without the prefix.
291
290
'data ' => preg_replace (
292
291
'/^data:[a-z]+\/[a-z]+;base64,/ ' ,
293
292
'' ,
294
- $ data [ ' inlineData ' ][ ' data ' ]
293
+ $ part -> get_base64_data ()
295
294
),
296
295
),
297
296
);
@@ -301,15 +300,15 @@ private static function get_content_transformers(): array {
301
300
);
302
301
}
303
302
} elseif ( $ part instanceof File_Data_Part ) {
304
- $ data = $ part ->to_array ();
303
+ $ mime_type = $ part ->get_mime_type ();
305
304
if (
306
- str_starts_with ( $ data [ ' fileData ' ][ ' mimeType ' ] , 'image/ ' )
307
- || str_starts_with ( $ data [ ' fileData ' ][ ' mimeType ' ] , 'audio/ ' )
305
+ str_starts_with ( $ mime_type , 'image/ ' )
306
+ || str_starts_with ( $ mime_type , 'audio/ ' )
308
307
) {
309
308
$ parts [] = array (
310
309
'fileData ' => array (
311
- 'mimeType ' => $ data [ ' fileData ' ][ ' mimeType ' ] ,
312
- 'fileUri ' => $ data [ ' fileData ' ][ ' fileUri ' ] ,
310
+ 'mimeType ' => $ mime_type ,
311
+ 'fileUri ' => $ part -> get_file_uri () ,
313
312
),
314
313
);
315
314
} else {
0 commit comments