@@ -320,18 +320,24 @@ async def _map_user_prompt(part: UserPromptPart) -> list[_GeminiPartUnion]:
320
320
content .append ({'text' : item })
321
321
elif isinstance (item , BinaryContent ):
322
322
base64_encoded = base64 .b64encode (item .data ).decode ('utf-8' )
323
- content .append (_GeminiInlineDataPart (data = base64_encoded , mime_type = item .media_type ))
323
+ content .append (
324
+ _GeminiInlineDataPart (inline_data = {'data' : base64_encoded , 'mime_type' : item .media_type })
325
+ )
324
326
elif isinstance (item , (AudioUrl , ImageUrl )):
325
327
try :
326
- content .append (_GeminiFileDataData (file_uri = item .url , mime_type = item .media_type ))
328
+ content .append (
329
+ _GeminiFileDataPart (file_data = {'file_uri' : item .url , 'mime_type' : item .media_type })
330
+ )
327
331
except ValueError :
328
332
# Download the file if can't find the mime type.
329
333
client = cached_async_http_client ()
330
334
response = await client .get (item .url , follow_redirects = True )
331
335
response .raise_for_status ()
332
336
base64_encoded = base64 .b64encode (response .content ).decode ('utf-8' )
333
337
content .append (
334
- _GeminiInlineDataPart (data = base64_encoded , mime_type = response .headers ['Content-Type' ])
338
+ _GeminiInlineDataPart (
339
+ inline_data = {'data' : base64_encoded , 'mime_type' : response .headers ['Content-Type' ]}
340
+ )
335
341
)
336
342
else :
337
343
assert_never (item )
@@ -528,20 +534,28 @@ class _GeminiTextPart(TypedDict):
528
534
text : str
529
535
530
536
537
+ class _GeminiInlineData (TypedDict ):
538
+ data : str
539
+ mime_type : Annotated [str , pydantic .Field (alias = 'mimeType' )]
540
+
541
+
531
542
class _GeminiInlineDataPart (TypedDict ):
532
543
"""See <https://ai.google.dev/api/caching#Blob>."""
533
544
534
- data : str
535
- mime_type : Annotated [str , pydantic .Field (alias = 'mimeType' )]
545
+ inline_data : Annotated [_GeminiInlineData , pydantic .Field (alias = 'inlineData' )]
536
546
537
547
538
- class _GeminiFileDataData (TypedDict ):
548
+ class _GeminiFileData (TypedDict ):
539
549
"""See <https://ai.google.dev/api/caching#FileData>."""
540
550
541
551
file_uri : Annotated [str , pydantic .Field (alias = 'fileUri' )]
542
552
mime_type : Annotated [str , pydantic .Field (alias = 'mimeType' )]
543
553
544
554
555
+ class _GeminiFileDataPart (TypedDict ):
556
+ file_data : Annotated [_GeminiFileData , pydantic .Field (alias = 'fileData' )]
557
+
558
+
545
559
class _GeminiFunctionCallPart (TypedDict ):
546
560
function_call : Annotated [_GeminiFunctionCall , pydantic .Field (alias = 'functionCall' )]
547
561
@@ -617,7 +631,7 @@ def _part_discriminator(v: Any) -> str:
617
631
Annotated [_GeminiFunctionCallPart , pydantic .Tag ('function_call' )],
618
632
Annotated [_GeminiFunctionResponsePart , pydantic .Tag ('function_response' )],
619
633
Annotated [_GeminiInlineDataPart , pydantic .Tag ('inline_data' )],
620
- Annotated [_GeminiFileDataData , pydantic .Tag ('file_data' )],
634
+ Annotated [_GeminiFileDataPart , pydantic .Tag ('file_data' )],
621
635
],
622
636
pydantic .Discriminator (_part_discriminator ),
623
637
]
0 commit comments