google-genai 1.20.0__py3-none-any.whl → 1.21.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 +170 -103
- google/genai/_common.py +73 -0
- google/genai/_live_converters.py +174 -414
- google/genai/_replay_api_client.py +9 -3
- google/genai/_tokens_converters.py +81 -176
- google/genai/_transformers.py +19 -40
- google/genai/batches.py +46 -64
- google/genai/caches.py +131 -222
- google/genai/chats.py +4 -4
- google/genai/client.py +1 -1
- google/genai/files.py +88 -106
- google/genai/live.py +15 -20
- google/genai/live_music.py +4 -5
- google/genai/models.py +317 -560
- google/genai/operations.py +35 -68
- google/genai/tokens.py +11 -6
- google/genai/tunings.py +64 -113
- google/genai/types.py +132 -9
- google/genai/version.py +1 -1
- {google_genai-1.20.0.dist-info → google_genai-1.21.0.dist-info}/METADATA +45 -1
- google_genai-1.21.0.dist-info/RECORD +35 -0
- google_genai-1.20.0.dist-info/RECORD +0 -35
- {google_genai-1.20.0.dist-info → google_genai-1.21.0.dist-info}/WHEEL +0 -0
- {google_genai-1.20.0.dist-info → google_genai-1.21.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.20.0.dist-info → google_genai-1.21.0.dist-info}/top_level.txt +0 -0
google/genai/chats.py
CHANGED
@@ -250,7 +250,7 @@ class Chat(_BaseChat):
|
|
250
250
|
f"Message must be a valid part type: {types.PartUnion} or"
|
251
251
|
f" {types.PartUnionDict}, got {type(message)}"
|
252
252
|
)
|
253
|
-
input_content = t.t_content(
|
253
|
+
input_content = t.t_content(message)
|
254
254
|
response = self._modules.generate_content(
|
255
255
|
model=self._model,
|
256
256
|
contents=self._curated_history + [input_content], # type: ignore[arg-type]
|
@@ -303,7 +303,7 @@ class Chat(_BaseChat):
|
|
303
303
|
f"Message must be a valid part type: {types.PartUnion} or"
|
304
304
|
f" {types.PartUnionDict}, got {type(message)}"
|
305
305
|
)
|
306
|
-
input_content = t.t_content(
|
306
|
+
input_content = t.t_content(message)
|
307
307
|
output_contents = []
|
308
308
|
finish_reason = None
|
309
309
|
is_valid = True
|
@@ -412,7 +412,7 @@ class AsyncChat(_BaseChat):
|
|
412
412
|
f"Message must be a valid part type: {types.PartUnion} or"
|
413
413
|
f" {types.PartUnionDict}, got {type(message)}"
|
414
414
|
)
|
415
|
-
input_content = t.t_content(
|
415
|
+
input_content = t.t_content(message)
|
416
416
|
response = await self._modules.generate_content(
|
417
417
|
model=self._model,
|
418
418
|
contents=self._curated_history + [input_content], # type: ignore[arg-type]
|
@@ -464,7 +464,7 @@ class AsyncChat(_BaseChat):
|
|
464
464
|
f"Message must be a valid part type: {types.PartUnion} or"
|
465
465
|
f" {types.PartUnionDict}, got {type(message)}"
|
466
466
|
)
|
467
|
-
input_content = t.t_content(
|
467
|
+
input_content = t.t_content(message)
|
468
468
|
|
469
469
|
async def async_generator(): # type: ignore[no-untyped-def]
|
470
470
|
output_contents = []
|
google/genai/client.py
CHANGED
@@ -31,7 +31,7 @@ from .models import AsyncModels, Models
|
|
31
31
|
from .operations import AsyncOperations, Operations
|
32
32
|
from .tokens import AsyncTokens, Tokens
|
33
33
|
from .tunings import AsyncTunings, Tunings
|
34
|
-
from .types import HttpOptions, HttpOptionsDict
|
34
|
+
from .types import HttpOptions, HttpOptionsDict, HttpRetryOptions
|
35
35
|
|
36
36
|
|
37
37
|
class AsyncClient:
|
google/genai/files.py
CHANGED
@@ -16,10 +16,10 @@
|
|
16
16
|
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
17
17
|
|
18
18
|
import io
|
19
|
+
import json
|
19
20
|
import logging
|
20
21
|
import mimetypes
|
21
22
|
import os
|
22
|
-
import pathlib
|
23
23
|
from typing import Any, Optional, Union
|
24
24
|
from urllib.parse import urlencode
|
25
25
|
|
@@ -27,7 +27,6 @@ from . import _api_module
|
|
27
27
|
from . import _common
|
28
28
|
from . import _transformers as t
|
29
29
|
from . import types
|
30
|
-
from ._api_client import BaseApiClient
|
31
30
|
from ._common import get_value_by_path as getv
|
32
31
|
from ._common import set_value_by_path as setv
|
33
32
|
from .pagers import AsyncPager, Pager
|
@@ -36,7 +35,6 @@ logger = logging.getLogger('google_genai.files')
|
|
36
35
|
|
37
36
|
|
38
37
|
def _ListFilesConfig_to_mldev(
|
39
|
-
api_client: BaseApiClient,
|
40
38
|
from_object: Union[dict[str, Any], object],
|
41
39
|
parent_object: Optional[dict[str, Any]] = None,
|
42
40
|
) -> dict[str, Any]:
|
@@ -58,7 +56,6 @@ def _ListFilesConfig_to_mldev(
|
|
58
56
|
|
59
57
|
|
60
58
|
def _ListFilesParameters_to_mldev(
|
61
|
-
api_client: BaseApiClient,
|
62
59
|
from_object: Union[dict[str, Any], object],
|
63
60
|
parent_object: Optional[dict[str, Any]] = None,
|
64
61
|
) -> dict[str, Any]:
|
@@ -67,16 +64,13 @@ def _ListFilesParameters_to_mldev(
|
|
67
64
|
setv(
|
68
65
|
to_object,
|
69
66
|
['config'],
|
70
|
-
_ListFilesConfig_to_mldev(
|
71
|
-
api_client, getv(from_object, ['config']), to_object
|
72
|
-
),
|
67
|
+
_ListFilesConfig_to_mldev(getv(from_object, ['config']), to_object),
|
73
68
|
)
|
74
69
|
|
75
70
|
return to_object
|
76
71
|
|
77
72
|
|
78
73
|
def _FileStatus_to_mldev(
|
79
|
-
api_client: BaseApiClient,
|
80
74
|
from_object: Union[dict[str, Any], object],
|
81
75
|
parent_object: Optional[dict[str, Any]] = None,
|
82
76
|
) -> dict[str, Any]:
|
@@ -94,7 +88,6 @@ def _FileStatus_to_mldev(
|
|
94
88
|
|
95
89
|
|
96
90
|
def _File_to_mldev(
|
97
|
-
api_client: BaseApiClient,
|
98
91
|
from_object: Union[dict[str, Any], object],
|
99
92
|
parent_object: Optional[dict[str, Any]] = None,
|
100
93
|
) -> dict[str, Any]:
|
@@ -142,16 +135,13 @@ def _File_to_mldev(
|
|
142
135
|
setv(
|
143
136
|
to_object,
|
144
137
|
['error'],
|
145
|
-
_FileStatus_to_mldev(
|
146
|
-
api_client, getv(from_object, ['error']), to_object
|
147
|
-
),
|
138
|
+
_FileStatus_to_mldev(getv(from_object, ['error']), to_object),
|
148
139
|
)
|
149
140
|
|
150
141
|
return to_object
|
151
142
|
|
152
143
|
|
153
144
|
def _CreateFileParameters_to_mldev(
|
154
|
-
api_client: BaseApiClient,
|
155
145
|
from_object: Union[dict[str, Any], object],
|
156
146
|
parent_object: Optional[dict[str, Any]] = None,
|
157
147
|
) -> dict[str, Any]:
|
@@ -160,7 +150,7 @@ def _CreateFileParameters_to_mldev(
|
|
160
150
|
setv(
|
161
151
|
to_object,
|
162
152
|
['file'],
|
163
|
-
_File_to_mldev(
|
153
|
+
_File_to_mldev(getv(from_object, ['file']), to_object),
|
164
154
|
)
|
165
155
|
|
166
156
|
if getv(from_object, ['config']) is not None:
|
@@ -170,16 +160,13 @@ def _CreateFileParameters_to_mldev(
|
|
170
160
|
|
171
161
|
|
172
162
|
def _GetFileParameters_to_mldev(
|
173
|
-
api_client: BaseApiClient,
|
174
163
|
from_object: Union[dict[str, Any], object],
|
175
164
|
parent_object: Optional[dict[str, Any]] = None,
|
176
165
|
) -> dict[str, Any]:
|
177
166
|
to_object: dict[str, Any] = {}
|
178
167
|
if getv(from_object, ['name']) is not None:
|
179
168
|
setv(
|
180
|
-
to_object,
|
181
|
-
['_url', 'file'],
|
182
|
-
t.t_file_name(api_client, getv(from_object, ['name'])),
|
169
|
+
to_object, ['_url', 'file'], t.t_file_name(getv(from_object, ['name']))
|
183
170
|
)
|
184
171
|
|
185
172
|
if getv(from_object, ['config']) is not None:
|
@@ -189,16 +176,13 @@ def _GetFileParameters_to_mldev(
|
|
189
176
|
|
190
177
|
|
191
178
|
def _DeleteFileParameters_to_mldev(
|
192
|
-
api_client: BaseApiClient,
|
193
179
|
from_object: Union[dict[str, Any], object],
|
194
180
|
parent_object: Optional[dict[str, Any]] = None,
|
195
181
|
) -> dict[str, Any]:
|
196
182
|
to_object: dict[str, Any] = {}
|
197
183
|
if getv(from_object, ['name']) is not None:
|
198
184
|
setv(
|
199
|
-
to_object,
|
200
|
-
['_url', 'file'],
|
201
|
-
t.t_file_name(api_client, getv(from_object, ['name'])),
|
185
|
+
to_object, ['_url', 'file'], t.t_file_name(getv(from_object, ['name']))
|
202
186
|
)
|
203
187
|
|
204
188
|
if getv(from_object, ['config']) is not None:
|
@@ -208,7 +192,6 @@ def _DeleteFileParameters_to_mldev(
|
|
208
192
|
|
209
193
|
|
210
194
|
def _FileStatus_from_mldev(
|
211
|
-
api_client: BaseApiClient,
|
212
195
|
from_object: Union[dict[str, Any], object],
|
213
196
|
parent_object: Optional[dict[str, Any]] = None,
|
214
197
|
) -> dict[str, Any]:
|
@@ -226,7 +209,6 @@ def _FileStatus_from_mldev(
|
|
226
209
|
|
227
210
|
|
228
211
|
def _File_from_mldev(
|
229
|
-
api_client: BaseApiClient,
|
230
212
|
from_object: Union[dict[str, Any], object],
|
231
213
|
parent_object: Optional[dict[str, Any]] = None,
|
232
214
|
) -> dict[str, Any]:
|
@@ -274,16 +256,13 @@ def _File_from_mldev(
|
|
274
256
|
setv(
|
275
257
|
to_object,
|
276
258
|
['error'],
|
277
|
-
_FileStatus_from_mldev(
|
278
|
-
api_client, getv(from_object, ['error']), to_object
|
279
|
-
),
|
259
|
+
_FileStatus_from_mldev(getv(from_object, ['error']), to_object),
|
280
260
|
)
|
281
261
|
|
282
262
|
return to_object
|
283
263
|
|
284
264
|
|
285
265
|
def _ListFilesResponse_from_mldev(
|
286
|
-
api_client: BaseApiClient,
|
287
266
|
from_object: Union[dict[str, Any], object],
|
288
267
|
parent_object: Optional[dict[str, Any]] = None,
|
289
268
|
) -> dict[str, Any]:
|
@@ -296,7 +275,7 @@ def _ListFilesResponse_from_mldev(
|
|
296
275
|
to_object,
|
297
276
|
['files'],
|
298
277
|
[
|
299
|
-
_File_from_mldev(
|
278
|
+
_File_from_mldev(item, to_object)
|
300
279
|
for item in getv(from_object, ['files'])
|
301
280
|
],
|
302
281
|
)
|
@@ -305,19 +284,15 @@ def _ListFilesResponse_from_mldev(
|
|
305
284
|
|
306
285
|
|
307
286
|
def _CreateFileResponse_from_mldev(
|
308
|
-
api_client: BaseApiClient,
|
309
287
|
from_object: Union[dict[str, Any], object],
|
310
288
|
parent_object: Optional[dict[str, Any]] = None,
|
311
289
|
) -> dict[str, Any]:
|
312
290
|
to_object: dict[str, Any] = {}
|
313
|
-
if getv(from_object, ['httpHeaders']) is not None:
|
314
|
-
setv(to_object, ['http_headers'], getv(from_object, ['httpHeaders']))
|
315
291
|
|
316
292
|
return to_object
|
317
293
|
|
318
294
|
|
319
295
|
def _DeleteFileResponse_from_mldev(
|
320
|
-
api_client: BaseApiClient,
|
321
296
|
from_object: Union[dict[str, Any], object],
|
322
297
|
parent_object: Optional[dict[str, Any]] = None,
|
323
298
|
) -> dict[str, Any]:
|
@@ -358,9 +333,7 @@ class Files(_api_module.BaseModule):
|
|
358
333
|
'This method is only supported in the Gemini Developer client.'
|
359
334
|
)
|
360
335
|
else:
|
361
|
-
request_dict = _ListFilesParameters_to_mldev(
|
362
|
-
self._api_client, parameter_model
|
363
|
-
)
|
336
|
+
request_dict = _ListFilesParameters_to_mldev(parameter_model)
|
364
337
|
request_url_dict = request_dict.get('_url')
|
365
338
|
if request_url_dict:
|
366
339
|
path = 'files'.format_map(request_url_dict)
|
@@ -383,14 +356,12 @@ class Files(_api_module.BaseModule):
|
|
383
356
|
request_dict = _common.convert_to_dict(request_dict)
|
384
357
|
request_dict = _common.encode_unserializable_types(request_dict)
|
385
358
|
|
386
|
-
|
387
|
-
|
388
|
-
)
|
359
|
+
response = self._api_client.request('get', path, request_dict, http_options)
|
360
|
+
|
361
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
389
362
|
|
390
363
|
if not self._api_client.vertexai:
|
391
|
-
response_dict = _ListFilesResponse_from_mldev(
|
392
|
-
self._api_client, response_dict
|
393
|
-
)
|
364
|
+
response_dict = _ListFilesResponse_from_mldev(response_dict)
|
394
365
|
|
395
366
|
return_value = types.ListFilesResponse._from_response(
|
396
367
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -415,9 +386,7 @@ class Files(_api_module.BaseModule):
|
|
415
386
|
'This method is only supported in the Gemini Developer client.'
|
416
387
|
)
|
417
388
|
else:
|
418
|
-
request_dict = _CreateFileParameters_to_mldev(
|
419
|
-
self._api_client, parameter_model
|
420
|
-
)
|
389
|
+
request_dict = _CreateFileParameters_to_mldev(parameter_model)
|
421
390
|
request_url_dict = request_dict.get('_url')
|
422
391
|
if request_url_dict:
|
423
392
|
path = 'upload/v1beta/files'.format_map(request_url_dict)
|
@@ -440,14 +409,20 @@ class Files(_api_module.BaseModule):
|
|
440
409
|
request_dict = _common.convert_to_dict(request_dict)
|
441
410
|
request_dict = _common.encode_unserializable_types(request_dict)
|
442
411
|
|
443
|
-
|
412
|
+
response = self._api_client.request(
|
444
413
|
'post', path, request_dict, http_options
|
445
414
|
)
|
446
415
|
|
416
|
+
if config is not None and getattr(
|
417
|
+
config, 'should_return_http_response', None
|
418
|
+
):
|
419
|
+
return_value = types.CreateFileResponse(sdk_http_response=response)
|
420
|
+
return return_value
|
421
|
+
|
422
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
423
|
+
|
447
424
|
if not self._api_client.vertexai:
|
448
|
-
response_dict = _CreateFileResponse_from_mldev(
|
449
|
-
self._api_client, response_dict
|
450
|
-
)
|
425
|
+
response_dict = _CreateFileResponse_from_mldev(response_dict)
|
451
426
|
|
452
427
|
return_value = types.CreateFileResponse._from_response(
|
453
428
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -486,9 +461,7 @@ class Files(_api_module.BaseModule):
|
|
486
461
|
'This method is only supported in the Gemini Developer client.'
|
487
462
|
)
|
488
463
|
else:
|
489
|
-
request_dict = _GetFileParameters_to_mldev(
|
490
|
-
self._api_client, parameter_model
|
491
|
-
)
|
464
|
+
request_dict = _GetFileParameters_to_mldev(parameter_model)
|
492
465
|
request_url_dict = request_dict.get('_url')
|
493
466
|
if request_url_dict:
|
494
467
|
path = 'files/{file}'.format_map(request_url_dict)
|
@@ -511,12 +484,12 @@ class Files(_api_module.BaseModule):
|
|
511
484
|
request_dict = _common.convert_to_dict(request_dict)
|
512
485
|
request_dict = _common.encode_unserializable_types(request_dict)
|
513
486
|
|
514
|
-
|
515
|
-
|
516
|
-
)
|
487
|
+
response = self._api_client.request('get', path, request_dict, http_options)
|
488
|
+
|
489
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
517
490
|
|
518
491
|
if not self._api_client.vertexai:
|
519
|
-
response_dict = _File_from_mldev(
|
492
|
+
response_dict = _File_from_mldev(response_dict)
|
520
493
|
|
521
494
|
return_value = types.File._from_response(
|
522
495
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -554,9 +527,7 @@ class Files(_api_module.BaseModule):
|
|
554
527
|
'This method is only supported in the Gemini Developer client.'
|
555
528
|
)
|
556
529
|
else:
|
557
|
-
request_dict = _DeleteFileParameters_to_mldev(
|
558
|
-
self._api_client, parameter_model
|
559
|
-
)
|
530
|
+
request_dict = _DeleteFileParameters_to_mldev(parameter_model)
|
560
531
|
request_url_dict = request_dict.get('_url')
|
561
532
|
if request_url_dict:
|
562
533
|
path = 'files/{file}'.format_map(request_url_dict)
|
@@ -579,14 +550,14 @@ class Files(_api_module.BaseModule):
|
|
579
550
|
request_dict = _common.convert_to_dict(request_dict)
|
580
551
|
request_dict = _common.encode_unserializable_types(request_dict)
|
581
552
|
|
582
|
-
|
553
|
+
response = self._api_client.request(
|
583
554
|
'delete', path, request_dict, http_options
|
584
555
|
)
|
585
556
|
|
557
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
558
|
+
|
586
559
|
if not self._api_client.vertexai:
|
587
|
-
response_dict = _DeleteFileResponse_from_mldev(
|
588
|
-
self._api_client, response_dict
|
589
|
-
)
|
560
|
+
response_dict = _DeleteFileResponse_from_mldev(response_dict)
|
590
561
|
|
591
562
|
return_value = types.DeleteFileResponse._from_response(
|
592
563
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -597,7 +568,7 @@ class Files(_api_module.BaseModule):
|
|
597
568
|
def upload(
|
598
569
|
self,
|
599
570
|
*,
|
600
|
-
file: Union[str,
|
571
|
+
file: Union[str, os.PathLike[str], io.IOBase],
|
601
572
|
config: Optional[types.UploadFileConfigOrDict] = None,
|
602
573
|
) -> types.File:
|
603
574
|
"""Calls the API to upload a file using a supported file service.
|
@@ -679,18 +650,22 @@ class Files(_api_module.BaseModule):
|
|
679
650
|
},
|
680
651
|
)
|
681
652
|
response = self._create(
|
682
|
-
file=file_obj,
|
653
|
+
file=file_obj,
|
654
|
+
config=types.CreateFileConfig(
|
655
|
+
http_options=http_options, should_return_http_response=True
|
656
|
+
),
|
683
657
|
)
|
684
658
|
|
685
659
|
if (
|
686
|
-
response.
|
687
|
-
or
|
660
|
+
response.sdk_http_response is None
|
661
|
+
or response.sdk_http_response.headers is None
|
662
|
+
or 'x-goog-upload-url' not in response.sdk_http_response.headers
|
688
663
|
):
|
689
664
|
raise KeyError(
|
690
665
|
'Failed to create file. Upload URL did not returned from the create'
|
691
666
|
' file request.'
|
692
667
|
)
|
693
|
-
upload_url = response.
|
668
|
+
upload_url = response.sdk_http_response.headers['x-goog-upload-url']
|
694
669
|
|
695
670
|
if isinstance(file, io.IOBase):
|
696
671
|
return_file = self._api_client.upload_file(
|
@@ -702,7 +677,7 @@ class Files(_api_module.BaseModule):
|
|
702
677
|
)
|
703
678
|
|
704
679
|
return types.File._from_response(
|
705
|
-
response=_File_from_mldev(
|
680
|
+
response=_File_from_mldev(return_file.json['file']),
|
706
681
|
kwargs=config_model.model_dump() if config else {},
|
707
682
|
)
|
708
683
|
|
@@ -775,7 +750,7 @@ class Files(_api_module.BaseModule):
|
|
775
750
|
'downloaded. You can tell which files are downloadable by checking '
|
776
751
|
'the `source` or `download_uri` property.'
|
777
752
|
)
|
778
|
-
name = t.t_file_name(
|
753
|
+
name = t.t_file_name(file)
|
779
754
|
|
780
755
|
path = f'files/{name}:download'
|
781
756
|
|
@@ -830,9 +805,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
830
805
|
'This method is only supported in the Gemini Developer client.'
|
831
806
|
)
|
832
807
|
else:
|
833
|
-
request_dict = _ListFilesParameters_to_mldev(
|
834
|
-
self._api_client, parameter_model
|
835
|
-
)
|
808
|
+
request_dict = _ListFilesParameters_to_mldev(parameter_model)
|
836
809
|
request_url_dict = request_dict.get('_url')
|
837
810
|
if request_url_dict:
|
838
811
|
path = 'files'.format_map(request_url_dict)
|
@@ -855,14 +828,14 @@ class AsyncFiles(_api_module.BaseModule):
|
|
855
828
|
request_dict = _common.convert_to_dict(request_dict)
|
856
829
|
request_dict = _common.encode_unserializable_types(request_dict)
|
857
830
|
|
858
|
-
|
831
|
+
response = await self._api_client.async_request(
|
859
832
|
'get', path, request_dict, http_options
|
860
833
|
)
|
861
834
|
|
835
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
836
|
+
|
862
837
|
if not self._api_client.vertexai:
|
863
|
-
response_dict = _ListFilesResponse_from_mldev(
|
864
|
-
self._api_client, response_dict
|
865
|
-
)
|
838
|
+
response_dict = _ListFilesResponse_from_mldev(response_dict)
|
866
839
|
|
867
840
|
return_value = types.ListFilesResponse._from_response(
|
868
841
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -887,9 +860,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
887
860
|
'This method is only supported in the Gemini Developer client.'
|
888
861
|
)
|
889
862
|
else:
|
890
|
-
request_dict = _CreateFileParameters_to_mldev(
|
891
|
-
self._api_client, parameter_model
|
892
|
-
)
|
863
|
+
request_dict = _CreateFileParameters_to_mldev(parameter_model)
|
893
864
|
request_url_dict = request_dict.get('_url')
|
894
865
|
if request_url_dict:
|
895
866
|
path = 'upload/v1beta/files'.format_map(request_url_dict)
|
@@ -912,14 +883,20 @@ class AsyncFiles(_api_module.BaseModule):
|
|
912
883
|
request_dict = _common.convert_to_dict(request_dict)
|
913
884
|
request_dict = _common.encode_unserializable_types(request_dict)
|
914
885
|
|
915
|
-
|
886
|
+
response = await self._api_client.async_request(
|
916
887
|
'post', path, request_dict, http_options
|
917
888
|
)
|
918
889
|
|
890
|
+
if config is not None and getattr(
|
891
|
+
config, 'should_return_http_response', None
|
892
|
+
):
|
893
|
+
return_value = types.CreateFileResponse(sdk_http_response=response)
|
894
|
+
return return_value
|
895
|
+
|
896
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
897
|
+
|
919
898
|
if not self._api_client.vertexai:
|
920
|
-
response_dict = _CreateFileResponse_from_mldev(
|
921
|
-
self._api_client, response_dict
|
922
|
-
)
|
899
|
+
response_dict = _CreateFileResponse_from_mldev(response_dict)
|
923
900
|
|
924
901
|
return_value = types.CreateFileResponse._from_response(
|
925
902
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -958,9 +935,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
958
935
|
'This method is only supported in the Gemini Developer client.'
|
959
936
|
)
|
960
937
|
else:
|
961
|
-
request_dict = _GetFileParameters_to_mldev(
|
962
|
-
self._api_client, parameter_model
|
963
|
-
)
|
938
|
+
request_dict = _GetFileParameters_to_mldev(parameter_model)
|
964
939
|
request_url_dict = request_dict.get('_url')
|
965
940
|
if request_url_dict:
|
966
941
|
path = 'files/{file}'.format_map(request_url_dict)
|
@@ -983,12 +958,14 @@ class AsyncFiles(_api_module.BaseModule):
|
|
983
958
|
request_dict = _common.convert_to_dict(request_dict)
|
984
959
|
request_dict = _common.encode_unserializable_types(request_dict)
|
985
960
|
|
986
|
-
|
961
|
+
response = await self._api_client.async_request(
|
987
962
|
'get', path, request_dict, http_options
|
988
963
|
)
|
989
964
|
|
965
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
966
|
+
|
990
967
|
if not self._api_client.vertexai:
|
991
|
-
response_dict = _File_from_mldev(
|
968
|
+
response_dict = _File_from_mldev(response_dict)
|
992
969
|
|
993
970
|
return_value = types.File._from_response(
|
994
971
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -1026,9 +1003,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1026
1003
|
'This method is only supported in the Gemini Developer client.'
|
1027
1004
|
)
|
1028
1005
|
else:
|
1029
|
-
request_dict = _DeleteFileParameters_to_mldev(
|
1030
|
-
self._api_client, parameter_model
|
1031
|
-
)
|
1006
|
+
request_dict = _DeleteFileParameters_to_mldev(parameter_model)
|
1032
1007
|
request_url_dict = request_dict.get('_url')
|
1033
1008
|
if request_url_dict:
|
1034
1009
|
path = 'files/{file}'.format_map(request_url_dict)
|
@@ -1051,14 +1026,14 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1051
1026
|
request_dict = _common.convert_to_dict(request_dict)
|
1052
1027
|
request_dict = _common.encode_unserializable_types(request_dict)
|
1053
1028
|
|
1054
|
-
|
1029
|
+
response = await self._api_client.async_request(
|
1055
1030
|
'delete', path, request_dict, http_options
|
1056
1031
|
)
|
1057
1032
|
|
1033
|
+
response_dict = '' if not response.body else json.loads(response.body)
|
1034
|
+
|
1058
1035
|
if not self._api_client.vertexai:
|
1059
|
-
response_dict = _DeleteFileResponse_from_mldev(
|
1060
|
-
self._api_client, response_dict
|
1061
|
-
)
|
1036
|
+
response_dict = _DeleteFileResponse_from_mldev(response_dict)
|
1062
1037
|
|
1063
1038
|
return_value = types.DeleteFileResponse._from_response(
|
1064
1039
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -1069,7 +1044,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1069
1044
|
async def upload(
|
1070
1045
|
self,
|
1071
1046
|
*,
|
1072
|
-
file: Union[str,
|
1047
|
+
file: Union[str, os.PathLike[str], io.IOBase],
|
1073
1048
|
config: Optional[types.UploadFileConfigOrDict] = None,
|
1074
1049
|
) -> types.File:
|
1075
1050
|
"""Calls the API to upload a file asynchronously using a supported file service.
|
@@ -1151,20 +1126,27 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1151
1126
|
},
|
1152
1127
|
)
|
1153
1128
|
response = await self._create(
|
1154
|
-
file=file_obj,
|
1129
|
+
file=file_obj,
|
1130
|
+
config=types.CreateFileConfig(
|
1131
|
+
http_options=http_options, should_return_http_response=True
|
1132
|
+
),
|
1155
1133
|
)
|
1156
|
-
if
|
1157
|
-
|
1158
|
-
|
1134
|
+
if (
|
1135
|
+
response.sdk_http_response is None
|
1136
|
+
or response.sdk_http_response.headers is None
|
1137
|
+
or (
|
1138
|
+
'x-goog-upload-url' not in response.sdk_http_response.headers
|
1139
|
+
and 'X-Goog-Upload-URL' not in response.sdk_http_response.headers
|
1140
|
+
)
|
1159
1141
|
):
|
1160
1142
|
raise KeyError(
|
1161
1143
|
'Failed to create file. Upload URL did not returned from the create'
|
1162
1144
|
' file request.'
|
1163
1145
|
)
|
1164
|
-
elif 'x-goog-upload-url' in response.
|
1165
|
-
upload_url = response.
|
1146
|
+
elif 'x-goog-upload-url' in response.sdk_http_response.headers:
|
1147
|
+
upload_url = response.sdk_http_response.headers['x-goog-upload-url']
|
1166
1148
|
else:
|
1167
|
-
upload_url = response.
|
1149
|
+
upload_url = response.sdk_http_response.headers['X-Goog-Upload-URL']
|
1168
1150
|
|
1169
1151
|
if isinstance(file, io.IOBase):
|
1170
1152
|
return_file = await self._api_client.async_upload_file(
|
@@ -1176,7 +1158,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1176
1158
|
)
|
1177
1159
|
|
1178
1160
|
return types.File._from_response(
|
1179
|
-
response=_File_from_mldev(
|
1161
|
+
response=_File_from_mldev(return_file.json['file']),
|
1180
1162
|
kwargs=config_model.model_dump() if config else {},
|
1181
1163
|
)
|
1182
1164
|
|
@@ -1237,7 +1219,7 @@ class AsyncFiles(_api_module.BaseModule):
|
|
1237
1219
|
else:
|
1238
1220
|
config_model = config
|
1239
1221
|
|
1240
|
-
name = t.t_file_name(
|
1222
|
+
name = t.t_file_name(file)
|
1241
1223
|
|
1242
1224
|
path = f'files/{name}:download'
|
1243
1225
|
|
google/genai/live.py
CHANGED
@@ -79,6 +79,7 @@ _FUNCTION_RESPONSE_REQUIRES_ID = (
|
|
79
79
|
' response of a ToolCall.FunctionalCalls in Google AI.'
|
80
80
|
)
|
81
81
|
|
82
|
+
|
82
83
|
class AsyncSession:
|
83
84
|
"""[Preview] AsyncSession."""
|
84
85
|
|
@@ -215,11 +216,11 @@ class AsyncSession:
|
|
215
216
|
|
216
217
|
if self._api_client.vertexai:
|
217
218
|
client_content_dict = live_converters._LiveClientContent_to_vertex(
|
218
|
-
|
219
|
+
from_object=client_content
|
219
220
|
)
|
220
221
|
else:
|
221
222
|
client_content_dict = live_converters._LiveClientContent_to_mldev(
|
222
|
-
|
223
|
+
from_object=client_content
|
223
224
|
)
|
224
225
|
|
225
226
|
await self._ws.send(json.dumps({'client_content': client_content_dict}))
|
@@ -313,13 +314,13 @@ class AsyncSession:
|
|
313
314
|
if self._api_client.vertexai:
|
314
315
|
realtime_input_dict = (
|
315
316
|
live_converters._LiveSendRealtimeInputParameters_to_vertex(
|
316
|
-
|
317
|
+
from_object=realtime_input
|
317
318
|
)
|
318
319
|
)
|
319
320
|
else:
|
320
321
|
realtime_input_dict = (
|
321
322
|
live_converters._LiveSendRealtimeInputParameters_to_mldev(
|
322
|
-
|
323
|
+
from_object=realtime_input
|
323
324
|
)
|
324
325
|
)
|
325
326
|
realtime_input_dict = _common.convert_to_dict(realtime_input_dict)
|
@@ -399,11 +400,11 @@ class AsyncSession:
|
|
399
400
|
tool_response = t.t_tool_response(function_responses)
|
400
401
|
if self._api_client.vertexai:
|
401
402
|
tool_response_dict = live_converters._LiveClientToolResponse_to_vertex(
|
402
|
-
|
403
|
+
from_object=tool_response
|
403
404
|
)
|
404
405
|
else:
|
405
406
|
tool_response_dict = live_converters._LiveClientToolResponse_to_mldev(
|
406
|
-
|
407
|
+
from_object=tool_response
|
407
408
|
)
|
408
409
|
for response in tool_response_dict.get('functionResponses', []):
|
409
410
|
if response.get('id') is None:
|
@@ -527,13 +528,9 @@ class AsyncSession:
|
|
527
528
|
response = {}
|
528
529
|
|
529
530
|
if self._api_client.vertexai:
|
530
|
-
response_dict = live_converters._LiveServerMessage_from_vertex(
|
531
|
-
self._api_client, response
|
532
|
-
)
|
531
|
+
response_dict = live_converters._LiveServerMessage_from_vertex(response)
|
533
532
|
else:
|
534
|
-
response_dict = live_converters._LiveServerMessage_from_mldev(
|
535
|
-
self._api_client, response
|
536
|
-
)
|
533
|
+
response_dict = live_converters._LiveServerMessage_from_mldev(response)
|
537
534
|
|
538
535
|
return types.LiveServerMessage._from_response(
|
539
536
|
response=response_dict, kwargs=parameter_model.model_dump()
|
@@ -647,13 +644,13 @@ class AsyncSession:
|
|
647
644
|
content_input_parts.append(item)
|
648
645
|
if self._api_client.vertexai:
|
649
646
|
contents = [
|
650
|
-
_Content_to_vertex(
|
651
|
-
for item in t.t_contents(
|
647
|
+
_Content_to_vertex(item, to_object)
|
648
|
+
for item in t.t_contents(content_input_parts)
|
652
649
|
]
|
653
650
|
else:
|
654
651
|
contents = [
|
655
|
-
_Content_to_mldev(
|
656
|
-
for item in t.t_contents(
|
652
|
+
_Content_to_mldev(item, to_object)
|
653
|
+
for item in t.t_contents(content_input_parts)
|
657
654
|
]
|
658
655
|
|
659
656
|
content_dict_list: list[types.ContentDict] = []
|
@@ -1063,7 +1060,7 @@ async def _t_live_connect_config(
|
|
1063
1060
|
elif isinstance(config, dict):
|
1064
1061
|
if getv(config, ['system_instruction']) is not None:
|
1065
1062
|
converted_system_instruction = t.t_content(
|
1066
|
-
|
1063
|
+
getv(config, ['system_instruction'])
|
1067
1064
|
)
|
1068
1065
|
else:
|
1069
1066
|
converted_system_instruction = None
|
@@ -1073,9 +1070,7 @@ async def _t_live_connect_config(
|
|
1073
1070
|
if config.system_instruction is None:
|
1074
1071
|
system_instruction = None
|
1075
1072
|
else:
|
1076
|
-
system_instruction = t.t_content(
|
1077
|
-
api_client, getv(config, ['system_instruction'])
|
1078
|
-
)
|
1073
|
+
system_instruction = t.t_content(getv(config, ['system_instruction']))
|
1079
1074
|
parameter_model = config
|
1080
1075
|
parameter_model.system_instruction = system_instruction
|
1081
1076
|
|