google-genai 1.10.0__py3-none-any.whl → 1.12.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/_api_client.py +100 -31
- google/genai/_automatic_function_calling_util.py +4 -24
- google/genai/_common.py +40 -37
- google/genai/_extra_utils.py +72 -12
- google/genai/_live_converters.py +2487 -0
- google/genai/_replay_api_client.py +32 -26
- google/genai/_transformers.py +119 -25
- google/genai/batches.py +45 -45
- google/genai/caches.py +126 -126
- google/genai/chats.py +13 -9
- google/genai/client.py +3 -2
- google/genai/errors.py +6 -6
- google/genai/files.py +38 -38
- google/genai/live.py +138 -1029
- google/genai/models.py +455 -387
- google/genai/operations.py +33 -33
- google/genai/pagers.py +2 -2
- google/genai/py.typed +1 -0
- google/genai/tunings.py +70 -70
- google/genai/types.py +964 -45
- google/genai/version.py +1 -1
- {google_genai-1.10.0.dist-info → google_genai-1.12.0.dist-info}/METADATA +1 -1
- google_genai-1.12.0.dist-info/RECORD +29 -0
- {google_genai-1.10.0.dist-info → google_genai-1.12.0.dist-info}/WHEEL +1 -1
- google_genai-1.10.0.dist-info/RECORD +0 -27
- {google_genai-1.10.0.dist-info → google_genai-1.12.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.10.0.dist-info → google_genai-1.12.0.dist-info}/top_level.txt +0 -0
google/genai/caches.py
CHANGED
@@ -32,9 +32,9 @@ logger = logging.getLogger('google_genai.caches')
|
|
32
32
|
|
33
33
|
def _Part_to_mldev(
|
34
34
|
api_client: BaseApiClient,
|
35
|
-
from_object: Union[dict, object],
|
36
|
-
parent_object: Optional[dict] = None,
|
37
|
-
) -> dict:
|
35
|
+
from_object: Union[dict[str, Any], object],
|
36
|
+
parent_object: Optional[dict[str, Any]] = None,
|
37
|
+
) -> dict[str, Any]:
|
38
38
|
to_object: dict[str, Any] = {}
|
39
39
|
if getv(from_object, ['video_metadata']) is not None:
|
40
40
|
raise ValueError('video_metadata parameter is not supported in Gemini API.')
|
@@ -76,9 +76,9 @@ def _Part_to_mldev(
|
|
76
76
|
|
77
77
|
def _Content_to_mldev(
|
78
78
|
api_client: BaseApiClient,
|
79
|
-
from_object: Union[dict, object],
|
80
|
-
parent_object: Optional[dict] = None,
|
81
|
-
) -> dict:
|
79
|
+
from_object: Union[dict[str, Any], object],
|
80
|
+
parent_object: Optional[dict[str, Any]] = None,
|
81
|
+
) -> dict[str, Any]:
|
82
82
|
to_object: dict[str, Any] = {}
|
83
83
|
if getv(from_object, ['parts']) is not None:
|
84
84
|
setv(
|
@@ -98,9 +98,9 @@ def _Content_to_mldev(
|
|
98
98
|
|
99
99
|
def _Schema_to_mldev(
|
100
100
|
api_client: BaseApiClient,
|
101
|
-
from_object: Union[dict, object],
|
102
|
-
parent_object: Optional[dict] = None,
|
103
|
-
) -> dict:
|
101
|
+
from_object: Union[dict[str, Any], object],
|
102
|
+
parent_object: Optional[dict[str, Any]] = None,
|
103
|
+
) -> dict[str, Any]:
|
104
104
|
to_object: dict[str, Any] = {}
|
105
105
|
if getv(from_object, ['example']) is not None:
|
106
106
|
raise ValueError('example parameter is not supported in Gemini API.')
|
@@ -177,9 +177,9 @@ def _Schema_to_mldev(
|
|
177
177
|
|
178
178
|
def _FunctionDeclaration_to_mldev(
|
179
179
|
api_client: BaseApiClient,
|
180
|
-
from_object: Union[dict, object],
|
181
|
-
parent_object: Optional[dict] = None,
|
182
|
-
) -> dict:
|
180
|
+
from_object: Union[dict[str, Any], object],
|
181
|
+
parent_object: Optional[dict[str, Any]] = None,
|
182
|
+
) -> dict[str, Any]:
|
183
183
|
to_object: dict[str, Any] = {}
|
184
184
|
if getv(from_object, ['response']) is not None:
|
185
185
|
raise ValueError('response parameter is not supported in Gemini API.')
|
@@ -198,9 +198,9 @@ def _FunctionDeclaration_to_mldev(
|
|
198
198
|
|
199
199
|
def _GoogleSearch_to_mldev(
|
200
200
|
api_client: BaseApiClient,
|
201
|
-
from_object: Union[dict, object],
|
202
|
-
parent_object: Optional[dict] = None,
|
203
|
-
) -> dict:
|
201
|
+
from_object: Union[dict[str, Any], object],
|
202
|
+
parent_object: Optional[dict[str, Any]] = None,
|
203
|
+
) -> dict[str, Any]:
|
204
204
|
to_object: dict[str, Any] = {}
|
205
205
|
|
206
206
|
return to_object
|
@@ -208,9 +208,9 @@ def _GoogleSearch_to_mldev(
|
|
208
208
|
|
209
209
|
def _DynamicRetrievalConfig_to_mldev(
|
210
210
|
api_client: BaseApiClient,
|
211
|
-
from_object: Union[dict, object],
|
212
|
-
parent_object: Optional[dict] = None,
|
213
|
-
) -> dict:
|
211
|
+
from_object: Union[dict[str, Any], object],
|
212
|
+
parent_object: Optional[dict[str, Any]] = None,
|
213
|
+
) -> dict[str, Any]:
|
214
214
|
to_object: dict[str, Any] = {}
|
215
215
|
if getv(from_object, ['mode']) is not None:
|
216
216
|
setv(to_object, ['mode'], getv(from_object, ['mode']))
|
@@ -227,9 +227,9 @@ def _DynamicRetrievalConfig_to_mldev(
|
|
227
227
|
|
228
228
|
def _GoogleSearchRetrieval_to_mldev(
|
229
229
|
api_client: BaseApiClient,
|
230
|
-
from_object: Union[dict, object],
|
231
|
-
parent_object: Optional[dict] = None,
|
232
|
-
) -> dict:
|
230
|
+
from_object: Union[dict[str, Any], object],
|
231
|
+
parent_object: Optional[dict[str, Any]] = None,
|
232
|
+
) -> dict[str, Any]:
|
233
233
|
to_object: dict[str, Any] = {}
|
234
234
|
if getv(from_object, ['dynamic_retrieval_config']) is not None:
|
235
235
|
setv(
|
@@ -247,9 +247,9 @@ def _GoogleSearchRetrieval_to_mldev(
|
|
247
247
|
|
248
248
|
def _Tool_to_mldev(
|
249
249
|
api_client: BaseApiClient,
|
250
|
-
from_object: Union[dict, object],
|
251
|
-
parent_object: Optional[dict] = None,
|
252
|
-
) -> dict:
|
250
|
+
from_object: Union[dict[str, Any], object],
|
251
|
+
parent_object: Optional[dict[str, Any]] = None,
|
252
|
+
) -> dict[str, Any]:
|
253
253
|
to_object: dict[str, Any] = {}
|
254
254
|
if getv(from_object, ['function_declarations']) is not None:
|
255
255
|
setv(
|
@@ -292,9 +292,9 @@ def _Tool_to_mldev(
|
|
292
292
|
|
293
293
|
def _FunctionCallingConfig_to_mldev(
|
294
294
|
api_client: BaseApiClient,
|
295
|
-
from_object: Union[dict, object],
|
296
|
-
parent_object: Optional[dict] = None,
|
297
|
-
) -> dict:
|
295
|
+
from_object: Union[dict[str, Any], object],
|
296
|
+
parent_object: Optional[dict[str, Any]] = None,
|
297
|
+
) -> dict[str, Any]:
|
298
298
|
to_object: dict[str, Any] = {}
|
299
299
|
if getv(from_object, ['mode']) is not None:
|
300
300
|
setv(to_object, ['mode'], getv(from_object, ['mode']))
|
@@ -311,9 +311,9 @@ def _FunctionCallingConfig_to_mldev(
|
|
311
311
|
|
312
312
|
def _ToolConfig_to_mldev(
|
313
313
|
api_client: BaseApiClient,
|
314
|
-
from_object: Union[dict, object],
|
315
|
-
parent_object: Optional[dict] = None,
|
316
|
-
) -> dict:
|
314
|
+
from_object: Union[dict[str, Any], object],
|
315
|
+
parent_object: Optional[dict[str, Any]] = None,
|
316
|
+
) -> dict[str, Any]:
|
317
317
|
to_object: dict[str, Any] = {}
|
318
318
|
if getv(from_object, ['function_calling_config']) is not None:
|
319
319
|
setv(
|
@@ -331,9 +331,9 @@ def _ToolConfig_to_mldev(
|
|
331
331
|
|
332
332
|
def _CreateCachedContentConfig_to_mldev(
|
333
333
|
api_client: BaseApiClient,
|
334
|
-
from_object: Union[dict, object],
|
335
|
-
parent_object: Optional[dict] = None,
|
336
|
-
) -> dict:
|
334
|
+
from_object: Union[dict[str, Any], object],
|
335
|
+
parent_object: Optional[dict[str, Any]] = None,
|
336
|
+
) -> dict[str, Any]:
|
337
337
|
to_object: dict[str, Any] = {}
|
338
338
|
|
339
339
|
if getv(from_object, ['ttl']) is not None:
|
@@ -392,9 +392,9 @@ def _CreateCachedContentConfig_to_mldev(
|
|
392
392
|
|
393
393
|
def _CreateCachedContentParameters_to_mldev(
|
394
394
|
api_client: BaseApiClient,
|
395
|
-
from_object: Union[dict, object],
|
396
|
-
parent_object: Optional[dict] = None,
|
397
|
-
) -> dict:
|
395
|
+
from_object: Union[dict[str, Any], object],
|
396
|
+
parent_object: Optional[dict[str, Any]] = None,
|
397
|
+
) -> dict[str, Any]:
|
398
398
|
to_object: dict[str, Any] = {}
|
399
399
|
if getv(from_object, ['model']) is not None:
|
400
400
|
setv(
|
@@ -417,9 +417,9 @@ def _CreateCachedContentParameters_to_mldev(
|
|
417
417
|
|
418
418
|
def _GetCachedContentParameters_to_mldev(
|
419
419
|
api_client: BaseApiClient,
|
420
|
-
from_object: Union[dict, object],
|
421
|
-
parent_object: Optional[dict] = None,
|
422
|
-
) -> dict:
|
420
|
+
from_object: Union[dict[str, Any], object],
|
421
|
+
parent_object: Optional[dict[str, Any]] = None,
|
422
|
+
) -> dict[str, Any]:
|
423
423
|
to_object: dict[str, Any] = {}
|
424
424
|
if getv(from_object, ['name']) is not None:
|
425
425
|
setv(
|
@@ -436,9 +436,9 @@ def _GetCachedContentParameters_to_mldev(
|
|
436
436
|
|
437
437
|
def _DeleteCachedContentParameters_to_mldev(
|
438
438
|
api_client: BaseApiClient,
|
439
|
-
from_object: Union[dict, object],
|
440
|
-
parent_object: Optional[dict] = None,
|
441
|
-
) -> dict:
|
439
|
+
from_object: Union[dict[str, Any], object],
|
440
|
+
parent_object: Optional[dict[str, Any]] = None,
|
441
|
+
) -> dict[str, Any]:
|
442
442
|
to_object: dict[str, Any] = {}
|
443
443
|
if getv(from_object, ['name']) is not None:
|
444
444
|
setv(
|
@@ -455,9 +455,9 @@ def _DeleteCachedContentParameters_to_mldev(
|
|
455
455
|
|
456
456
|
def _UpdateCachedContentConfig_to_mldev(
|
457
457
|
api_client: BaseApiClient,
|
458
|
-
from_object: Union[dict, object],
|
459
|
-
parent_object: Optional[dict] = None,
|
460
|
-
) -> dict:
|
458
|
+
from_object: Union[dict[str, Any], object],
|
459
|
+
parent_object: Optional[dict[str, Any]] = None,
|
460
|
+
) -> dict[str, Any]:
|
461
461
|
to_object: dict[str, Any] = {}
|
462
462
|
|
463
463
|
if getv(from_object, ['ttl']) is not None:
|
@@ -471,9 +471,9 @@ def _UpdateCachedContentConfig_to_mldev(
|
|
471
471
|
|
472
472
|
def _UpdateCachedContentParameters_to_mldev(
|
473
473
|
api_client: BaseApiClient,
|
474
|
-
from_object: Union[dict, object],
|
475
|
-
parent_object: Optional[dict] = None,
|
476
|
-
) -> dict:
|
474
|
+
from_object: Union[dict[str, Any], object],
|
475
|
+
parent_object: Optional[dict[str, Any]] = None,
|
476
|
+
) -> dict[str, Any]:
|
477
477
|
to_object: dict[str, Any] = {}
|
478
478
|
if getv(from_object, ['name']) is not None:
|
479
479
|
setv(
|
@@ -496,9 +496,9 @@ def _UpdateCachedContentParameters_to_mldev(
|
|
496
496
|
|
497
497
|
def _ListCachedContentsConfig_to_mldev(
|
498
498
|
api_client: BaseApiClient,
|
499
|
-
from_object: Union[dict, object],
|
500
|
-
parent_object: Optional[dict] = None,
|
501
|
-
) -> dict:
|
499
|
+
from_object: Union[dict[str, Any], object],
|
500
|
+
parent_object: Optional[dict[str, Any]] = None,
|
501
|
+
) -> dict[str, Any]:
|
502
502
|
to_object: dict[str, Any] = {}
|
503
503
|
|
504
504
|
if getv(from_object, ['page_size']) is not None:
|
@@ -518,9 +518,9 @@ def _ListCachedContentsConfig_to_mldev(
|
|
518
518
|
|
519
519
|
def _ListCachedContentsParameters_to_mldev(
|
520
520
|
api_client: BaseApiClient,
|
521
|
-
from_object: Union[dict, object],
|
522
|
-
parent_object: Optional[dict] = None,
|
523
|
-
) -> dict:
|
521
|
+
from_object: Union[dict[str, Any], object],
|
522
|
+
parent_object: Optional[dict[str, Any]] = None,
|
523
|
+
) -> dict[str, Any]:
|
524
524
|
to_object: dict[str, Any] = {}
|
525
525
|
if getv(from_object, ['config']) is not None:
|
526
526
|
setv(
|
@@ -536,9 +536,9 @@ def _ListCachedContentsParameters_to_mldev(
|
|
536
536
|
|
537
537
|
def _Part_to_vertex(
|
538
538
|
api_client: BaseApiClient,
|
539
|
-
from_object: Union[dict, object],
|
540
|
-
parent_object: Optional[dict] = None,
|
541
|
-
) -> dict:
|
539
|
+
from_object: Union[dict[str, Any], object],
|
540
|
+
parent_object: Optional[dict[str, Any]] = None,
|
541
|
+
) -> dict[str, Any]:
|
542
542
|
to_object: dict[str, Any] = {}
|
543
543
|
if getv(from_object, ['video_metadata']) is not None:
|
544
544
|
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
|
@@ -580,9 +580,9 @@ def _Part_to_vertex(
|
|
580
580
|
|
581
581
|
def _Content_to_vertex(
|
582
582
|
api_client: BaseApiClient,
|
583
|
-
from_object: Union[dict, object],
|
584
|
-
parent_object: Optional[dict] = None,
|
585
|
-
) -> dict:
|
583
|
+
from_object: Union[dict[str, Any], object],
|
584
|
+
parent_object: Optional[dict[str, Any]] = None,
|
585
|
+
) -> dict[str, Any]:
|
586
586
|
to_object: dict[str, Any] = {}
|
587
587
|
if getv(from_object, ['parts']) is not None:
|
588
588
|
setv(
|
@@ -602,9 +602,9 @@ def _Content_to_vertex(
|
|
602
602
|
|
603
603
|
def _Schema_to_vertex(
|
604
604
|
api_client: BaseApiClient,
|
605
|
-
from_object: Union[dict, object],
|
606
|
-
parent_object: Optional[dict] = None,
|
607
|
-
) -> dict:
|
605
|
+
from_object: Union[dict[str, Any], object],
|
606
|
+
parent_object: Optional[dict[str, Any]] = None,
|
607
|
+
) -> dict[str, Any]:
|
608
608
|
to_object: dict[str, Any] = {}
|
609
609
|
if getv(from_object, ['example']) is not None:
|
610
610
|
setv(to_object, ['example'], getv(from_object, ['example']))
|
@@ -681,9 +681,9 @@ def _Schema_to_vertex(
|
|
681
681
|
|
682
682
|
def _FunctionDeclaration_to_vertex(
|
683
683
|
api_client: BaseApiClient,
|
684
|
-
from_object: Union[dict, object],
|
685
|
-
parent_object: Optional[dict] = None,
|
686
|
-
) -> dict:
|
684
|
+
from_object: Union[dict[str, Any], object],
|
685
|
+
parent_object: Optional[dict[str, Any]] = None,
|
686
|
+
) -> dict[str, Any]:
|
687
687
|
to_object: dict[str, Any] = {}
|
688
688
|
if getv(from_object, ['response']) is not None:
|
689
689
|
setv(
|
@@ -708,9 +708,9 @@ def _FunctionDeclaration_to_vertex(
|
|
708
708
|
|
709
709
|
def _GoogleSearch_to_vertex(
|
710
710
|
api_client: BaseApiClient,
|
711
|
-
from_object: Union[dict, object],
|
712
|
-
parent_object: Optional[dict] = None,
|
713
|
-
) -> dict:
|
711
|
+
from_object: Union[dict[str, Any], object],
|
712
|
+
parent_object: Optional[dict[str, Any]] = None,
|
713
|
+
) -> dict[str, Any]:
|
714
714
|
to_object: dict[str, Any] = {}
|
715
715
|
|
716
716
|
return to_object
|
@@ -718,9 +718,9 @@ def _GoogleSearch_to_vertex(
|
|
718
718
|
|
719
719
|
def _DynamicRetrievalConfig_to_vertex(
|
720
720
|
api_client: BaseApiClient,
|
721
|
-
from_object: Union[dict, object],
|
722
|
-
parent_object: Optional[dict] = None,
|
723
|
-
) -> dict:
|
721
|
+
from_object: Union[dict[str, Any], object],
|
722
|
+
parent_object: Optional[dict[str, Any]] = None,
|
723
|
+
) -> dict[str, Any]:
|
724
724
|
to_object: dict[str, Any] = {}
|
725
725
|
if getv(from_object, ['mode']) is not None:
|
726
726
|
setv(to_object, ['mode'], getv(from_object, ['mode']))
|
@@ -737,9 +737,9 @@ def _DynamicRetrievalConfig_to_vertex(
|
|
737
737
|
|
738
738
|
def _GoogleSearchRetrieval_to_vertex(
|
739
739
|
api_client: BaseApiClient,
|
740
|
-
from_object: Union[dict, object],
|
741
|
-
parent_object: Optional[dict] = None,
|
742
|
-
) -> dict:
|
740
|
+
from_object: Union[dict[str, Any], object],
|
741
|
+
parent_object: Optional[dict[str, Any]] = None,
|
742
|
+
) -> dict[str, Any]:
|
743
743
|
to_object: dict[str, Any] = {}
|
744
744
|
if getv(from_object, ['dynamic_retrieval_config']) is not None:
|
745
745
|
setv(
|
@@ -757,9 +757,9 @@ def _GoogleSearchRetrieval_to_vertex(
|
|
757
757
|
|
758
758
|
def _Tool_to_vertex(
|
759
759
|
api_client: BaseApiClient,
|
760
|
-
from_object: Union[dict, object],
|
761
|
-
parent_object: Optional[dict] = None,
|
762
|
-
) -> dict:
|
760
|
+
from_object: Union[dict[str, Any], object],
|
761
|
+
parent_object: Optional[dict[str, Any]] = None,
|
762
|
+
) -> dict[str, Any]:
|
763
763
|
to_object: dict[str, Any] = {}
|
764
764
|
if getv(from_object, ['function_declarations']) is not None:
|
765
765
|
setv(
|
@@ -802,9 +802,9 @@ def _Tool_to_vertex(
|
|
802
802
|
|
803
803
|
def _FunctionCallingConfig_to_vertex(
|
804
804
|
api_client: BaseApiClient,
|
805
|
-
from_object: Union[dict, object],
|
806
|
-
parent_object: Optional[dict] = None,
|
807
|
-
) -> dict:
|
805
|
+
from_object: Union[dict[str, Any], object],
|
806
|
+
parent_object: Optional[dict[str, Any]] = None,
|
807
|
+
) -> dict[str, Any]:
|
808
808
|
to_object: dict[str, Any] = {}
|
809
809
|
if getv(from_object, ['mode']) is not None:
|
810
810
|
setv(to_object, ['mode'], getv(from_object, ['mode']))
|
@@ -821,9 +821,9 @@ def _FunctionCallingConfig_to_vertex(
|
|
821
821
|
|
822
822
|
def _ToolConfig_to_vertex(
|
823
823
|
api_client: BaseApiClient,
|
824
|
-
from_object: Union[dict, object],
|
825
|
-
parent_object: Optional[dict] = None,
|
826
|
-
) -> dict:
|
824
|
+
from_object: Union[dict[str, Any], object],
|
825
|
+
parent_object: Optional[dict[str, Any]] = None,
|
826
|
+
) -> dict[str, Any]:
|
827
827
|
to_object: dict[str, Any] = {}
|
828
828
|
if getv(from_object, ['function_calling_config']) is not None:
|
829
829
|
setv(
|
@@ -841,9 +841,9 @@ def _ToolConfig_to_vertex(
|
|
841
841
|
|
842
842
|
def _CreateCachedContentConfig_to_vertex(
|
843
843
|
api_client: BaseApiClient,
|
844
|
-
from_object: Union[dict, object],
|
845
|
-
parent_object: Optional[dict] = None,
|
846
|
-
) -> dict:
|
844
|
+
from_object: Union[dict[str, Any], object],
|
845
|
+
parent_object: Optional[dict[str, Any]] = None,
|
846
|
+
) -> dict[str, Any]:
|
847
847
|
to_object: dict[str, Any] = {}
|
848
848
|
|
849
849
|
if getv(from_object, ['ttl']) is not None:
|
@@ -902,9 +902,9 @@ def _CreateCachedContentConfig_to_vertex(
|
|
902
902
|
|
903
903
|
def _CreateCachedContentParameters_to_vertex(
|
904
904
|
api_client: BaseApiClient,
|
905
|
-
from_object: Union[dict, object],
|
906
|
-
parent_object: Optional[dict] = None,
|
907
|
-
) -> dict:
|
905
|
+
from_object: Union[dict[str, Any], object],
|
906
|
+
parent_object: Optional[dict[str, Any]] = None,
|
907
|
+
) -> dict[str, Any]:
|
908
908
|
to_object: dict[str, Any] = {}
|
909
909
|
if getv(from_object, ['model']) is not None:
|
910
910
|
setv(
|
@@ -927,9 +927,9 @@ def _CreateCachedContentParameters_to_vertex(
|
|
927
927
|
|
928
928
|
def _GetCachedContentParameters_to_vertex(
|
929
929
|
api_client: BaseApiClient,
|
930
|
-
from_object: Union[dict, object],
|
931
|
-
parent_object: Optional[dict] = None,
|
932
|
-
) -> dict:
|
930
|
+
from_object: Union[dict[str, Any], object],
|
931
|
+
parent_object: Optional[dict[str, Any]] = None,
|
932
|
+
) -> dict[str, Any]:
|
933
933
|
to_object: dict[str, Any] = {}
|
934
934
|
if getv(from_object, ['name']) is not None:
|
935
935
|
setv(
|
@@ -946,9 +946,9 @@ def _GetCachedContentParameters_to_vertex(
|
|
946
946
|
|
947
947
|
def _DeleteCachedContentParameters_to_vertex(
|
948
948
|
api_client: BaseApiClient,
|
949
|
-
from_object: Union[dict, object],
|
950
|
-
parent_object: Optional[dict] = None,
|
951
|
-
) -> dict:
|
949
|
+
from_object: Union[dict[str, Any], object],
|
950
|
+
parent_object: Optional[dict[str, Any]] = None,
|
951
|
+
) -> dict[str, Any]:
|
952
952
|
to_object: dict[str, Any] = {}
|
953
953
|
if getv(from_object, ['name']) is not None:
|
954
954
|
setv(
|
@@ -965,9 +965,9 @@ def _DeleteCachedContentParameters_to_vertex(
|
|
965
965
|
|
966
966
|
def _UpdateCachedContentConfig_to_vertex(
|
967
967
|
api_client: BaseApiClient,
|
968
|
-
from_object: Union[dict, object],
|
969
|
-
parent_object: Optional[dict] = None,
|
970
|
-
) -> dict:
|
968
|
+
from_object: Union[dict[str, Any], object],
|
969
|
+
parent_object: Optional[dict[str, Any]] = None,
|
970
|
+
) -> dict[str, Any]:
|
971
971
|
to_object: dict[str, Any] = {}
|
972
972
|
|
973
973
|
if getv(from_object, ['ttl']) is not None:
|
@@ -981,9 +981,9 @@ def _UpdateCachedContentConfig_to_vertex(
|
|
981
981
|
|
982
982
|
def _UpdateCachedContentParameters_to_vertex(
|
983
983
|
api_client: BaseApiClient,
|
984
|
-
from_object: Union[dict, object],
|
985
|
-
parent_object: Optional[dict] = None,
|
986
|
-
) -> dict:
|
984
|
+
from_object: Union[dict[str, Any], object],
|
985
|
+
parent_object: Optional[dict[str, Any]] = None,
|
986
|
+
) -> dict[str, Any]:
|
987
987
|
to_object: dict[str, Any] = {}
|
988
988
|
if getv(from_object, ['name']) is not None:
|
989
989
|
setv(
|
@@ -1006,9 +1006,9 @@ def _UpdateCachedContentParameters_to_vertex(
|
|
1006
1006
|
|
1007
1007
|
def _ListCachedContentsConfig_to_vertex(
|
1008
1008
|
api_client: BaseApiClient,
|
1009
|
-
from_object: Union[dict, object],
|
1010
|
-
parent_object: Optional[dict] = None,
|
1011
|
-
) -> dict:
|
1009
|
+
from_object: Union[dict[str, Any], object],
|
1010
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1011
|
+
) -> dict[str, Any]:
|
1012
1012
|
to_object: dict[str, Any] = {}
|
1013
1013
|
|
1014
1014
|
if getv(from_object, ['page_size']) is not None:
|
@@ -1028,9 +1028,9 @@ def _ListCachedContentsConfig_to_vertex(
|
|
1028
1028
|
|
1029
1029
|
def _ListCachedContentsParameters_to_vertex(
|
1030
1030
|
api_client: BaseApiClient,
|
1031
|
-
from_object: Union[dict, object],
|
1032
|
-
parent_object: Optional[dict] = None,
|
1033
|
-
) -> dict:
|
1031
|
+
from_object: Union[dict[str, Any], object],
|
1032
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1033
|
+
) -> dict[str, Any]:
|
1034
1034
|
to_object: dict[str, Any] = {}
|
1035
1035
|
if getv(from_object, ['config']) is not None:
|
1036
1036
|
setv(
|
@@ -1046,9 +1046,9 @@ def _ListCachedContentsParameters_to_vertex(
|
|
1046
1046
|
|
1047
1047
|
def _CachedContent_from_mldev(
|
1048
1048
|
api_client: BaseApiClient,
|
1049
|
-
from_object: Union[dict, object],
|
1050
|
-
parent_object: Optional[dict] = None,
|
1051
|
-
) -> dict:
|
1049
|
+
from_object: Union[dict[str, Any], object],
|
1050
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1051
|
+
) -> dict[str, Any]:
|
1052
1052
|
to_object: dict[str, Any] = {}
|
1053
1053
|
if getv(from_object, ['name']) is not None:
|
1054
1054
|
setv(to_object, ['name'], getv(from_object, ['name']))
|
@@ -1076,9 +1076,9 @@ def _CachedContent_from_mldev(
|
|
1076
1076
|
|
1077
1077
|
def _DeleteCachedContentResponse_from_mldev(
|
1078
1078
|
api_client: BaseApiClient,
|
1079
|
-
from_object: Union[dict, object],
|
1080
|
-
parent_object: Optional[dict] = None,
|
1081
|
-
) -> dict:
|
1079
|
+
from_object: Union[dict[str, Any], object],
|
1080
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1081
|
+
) -> dict[str, Any]:
|
1082
1082
|
to_object: dict[str, Any] = {}
|
1083
1083
|
|
1084
1084
|
return to_object
|
@@ -1086,9 +1086,9 @@ def _DeleteCachedContentResponse_from_mldev(
|
|
1086
1086
|
|
1087
1087
|
def _ListCachedContentsResponse_from_mldev(
|
1088
1088
|
api_client: BaseApiClient,
|
1089
|
-
from_object: Union[dict, object],
|
1090
|
-
parent_object: Optional[dict] = None,
|
1091
|
-
) -> dict:
|
1089
|
+
from_object: Union[dict[str, Any], object],
|
1090
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1091
|
+
) -> dict[str, Any]:
|
1092
1092
|
to_object: dict[str, Any] = {}
|
1093
1093
|
if getv(from_object, ['nextPageToken']) is not None:
|
1094
1094
|
setv(to_object, ['next_page_token'], getv(from_object, ['nextPageToken']))
|
@@ -1108,9 +1108,9 @@ def _ListCachedContentsResponse_from_mldev(
|
|
1108
1108
|
|
1109
1109
|
def _CachedContent_from_vertex(
|
1110
1110
|
api_client: BaseApiClient,
|
1111
|
-
from_object: Union[dict, object],
|
1112
|
-
parent_object: Optional[dict] = None,
|
1113
|
-
) -> dict:
|
1111
|
+
from_object: Union[dict[str, Any], object],
|
1112
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1113
|
+
) -> dict[str, Any]:
|
1114
1114
|
to_object: dict[str, Any] = {}
|
1115
1115
|
if getv(from_object, ['name']) is not None:
|
1116
1116
|
setv(to_object, ['name'], getv(from_object, ['name']))
|
@@ -1138,9 +1138,9 @@ def _CachedContent_from_vertex(
|
|
1138
1138
|
|
1139
1139
|
def _DeleteCachedContentResponse_from_vertex(
|
1140
1140
|
api_client: BaseApiClient,
|
1141
|
-
from_object: Union[dict, object],
|
1142
|
-
parent_object: Optional[dict] = None,
|
1143
|
-
) -> dict:
|
1141
|
+
from_object: Union[dict[str, Any], object],
|
1142
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1143
|
+
) -> dict[str, Any]:
|
1144
1144
|
to_object: dict[str, Any] = {}
|
1145
1145
|
|
1146
1146
|
return to_object
|
@@ -1148,9 +1148,9 @@ def _DeleteCachedContentResponse_from_vertex(
|
|
1148
1148
|
|
1149
1149
|
def _ListCachedContentsResponse_from_vertex(
|
1150
1150
|
api_client: BaseApiClient,
|
1151
|
-
from_object: Union[dict, object],
|
1152
|
-
parent_object: Optional[dict] = None,
|
1153
|
-
) -> dict:
|
1151
|
+
from_object: Union[dict[str, Any], object],
|
1152
|
+
parent_object: Optional[dict[str, Any]] = None,
|
1153
|
+
) -> dict[str, Any]:
|
1154
1154
|
to_object: dict[str, Any] = {}
|
1155
1155
|
if getv(from_object, ['nextPageToken']) is not None:
|
1156
1156
|
setv(to_object, ['next_page_token'], getv(from_object, ['nextPageToken']))
|
google/genai/chats.py
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
#
|
15
15
|
|
16
|
+
from collections.abc import Iterator
|
16
17
|
import sys
|
17
18
|
from typing import AsyncIterator, Awaitable, Optional, Union, get_args
|
18
19
|
|
@@ -140,7 +141,7 @@ class _BaseChat:
|
|
140
141
|
model_output: list[Content],
|
141
142
|
automatic_function_calling_history: list[Content],
|
142
143
|
is_valid: bool,
|
143
|
-
):
|
144
|
+
) -> None:
|
144
145
|
"""Records the chat history.
|
145
146
|
|
146
147
|
Maintaining both comprehensive and curated histories.
|
@@ -282,7 +283,7 @@ class Chat(_BaseChat):
|
|
282
283
|
self,
|
283
284
|
message: Union[list[PartUnionDict], PartUnionDict],
|
284
285
|
config: Optional[GenerateContentConfigOrDict] = None,
|
285
|
-
):
|
286
|
+
) -> Iterator[GenerateContentResponse]:
|
286
287
|
"""Sends the conversation history with the additional message and yields the model's response in chunks.
|
287
288
|
|
288
289
|
Args:
|
@@ -444,7 +445,7 @@ class AsyncChat(_BaseChat):
|
|
444
445
|
self,
|
445
446
|
message: Union[list[PartUnionDict], PartUnionDict],
|
446
447
|
config: Optional[GenerateContentConfigOrDict] = None,
|
447
|
-
) ->
|
448
|
+
) -> AsyncIterator[GenerateContentResponse]:
|
448
449
|
"""Sends the conversation history with the additional message and yields the model's response in chunks.
|
449
450
|
|
450
451
|
Args:
|
@@ -470,14 +471,14 @@ class AsyncChat(_BaseChat):
|
|
470
471
|
)
|
471
472
|
input_content = t.t_content(self._modules._api_client, message)
|
472
473
|
|
473
|
-
async def async_generator():
|
474
|
+
async def async_generator(): # type: ignore[no-untyped-def]
|
474
475
|
output_contents = []
|
475
476
|
finish_reason = None
|
476
477
|
is_valid = True
|
477
478
|
chunk = None
|
478
|
-
async for chunk in await self._modules.generate_content_stream(
|
479
|
+
async for chunk in await self._modules.generate_content_stream( # type: ignore[attr-defined]
|
479
480
|
model=self._model,
|
480
|
-
contents=self._curated_history + [input_content],
|
481
|
+
contents=self._curated_history + [input_content], # type: ignore[arg-type]
|
481
482
|
config=config if config else self._config,
|
482
483
|
):
|
483
484
|
if not _validate_response(chunk):
|
@@ -488,13 +489,16 @@ class AsyncChat(_BaseChat):
|
|
488
489
|
finish_reason = chunk.candidates[0].finish_reason
|
489
490
|
yield chunk
|
490
491
|
|
492
|
+
if not output_contents or finish_reason is None:
|
493
|
+
is_valid = False
|
494
|
+
|
491
495
|
self.record_history(
|
492
496
|
user_input=input_content,
|
493
497
|
model_output=output_contents,
|
494
|
-
automatic_function_calling_history=chunk.automatic_function_calling_history,
|
495
|
-
is_valid=is_valid
|
498
|
+
automatic_function_calling_history=chunk.automatic_function_calling_history if chunk.automatic_function_calling_history else [],
|
499
|
+
is_valid=is_valid,
|
496
500
|
)
|
497
|
-
return async_generator()
|
501
|
+
return async_generator() # type: ignore[no-untyped-call, no-any-return]
|
498
502
|
|
499
503
|
|
500
504
|
class AsyncChats:
|
google/genai/client.py
CHANGED
@@ -19,7 +19,7 @@ from typing import Optional, Union
|
|
19
19
|
import google.auth
|
20
20
|
import pydantic
|
21
21
|
|
22
|
-
from ._api_client import BaseApiClient
|
22
|
+
from ._api_client import BaseApiClient
|
23
23
|
from ._replay_api_client import ReplayApiClient
|
24
24
|
from .batches import AsyncBatches, Batches
|
25
25
|
from .caches import AsyncCaches, Caches
|
@@ -29,6 +29,7 @@ from .live import AsyncLive
|
|
29
29
|
from .models import AsyncModels, Models
|
30
30
|
from .operations import AsyncOperations, Operations
|
31
31
|
from .tunings import AsyncTunings, Tunings
|
32
|
+
from .types import HttpOptions, HttpOptionsDict
|
32
33
|
|
33
34
|
|
34
35
|
class AsyncClient:
|
@@ -224,7 +225,7 @@ class Client:
|
|
224
225
|
location: Optional[str] = None,
|
225
226
|
debug_config: Optional[DebugConfig] = None,
|
226
227
|
http_options: Optional[HttpOptions] = None,
|
227
|
-
):
|
228
|
+
) -> BaseApiClient:
|
228
229
|
if debug_config and debug_config.client_mode in [
|
229
230
|
'record',
|
230
231
|
'replay',
|
google/genai/errors.py
CHANGED
@@ -46,22 +46,22 @@ class APIError(Exception):
|
|
46
46
|
|
47
47
|
super().__init__(f'{self.code} {self.status}. {self.details}')
|
48
48
|
|
49
|
-
def _get_status(self, response_json):
|
49
|
+
def _get_status(self, response_json: Any) -> Any:
|
50
50
|
return response_json.get(
|
51
51
|
'status', response_json.get('error', {}).get('status', None)
|
52
52
|
)
|
53
53
|
|
54
|
-
def _get_message(self, response_json):
|
54
|
+
def _get_message(self, response_json: Any) -> Any:
|
55
55
|
return response_json.get(
|
56
56
|
'message', response_json.get('error', {}).get('message', None)
|
57
57
|
)
|
58
58
|
|
59
|
-
def _get_code(self, response_json):
|
59
|
+
def _get_code(self, response_json: Any) -> Any:
|
60
60
|
return response_json.get(
|
61
61
|
'code', response_json.get('error', {}).get('code', None)
|
62
62
|
)
|
63
63
|
|
64
|
-
def _to_replay_record(self):
|
64
|
+
def _to_replay_record(self) -> dict[str, Any]:
|
65
65
|
"""Returns a dictionary representation of the error for replay recording.
|
66
66
|
|
67
67
|
details is not included since it may expose internal information in the
|
@@ -78,7 +78,7 @@ class APIError(Exception):
|
|
78
78
|
@classmethod
|
79
79
|
def raise_for_response(
|
80
80
|
cls, response: Union['ReplayResponse', httpx.Response]
|
81
|
-
):
|
81
|
+
) -> None:
|
82
82
|
"""Raises an error with detailed error message if the response has an error status."""
|
83
83
|
if response.status_code == 200:
|
84
84
|
return
|
@@ -107,7 +107,7 @@ class APIError(Exception):
|
|
107
107
|
@classmethod
|
108
108
|
async def raise_for_async_response(
|
109
109
|
cls, response: Union['ReplayResponse', httpx.Response]
|
110
|
-
):
|
110
|
+
) -> None:
|
111
111
|
"""Raises an error with detailed error message if the response has an error status."""
|
112
112
|
if response.status_code == 200:
|
113
113
|
return
|