google-genai 1.33.0__py3-none-any.whl → 1.35.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/genai/_common.py +5 -1
- google/genai/_extra_utils.py +5 -8
- google/genai/_live_converters.py +102 -44
- google/genai/_tokens_converters.py +24 -3
- google/genai/_transformers.py +55 -15
- google/genai/batches.py +680 -142
- google/genai/caches.py +50 -6
- google/genai/local_tokenizer.py +29 -1
- google/genai/models.py +130 -12
- google/genai/types.py +302 -42
- google/genai/version.py +1 -1
- {google_genai-1.33.0.dist-info → google_genai-1.35.0.dist-info}/METADATA +18 -1
- {google_genai-1.33.0.dist-info → google_genai-1.35.0.dist-info}/RECORD +16 -16
- {google_genai-1.33.0.dist-info → google_genai-1.35.0.dist-info}/WHEEL +0 -0
- {google_genai-1.33.0.dist-info → google_genai-1.35.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.33.0.dist-info → google_genai-1.35.0.dist-info}/top_level.txt +0 -0
google/genai/caches.py
CHANGED
@@ -84,6 +84,23 @@ def _FileData_to_mldev(
|
|
84
84
|
return to_object
|
85
85
|
|
86
86
|
|
87
|
+
def _FunctionCall_to_mldev(
|
88
|
+
from_object: Union[dict[str, Any], object],
|
89
|
+
parent_object: Optional[dict[str, Any]] = None,
|
90
|
+
) -> dict[str, Any]:
|
91
|
+
to_object: dict[str, Any] = {}
|
92
|
+
if getv(from_object, ['id']) is not None:
|
93
|
+
setv(to_object, ['id'], getv(from_object, ['id']))
|
94
|
+
|
95
|
+
if getv(from_object, ['args']) is not None:
|
96
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
97
|
+
|
98
|
+
if getv(from_object, ['name']) is not None:
|
99
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
100
|
+
|
101
|
+
return to_object
|
102
|
+
|
103
|
+
|
87
104
|
def _Part_to_mldev(
|
88
105
|
from_object: Union[dict[str, Any], object],
|
89
106
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -122,6 +139,13 @@ def _Part_to_mldev(
|
|
122
139
|
getv(from_object, ['thought_signature']),
|
123
140
|
)
|
124
141
|
|
142
|
+
if getv(from_object, ['function_call']) is not None:
|
143
|
+
setv(
|
144
|
+
to_object,
|
145
|
+
['functionCall'],
|
146
|
+
_FunctionCall_to_mldev(getv(from_object, ['function_call']), to_object),
|
147
|
+
)
|
148
|
+
|
125
149
|
if getv(from_object, ['code_execution_result']) is not None:
|
126
150
|
setv(
|
127
151
|
to_object,
|
@@ -132,9 +156,6 @@ def _Part_to_mldev(
|
|
132
156
|
if getv(from_object, ['executable_code']) is not None:
|
133
157
|
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
|
134
158
|
|
135
|
-
if getv(from_object, ['function_call']) is not None:
|
136
|
-
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
|
137
|
-
|
138
159
|
if getv(from_object, ['function_response']) is not None:
|
139
160
|
setv(
|
140
161
|
to_object,
|
@@ -684,6 +705,23 @@ def _FileData_to_vertex(
|
|
684
705
|
return to_object
|
685
706
|
|
686
707
|
|
708
|
+
def _FunctionCall_to_vertex(
|
709
|
+
from_object: Union[dict[str, Any], object],
|
710
|
+
parent_object: Optional[dict[str, Any]] = None,
|
711
|
+
) -> dict[str, Any]:
|
712
|
+
to_object: dict[str, Any] = {}
|
713
|
+
if getv(from_object, ['id']) is not None:
|
714
|
+
setv(to_object, ['id'], getv(from_object, ['id']))
|
715
|
+
|
716
|
+
if getv(from_object, ['args']) is not None:
|
717
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
718
|
+
|
719
|
+
if getv(from_object, ['name']) is not None:
|
720
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
721
|
+
|
722
|
+
return to_object
|
723
|
+
|
724
|
+
|
687
725
|
def _Part_to_vertex(
|
688
726
|
from_object: Union[dict[str, Any], object],
|
689
727
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -722,6 +760,15 @@ def _Part_to_vertex(
|
|
722
760
|
getv(from_object, ['thought_signature']),
|
723
761
|
)
|
724
762
|
|
763
|
+
if getv(from_object, ['function_call']) is not None:
|
764
|
+
setv(
|
765
|
+
to_object,
|
766
|
+
['functionCall'],
|
767
|
+
_FunctionCall_to_vertex(
|
768
|
+
getv(from_object, ['function_call']), to_object
|
769
|
+
),
|
770
|
+
)
|
771
|
+
|
725
772
|
if getv(from_object, ['code_execution_result']) is not None:
|
726
773
|
setv(
|
727
774
|
to_object,
|
@@ -732,9 +779,6 @@ def _Part_to_vertex(
|
|
732
779
|
if getv(from_object, ['executable_code']) is not None:
|
733
780
|
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
|
734
781
|
|
735
|
-
if getv(from_object, ['function_call']) is not None:
|
736
|
-
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
|
737
|
-
|
738
782
|
if getv(from_object, ['function_response']) is not None:
|
739
783
|
setv(
|
740
784
|
to_object,
|
google/genai/local_tokenizer.py
CHANGED
@@ -303,9 +303,20 @@ class LocalTokenizer:
|
|
303
303
|
|
304
304
|
Args:
|
305
305
|
contents: The contents to tokenize.
|
306
|
+
config: The configuration for counting tokens.
|
306
307
|
|
307
308
|
Returns:
|
308
309
|
A `CountTokensResult` containing the total number of tokens.
|
310
|
+
|
311
|
+
Usage:
|
312
|
+
|
313
|
+
.. code-block:: python
|
314
|
+
|
315
|
+
from google import genai
|
316
|
+
tokenizer = genai.LocalTokenizer(model_name='gemini-2.0-flash-001')
|
317
|
+
result = tokenizer.count_tokens("What is your name?")
|
318
|
+
print(result)
|
319
|
+
# total_tokens=5
|
309
320
|
"""
|
310
321
|
processed_contents = t.t_contents(contents)
|
311
322
|
text_accumulator = _TextsAccumulator()
|
@@ -330,7 +341,24 @@ class LocalTokenizer:
|
|
330
341
|
self,
|
331
342
|
contents: Union[types.ContentListUnion, types.ContentListUnionDict],
|
332
343
|
) -> types.ComputeTokensResult:
|
333
|
-
"""Computes the tokens ids and string pieces in the input.
|
344
|
+
"""Computes the tokens ids and string pieces in the input.
|
345
|
+
|
346
|
+
Args:
|
347
|
+
contents: The contents to tokenize.
|
348
|
+
|
349
|
+
Returns:
|
350
|
+
A `ComputeTokensResult` containing the token information.
|
351
|
+
|
352
|
+
Usage:
|
353
|
+
|
354
|
+
.. code-block:: python
|
355
|
+
|
356
|
+
from google import genai
|
357
|
+
tokenizer = genai.LocalTokenizer(model_name='gemini-2.0-flash-001')
|
358
|
+
result = tokenizer.compute_tokens("What is your name?")
|
359
|
+
print(result)
|
360
|
+
# tokens_info=[TokensInfo(token_ids=[279, 329, 1313, 2508, 13], tokens=[b' What', b' is', b' your', b' name', b'?'], role='user')]
|
361
|
+
"""
|
334
362
|
processed_contents = t.t_contents(contents)
|
335
363
|
text_accumulator = _TextsAccumulator()
|
336
364
|
for content in processed_contents:
|
google/genai/models.py
CHANGED
@@ -88,6 +88,23 @@ def _FileData_to_mldev(
|
|
88
88
|
return to_object
|
89
89
|
|
90
90
|
|
91
|
+
def _FunctionCall_to_mldev(
|
92
|
+
from_object: Union[dict[str, Any], object],
|
93
|
+
parent_object: Optional[dict[str, Any]] = None,
|
94
|
+
) -> dict[str, Any]:
|
95
|
+
to_object: dict[str, Any] = {}
|
96
|
+
if getv(from_object, ['id']) is not None:
|
97
|
+
setv(to_object, ['id'], getv(from_object, ['id']))
|
98
|
+
|
99
|
+
if getv(from_object, ['args']) is not None:
|
100
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
101
|
+
|
102
|
+
if getv(from_object, ['name']) is not None:
|
103
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
104
|
+
|
105
|
+
return to_object
|
106
|
+
|
107
|
+
|
91
108
|
def _Part_to_mldev(
|
92
109
|
from_object: Union[dict[str, Any], object],
|
93
110
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -126,6 +143,13 @@ def _Part_to_mldev(
|
|
126
143
|
getv(from_object, ['thought_signature']),
|
127
144
|
)
|
128
145
|
|
146
|
+
if getv(from_object, ['function_call']) is not None:
|
147
|
+
setv(
|
148
|
+
to_object,
|
149
|
+
['functionCall'],
|
150
|
+
_FunctionCall_to_mldev(getv(from_object, ['function_call']), to_object),
|
151
|
+
)
|
152
|
+
|
129
153
|
if getv(from_object, ['code_execution_result']) is not None:
|
130
154
|
setv(
|
131
155
|
to_object,
|
@@ -136,9 +160,6 @@ def _Part_to_mldev(
|
|
136
160
|
if getv(from_object, ['executable_code']) is not None:
|
137
161
|
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
|
138
162
|
|
139
|
-
if getv(from_object, ['function_call']) is not None:
|
140
|
-
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
|
141
|
-
|
142
163
|
if getv(from_object, ['function_response']) is not None:
|
143
164
|
setv(
|
144
165
|
to_object,
|
@@ -1371,6 +1392,9 @@ def _GenerateVideosConfig_to_mldev(
|
|
1371
1392
|
'reference_images parameter is not supported in Gemini API.'
|
1372
1393
|
)
|
1373
1394
|
|
1395
|
+
if getv(from_object, ['mask']) is not None:
|
1396
|
+
raise ValueError('mask parameter is not supported in Gemini API.')
|
1397
|
+
|
1374
1398
|
if getv(from_object, ['compression_quality']) is not None:
|
1375
1399
|
raise ValueError(
|
1376
1400
|
'compression_quality parameter is not supported in Gemini API.'
|
@@ -1477,6 +1501,23 @@ def _FileData_to_vertex(
|
|
1477
1501
|
return to_object
|
1478
1502
|
|
1479
1503
|
|
1504
|
+
def _FunctionCall_to_vertex(
|
1505
|
+
from_object: Union[dict[str, Any], object],
|
1506
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1507
|
+
) -> dict[str, Any]:
|
1508
|
+
to_object: dict[str, Any] = {}
|
1509
|
+
if getv(from_object, ['id']) is not None:
|
1510
|
+
setv(to_object, ['id'], getv(from_object, ['id']))
|
1511
|
+
|
1512
|
+
if getv(from_object, ['args']) is not None:
|
1513
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
1514
|
+
|
1515
|
+
if getv(from_object, ['name']) is not None:
|
1516
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
1517
|
+
|
1518
|
+
return to_object
|
1519
|
+
|
1520
|
+
|
1480
1521
|
def _Part_to_vertex(
|
1481
1522
|
from_object: Union[dict[str, Any], object],
|
1482
1523
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1515,6 +1556,15 @@ def _Part_to_vertex(
|
|
1515
1556
|
getv(from_object, ['thought_signature']),
|
1516
1557
|
)
|
1517
1558
|
|
1559
|
+
if getv(from_object, ['function_call']) is not None:
|
1560
|
+
setv(
|
1561
|
+
to_object,
|
1562
|
+
['functionCall'],
|
1563
|
+
_FunctionCall_to_vertex(
|
1564
|
+
getv(from_object, ['function_call']), to_object
|
1565
|
+
),
|
1566
|
+
)
|
1567
|
+
|
1518
1568
|
if getv(from_object, ['code_execution_result']) is not None:
|
1519
1569
|
setv(
|
1520
1570
|
to_object,
|
@@ -1525,9 +1575,6 @@ def _Part_to_vertex(
|
|
1525
1575
|
if getv(from_object, ['executable_code']) is not None:
|
1526
1576
|
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
|
1527
1577
|
|
1528
|
-
if getv(from_object, ['function_call']) is not None:
|
1529
|
-
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
|
1530
|
-
|
1531
1578
|
if getv(from_object, ['function_response']) is not None:
|
1532
1579
|
setv(
|
1533
1580
|
to_object,
|
@@ -3492,6 +3539,24 @@ def _VideoGenerationReferenceImage_to_vertex(
|
|
3492
3539
|
return to_object
|
3493
3540
|
|
3494
3541
|
|
3542
|
+
def _VideoGenerationMask_to_vertex(
|
3543
|
+
from_object: Union[dict[str, Any], object],
|
3544
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3545
|
+
) -> dict[str, Any]:
|
3546
|
+
to_object: dict[str, Any] = {}
|
3547
|
+
if getv(from_object, ['image']) is not None:
|
3548
|
+
setv(
|
3549
|
+
to_object,
|
3550
|
+
['_self'],
|
3551
|
+
_Image_to_vertex(getv(from_object, ['image']), to_object),
|
3552
|
+
)
|
3553
|
+
|
3554
|
+
if getv(from_object, ['mask_mode']) is not None:
|
3555
|
+
setv(to_object, ['maskMode'], getv(from_object, ['mask_mode']))
|
3556
|
+
|
3557
|
+
return to_object
|
3558
|
+
|
3559
|
+
|
3495
3560
|
def _GenerateVideosConfig_to_vertex(
|
3496
3561
|
from_object: Union[dict[str, Any], object],
|
3497
3562
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -3591,6 +3656,13 @@ def _GenerateVideosConfig_to_vertex(
|
|
3591
3656
|
],
|
3592
3657
|
)
|
3593
3658
|
|
3659
|
+
if getv(from_object, ['mask']) is not None:
|
3660
|
+
setv(
|
3661
|
+
parent_object,
|
3662
|
+
['instances[0]', 'mask'],
|
3663
|
+
_VideoGenerationMask_to_vertex(getv(from_object, ['mask']), to_object),
|
3664
|
+
)
|
3665
|
+
|
3594
3666
|
if getv(from_object, ['compression_quality']) is not None:
|
3595
3667
|
setv(
|
3596
3668
|
parent_object,
|
@@ -3714,6 +3786,23 @@ def _FileData_from_mldev(
|
|
3714
3786
|
return to_object
|
3715
3787
|
|
3716
3788
|
|
3789
|
+
def _FunctionCall_from_mldev(
|
3790
|
+
from_object: Union[dict[str, Any], object],
|
3791
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3792
|
+
) -> dict[str, Any]:
|
3793
|
+
to_object: dict[str, Any] = {}
|
3794
|
+
if getv(from_object, ['id']) is not None:
|
3795
|
+
setv(to_object, ['id'], getv(from_object, ['id']))
|
3796
|
+
|
3797
|
+
if getv(from_object, ['args']) is not None:
|
3798
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
3799
|
+
|
3800
|
+
if getv(from_object, ['name']) is not None:
|
3801
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
3802
|
+
|
3803
|
+
return to_object
|
3804
|
+
|
3805
|
+
|
3717
3806
|
def _Part_from_mldev(
|
3718
3807
|
from_object: Union[dict[str, Any], object],
|
3719
3808
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -3752,6 +3841,15 @@ def _Part_from_mldev(
|
|
3752
3841
|
getv(from_object, ['thoughtSignature']),
|
3753
3842
|
)
|
3754
3843
|
|
3844
|
+
if getv(from_object, ['functionCall']) is not None:
|
3845
|
+
setv(
|
3846
|
+
to_object,
|
3847
|
+
['function_call'],
|
3848
|
+
_FunctionCall_from_mldev(
|
3849
|
+
getv(from_object, ['functionCall']), to_object
|
3850
|
+
),
|
3851
|
+
)
|
3852
|
+
|
3755
3853
|
if getv(from_object, ['codeExecutionResult']) is not None:
|
3756
3854
|
setv(
|
3757
3855
|
to_object,
|
@@ -3762,9 +3860,6 @@ def _Part_from_mldev(
|
|
3762
3860
|
if getv(from_object, ['executableCode']) is not None:
|
3763
3861
|
setv(to_object, ['executable_code'], getv(from_object, ['executableCode']))
|
3764
3862
|
|
3765
|
-
if getv(from_object, ['functionCall']) is not None:
|
3766
|
-
setv(to_object, ['function_call'], getv(from_object, ['functionCall']))
|
3767
|
-
|
3768
3863
|
if getv(from_object, ['functionResponse']) is not None:
|
3769
3864
|
setv(
|
3770
3865
|
to_object,
|
@@ -4376,6 +4471,23 @@ def _FileData_from_vertex(
|
|
4376
4471
|
return to_object
|
4377
4472
|
|
4378
4473
|
|
4474
|
+
def _FunctionCall_from_vertex(
|
4475
|
+
from_object: Union[dict[str, Any], object],
|
4476
|
+
parent_object: Optional[dict[str, Any]] = None,
|
4477
|
+
) -> dict[str, Any]:
|
4478
|
+
to_object: dict[str, Any] = {}
|
4479
|
+
if getv(from_object, ['id']) is not None:
|
4480
|
+
setv(to_object, ['id'], getv(from_object, ['id']))
|
4481
|
+
|
4482
|
+
if getv(from_object, ['args']) is not None:
|
4483
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
4484
|
+
|
4485
|
+
if getv(from_object, ['name']) is not None:
|
4486
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
4487
|
+
|
4488
|
+
return to_object
|
4489
|
+
|
4490
|
+
|
4379
4491
|
def _Part_from_vertex(
|
4380
4492
|
from_object: Union[dict[str, Any], object],
|
4381
4493
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -4414,6 +4526,15 @@ def _Part_from_vertex(
|
|
4414
4526
|
getv(from_object, ['thoughtSignature']),
|
4415
4527
|
)
|
4416
4528
|
|
4529
|
+
if getv(from_object, ['functionCall']) is not None:
|
4530
|
+
setv(
|
4531
|
+
to_object,
|
4532
|
+
['function_call'],
|
4533
|
+
_FunctionCall_from_vertex(
|
4534
|
+
getv(from_object, ['functionCall']), to_object
|
4535
|
+
),
|
4536
|
+
)
|
4537
|
+
|
4417
4538
|
if getv(from_object, ['codeExecutionResult']) is not None:
|
4418
4539
|
setv(
|
4419
4540
|
to_object,
|
@@ -4424,9 +4545,6 @@ def _Part_from_vertex(
|
|
4424
4545
|
if getv(from_object, ['executableCode']) is not None:
|
4425
4546
|
setv(to_object, ['executable_code'], getv(from_object, ['executableCode']))
|
4426
4547
|
|
4427
|
-
if getv(from_object, ['functionCall']) is not None:
|
4428
|
-
setv(to_object, ['function_call'], getv(from_object, ['functionCall']))
|
4429
|
-
|
4430
4548
|
if getv(from_object, ['functionResponse']) is not None:
|
4431
4549
|
setv(
|
4432
4550
|
to_object,
|