google-genai 1.33.0__py3-none-any.whl → 1.34.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 +100 -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 +100 -12
- google/genai/types.py +266 -42
- google/genai/version.py +1 -1
- {google_genai-1.33.0.dist-info → google_genai-1.34.0.dist-info}/METADATA +18 -1
- {google_genai-1.33.0.dist-info → google_genai-1.34.0.dist-info}/RECORD +16 -16
- {google_genai-1.33.0.dist-info → google_genai-1.34.0.dist-info}/WHEEL +0 -0
- {google_genai-1.33.0.dist-info → google_genai-1.34.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.33.0.dist-info → google_genai-1.34.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
|
+
raise ValueError('id parameter is not supported in Vertex AI.')
|
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,
|
@@ -1477,6 +1498,23 @@ def _FileData_to_vertex(
|
|
1477
1498
|
return to_object
|
1478
1499
|
|
1479
1500
|
|
1501
|
+
def _FunctionCall_to_vertex(
|
1502
|
+
from_object: Union[dict[str, Any], object],
|
1503
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1504
|
+
) -> dict[str, Any]:
|
1505
|
+
to_object: dict[str, Any] = {}
|
1506
|
+
if getv(from_object, ['id']) is not None:
|
1507
|
+
raise ValueError('id parameter is not supported in Vertex AI.')
|
1508
|
+
|
1509
|
+
if getv(from_object, ['args']) is not None:
|
1510
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
1511
|
+
|
1512
|
+
if getv(from_object, ['name']) is not None:
|
1513
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
1514
|
+
|
1515
|
+
return to_object
|
1516
|
+
|
1517
|
+
|
1480
1518
|
def _Part_to_vertex(
|
1481
1519
|
from_object: Union[dict[str, Any], object],
|
1482
1520
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -1515,6 +1553,15 @@ def _Part_to_vertex(
|
|
1515
1553
|
getv(from_object, ['thought_signature']),
|
1516
1554
|
)
|
1517
1555
|
|
1556
|
+
if getv(from_object, ['function_call']) is not None:
|
1557
|
+
setv(
|
1558
|
+
to_object,
|
1559
|
+
['functionCall'],
|
1560
|
+
_FunctionCall_to_vertex(
|
1561
|
+
getv(from_object, ['function_call']), to_object
|
1562
|
+
),
|
1563
|
+
)
|
1564
|
+
|
1518
1565
|
if getv(from_object, ['code_execution_result']) is not None:
|
1519
1566
|
setv(
|
1520
1567
|
to_object,
|
@@ -1525,9 +1572,6 @@ def _Part_to_vertex(
|
|
1525
1572
|
if getv(from_object, ['executable_code']) is not None:
|
1526
1573
|
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
|
1527
1574
|
|
1528
|
-
if getv(from_object, ['function_call']) is not None:
|
1529
|
-
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
|
1530
|
-
|
1531
1575
|
if getv(from_object, ['function_response']) is not None:
|
1532
1576
|
setv(
|
1533
1577
|
to_object,
|
@@ -3714,6 +3758,23 @@ def _FileData_from_mldev(
|
|
3714
3758
|
return to_object
|
3715
3759
|
|
3716
3760
|
|
3761
|
+
def _FunctionCall_from_mldev(
|
3762
|
+
from_object: Union[dict[str, Any], object],
|
3763
|
+
parent_object: Optional[dict[str, Any]] = None,
|
3764
|
+
) -> dict[str, Any]:
|
3765
|
+
to_object: dict[str, Any] = {}
|
3766
|
+
if getv(from_object, ['id']) is not None:
|
3767
|
+
setv(to_object, ['id'], getv(from_object, ['id']))
|
3768
|
+
|
3769
|
+
if getv(from_object, ['args']) is not None:
|
3770
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
3771
|
+
|
3772
|
+
if getv(from_object, ['name']) is not None:
|
3773
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
3774
|
+
|
3775
|
+
return to_object
|
3776
|
+
|
3777
|
+
|
3717
3778
|
def _Part_from_mldev(
|
3718
3779
|
from_object: Union[dict[str, Any], object],
|
3719
3780
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -3752,6 +3813,15 @@ def _Part_from_mldev(
|
|
3752
3813
|
getv(from_object, ['thoughtSignature']),
|
3753
3814
|
)
|
3754
3815
|
|
3816
|
+
if getv(from_object, ['functionCall']) is not None:
|
3817
|
+
setv(
|
3818
|
+
to_object,
|
3819
|
+
['function_call'],
|
3820
|
+
_FunctionCall_from_mldev(
|
3821
|
+
getv(from_object, ['functionCall']), to_object
|
3822
|
+
),
|
3823
|
+
)
|
3824
|
+
|
3755
3825
|
if getv(from_object, ['codeExecutionResult']) is not None:
|
3756
3826
|
setv(
|
3757
3827
|
to_object,
|
@@ -3762,9 +3832,6 @@ def _Part_from_mldev(
|
|
3762
3832
|
if getv(from_object, ['executableCode']) is not None:
|
3763
3833
|
setv(to_object, ['executable_code'], getv(from_object, ['executableCode']))
|
3764
3834
|
|
3765
|
-
if getv(from_object, ['functionCall']) is not None:
|
3766
|
-
setv(to_object, ['function_call'], getv(from_object, ['functionCall']))
|
3767
|
-
|
3768
3835
|
if getv(from_object, ['functionResponse']) is not None:
|
3769
3836
|
setv(
|
3770
3837
|
to_object,
|
@@ -4376,6 +4443,21 @@ def _FileData_from_vertex(
|
|
4376
4443
|
return to_object
|
4377
4444
|
|
4378
4445
|
|
4446
|
+
def _FunctionCall_from_vertex(
|
4447
|
+
from_object: Union[dict[str, Any], object],
|
4448
|
+
parent_object: Optional[dict[str, Any]] = None,
|
4449
|
+
) -> dict[str, Any]:
|
4450
|
+
to_object: dict[str, Any] = {}
|
4451
|
+
|
4452
|
+
if getv(from_object, ['args']) is not None:
|
4453
|
+
setv(to_object, ['args'], getv(from_object, ['args']))
|
4454
|
+
|
4455
|
+
if getv(from_object, ['name']) is not None:
|
4456
|
+
setv(to_object, ['name'], getv(from_object, ['name']))
|
4457
|
+
|
4458
|
+
return to_object
|
4459
|
+
|
4460
|
+
|
4379
4461
|
def _Part_from_vertex(
|
4380
4462
|
from_object: Union[dict[str, Any], object],
|
4381
4463
|
parent_object: Optional[dict[str, Any]] = None,
|
@@ -4414,6 +4496,15 @@ def _Part_from_vertex(
|
|
4414
4496
|
getv(from_object, ['thoughtSignature']),
|
4415
4497
|
)
|
4416
4498
|
|
4499
|
+
if getv(from_object, ['functionCall']) is not None:
|
4500
|
+
setv(
|
4501
|
+
to_object,
|
4502
|
+
['function_call'],
|
4503
|
+
_FunctionCall_from_vertex(
|
4504
|
+
getv(from_object, ['functionCall']), to_object
|
4505
|
+
),
|
4506
|
+
)
|
4507
|
+
|
4417
4508
|
if getv(from_object, ['codeExecutionResult']) is not None:
|
4418
4509
|
setv(
|
4419
4510
|
to_object,
|
@@ -4424,9 +4515,6 @@ def _Part_from_vertex(
|
|
4424
4515
|
if getv(from_object, ['executableCode']) is not None:
|
4425
4516
|
setv(to_object, ['executable_code'], getv(from_object, ['executableCode']))
|
4426
4517
|
|
4427
|
-
if getv(from_object, ['functionCall']) is not None:
|
4428
|
-
setv(to_object, ['function_call'], getv(from_object, ['functionCall']))
|
4429
|
-
|
4430
4518
|
if getv(from_object, ['functionResponse']) is not None:
|
4431
4519
|
setv(
|
4432
4520
|
to_object,
|