google-genai 0.3.0__py3-none-any.whl → 0.5.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/__init__.py +2 -1
- google/genai/_api_client.py +161 -52
- google/genai/_automatic_function_calling_util.py +14 -14
- google/genai/_common.py +14 -29
- google/genai/_replay_api_client.py +13 -54
- google/genai/_transformers.py +38 -0
- google/genai/batches.py +80 -78
- google/genai/caches.py +112 -98
- google/genai/chats.py +7 -10
- google/genai/client.py +6 -3
- google/genai/files.py +91 -90
- google/genai/live.py +65 -34
- google/genai/models.py +374 -297
- google/genai/tunings.py +87 -85
- google/genai/types.py +167 -82
- google/genai/version.py +16 -0
- {google_genai-0.3.0.dist-info → google_genai-0.5.0.dist-info}/METADATA +57 -17
- google_genai-0.5.0.dist-info/RECORD +25 -0
- {google_genai-0.3.0.dist-info → google_genai-0.5.0.dist-info}/WHEEL +1 -1
- google_genai-0.3.0.dist-info/RECORD +0 -24
- {google_genai-0.3.0.dist-info → google_genai-0.5.0.dist-info}/LICENSE +0 -0
- {google_genai-0.3.0.dist-info → google_genai-0.5.0.dist-info}/top_level.txt +0 -0
google/genai/caches.py
CHANGED
@@ -13,6 +13,8 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
#
|
15
15
|
|
16
|
+
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
17
|
+
|
16
18
|
from typing import Optional, Union
|
17
19
|
from urllib.parse import urlencode
|
18
20
|
from . import _common
|
@@ -30,7 +32,7 @@ def _Part_to_mldev(
|
|
30
32
|
parent_object: dict = None,
|
31
33
|
) -> dict:
|
32
34
|
to_object = {}
|
33
|
-
if getv(from_object, ['video_metadata']):
|
35
|
+
if getv(from_object, ['video_metadata']) is not None:
|
34
36
|
raise ValueError('video_metadata parameter is not supported in Google AI.')
|
35
37
|
|
36
38
|
if getv(from_object, ['thought']) is not None:
|
@@ -162,51 +164,51 @@ def _Schema_to_mldev(
|
|
162
164
|
parent_object: dict = None,
|
163
165
|
) -> dict:
|
164
166
|
to_object = {}
|
165
|
-
if getv(from_object, ['min_items']):
|
167
|
+
if getv(from_object, ['min_items']) is not None:
|
166
168
|
raise ValueError('min_items parameter is not supported in Google AI.')
|
167
169
|
|
168
|
-
if getv(from_object, ['example']):
|
170
|
+
if getv(from_object, ['example']) is not None:
|
169
171
|
raise ValueError('example parameter is not supported in Google AI.')
|
170
172
|
|
171
|
-
if getv(from_object, ['property_ordering']):
|
173
|
+
if getv(from_object, ['property_ordering']) is not None:
|
172
174
|
raise ValueError(
|
173
175
|
'property_ordering parameter is not supported in Google AI.'
|
174
176
|
)
|
175
177
|
|
176
|
-
if getv(from_object, ['pattern']):
|
178
|
+
if getv(from_object, ['pattern']) is not None:
|
177
179
|
raise ValueError('pattern parameter is not supported in Google AI.')
|
178
180
|
|
179
|
-
if getv(from_object, ['minimum']):
|
181
|
+
if getv(from_object, ['minimum']) is not None:
|
180
182
|
raise ValueError('minimum parameter is not supported in Google AI.')
|
181
183
|
|
182
|
-
if getv(from_object, ['default']):
|
184
|
+
if getv(from_object, ['default']) is not None:
|
183
185
|
raise ValueError('default parameter is not supported in Google AI.')
|
184
186
|
|
185
|
-
if getv(from_object, ['any_of']):
|
187
|
+
if getv(from_object, ['any_of']) is not None:
|
186
188
|
raise ValueError('any_of parameter is not supported in Google AI.')
|
187
189
|
|
188
|
-
if getv(from_object, ['max_length']):
|
190
|
+
if getv(from_object, ['max_length']) is not None:
|
189
191
|
raise ValueError('max_length parameter is not supported in Google AI.')
|
190
192
|
|
191
|
-
if getv(from_object, ['title']):
|
193
|
+
if getv(from_object, ['title']) is not None:
|
192
194
|
raise ValueError('title parameter is not supported in Google AI.')
|
193
195
|
|
194
|
-
if getv(from_object, ['min_length']):
|
196
|
+
if getv(from_object, ['min_length']) is not None:
|
195
197
|
raise ValueError('min_length parameter is not supported in Google AI.')
|
196
198
|
|
197
|
-
if getv(from_object, ['min_properties']):
|
199
|
+
if getv(from_object, ['min_properties']) is not None:
|
198
200
|
raise ValueError('min_properties parameter is not supported in Google AI.')
|
199
201
|
|
200
|
-
if getv(from_object, ['max_items']):
|
202
|
+
if getv(from_object, ['max_items']) is not None:
|
201
203
|
raise ValueError('max_items parameter is not supported in Google AI.')
|
202
204
|
|
203
|
-
if getv(from_object, ['maximum']):
|
205
|
+
if getv(from_object, ['maximum']) is not None:
|
204
206
|
raise ValueError('maximum parameter is not supported in Google AI.')
|
205
207
|
|
206
|
-
if getv(from_object, ['nullable']):
|
208
|
+
if getv(from_object, ['nullable']) is not None:
|
207
209
|
raise ValueError('nullable parameter is not supported in Google AI.')
|
208
210
|
|
209
|
-
if getv(from_object, ['max_properties']):
|
211
|
+
if getv(from_object, ['max_properties']) is not None:
|
210
212
|
raise ValueError('max_properties parameter is not supported in Google AI.')
|
211
213
|
|
212
214
|
if getv(from_object, ['type']) is not None:
|
@@ -318,7 +320,7 @@ def _FunctionDeclaration_to_mldev(
|
|
318
320
|
parent_object: dict = None,
|
319
321
|
) -> dict:
|
320
322
|
to_object = {}
|
321
|
-
if getv(from_object, ['response']):
|
323
|
+
if getv(from_object, ['response']) is not None:
|
322
324
|
raise ValueError('response parameter is not supported in Google AI.')
|
323
325
|
|
324
326
|
if getv(from_object, ['description']) is not None:
|
@@ -474,7 +476,7 @@ def _Tool_to_mldev(
|
|
474
476
|
],
|
475
477
|
)
|
476
478
|
|
477
|
-
if getv(from_object, ['retrieval']):
|
479
|
+
if getv(from_object, ['retrieval']) is not None:
|
478
480
|
raise ValueError('retrieval parameter is not supported in Google AI.')
|
479
481
|
|
480
482
|
if getv(from_object, ['google_search']) is not None:
|
@@ -1272,14 +1274,14 @@ class Caches(_common.BaseModule):
|
|
1272
1274
|
config=config,
|
1273
1275
|
)
|
1274
1276
|
|
1275
|
-
if self.
|
1277
|
+
if self._api_client.vertexai:
|
1276
1278
|
request_dict = _CreateCachedContentParameters_to_vertex(
|
1277
|
-
self.
|
1279
|
+
self._api_client, parameter_model
|
1278
1280
|
)
|
1279
1281
|
path = 'cachedContents'.format_map(request_dict.get('_url'))
|
1280
1282
|
else:
|
1281
1283
|
request_dict = _CreateCachedContentParameters_to_mldev(
|
1282
|
-
self.
|
1284
|
+
self._api_client, parameter_model
|
1283
1285
|
)
|
1284
1286
|
path = 'cachedContents'.format_map(request_dict.get('_url'))
|
1285
1287
|
query_params = request_dict.get('_query')
|
@@ -1291,19 +1293,21 @@ class Caches(_common.BaseModule):
|
|
1291
1293
|
request_dict = _common.convert_to_dict(request_dict)
|
1292
1294
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1293
1295
|
|
1294
|
-
response_dict = self.
|
1296
|
+
response_dict = self._api_client.request(
|
1295
1297
|
'post', path, request_dict, http_options
|
1296
1298
|
)
|
1297
1299
|
|
1298
|
-
if self.
|
1299
|
-
response_dict = _CachedContent_from_vertex(
|
1300
|
+
if self._api_client.vertexai:
|
1301
|
+
response_dict = _CachedContent_from_vertex(
|
1302
|
+
self._api_client, response_dict
|
1303
|
+
)
|
1300
1304
|
else:
|
1301
|
-
response_dict = _CachedContent_from_mldev(self.
|
1305
|
+
response_dict = _CachedContent_from_mldev(self._api_client, response_dict)
|
1302
1306
|
|
1303
1307
|
return_value = types.CachedContent._from_response(
|
1304
1308
|
response_dict, parameter_model
|
1305
1309
|
)
|
1306
|
-
self.
|
1310
|
+
self._api_client._verify_response(return_value)
|
1307
1311
|
return return_value
|
1308
1312
|
|
1309
1313
|
def get(
|
@@ -1325,14 +1329,14 @@ class Caches(_common.BaseModule):
|
|
1325
1329
|
config=config,
|
1326
1330
|
)
|
1327
1331
|
|
1328
|
-
if self.
|
1332
|
+
if self._api_client.vertexai:
|
1329
1333
|
request_dict = _GetCachedContentParameters_to_vertex(
|
1330
|
-
self.
|
1334
|
+
self._api_client, parameter_model
|
1331
1335
|
)
|
1332
1336
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1333
1337
|
else:
|
1334
1338
|
request_dict = _GetCachedContentParameters_to_mldev(
|
1335
|
-
self.
|
1339
|
+
self._api_client, parameter_model
|
1336
1340
|
)
|
1337
1341
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1338
1342
|
query_params = request_dict.get('_query')
|
@@ -1344,19 +1348,21 @@ class Caches(_common.BaseModule):
|
|
1344
1348
|
request_dict = _common.convert_to_dict(request_dict)
|
1345
1349
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1346
1350
|
|
1347
|
-
response_dict = self.
|
1351
|
+
response_dict = self._api_client.request(
|
1348
1352
|
'get', path, request_dict, http_options
|
1349
1353
|
)
|
1350
1354
|
|
1351
|
-
if self.
|
1352
|
-
response_dict = _CachedContent_from_vertex(
|
1355
|
+
if self._api_client.vertexai:
|
1356
|
+
response_dict = _CachedContent_from_vertex(
|
1357
|
+
self._api_client, response_dict
|
1358
|
+
)
|
1353
1359
|
else:
|
1354
|
-
response_dict = _CachedContent_from_mldev(self.
|
1360
|
+
response_dict = _CachedContent_from_mldev(self._api_client, response_dict)
|
1355
1361
|
|
1356
1362
|
return_value = types.CachedContent._from_response(
|
1357
1363
|
response_dict, parameter_model
|
1358
1364
|
)
|
1359
|
-
self.
|
1365
|
+
self._api_client._verify_response(return_value)
|
1360
1366
|
return return_value
|
1361
1367
|
|
1362
1368
|
def delete(
|
@@ -1380,14 +1386,14 @@ class Caches(_common.BaseModule):
|
|
1380
1386
|
config=config,
|
1381
1387
|
)
|
1382
1388
|
|
1383
|
-
if self.
|
1389
|
+
if self._api_client.vertexai:
|
1384
1390
|
request_dict = _DeleteCachedContentParameters_to_vertex(
|
1385
|
-
self.
|
1391
|
+
self._api_client, parameter_model
|
1386
1392
|
)
|
1387
1393
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1388
1394
|
else:
|
1389
1395
|
request_dict = _DeleteCachedContentParameters_to_mldev(
|
1390
|
-
self.
|
1396
|
+
self._api_client, parameter_model
|
1391
1397
|
)
|
1392
1398
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1393
1399
|
query_params = request_dict.get('_query')
|
@@ -1399,23 +1405,23 @@ class Caches(_common.BaseModule):
|
|
1399
1405
|
request_dict = _common.convert_to_dict(request_dict)
|
1400
1406
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1401
1407
|
|
1402
|
-
response_dict = self.
|
1408
|
+
response_dict = self._api_client.request(
|
1403
1409
|
'delete', path, request_dict, http_options
|
1404
1410
|
)
|
1405
1411
|
|
1406
|
-
if self.
|
1412
|
+
if self._api_client.vertexai:
|
1407
1413
|
response_dict = _DeleteCachedContentResponse_from_vertex(
|
1408
|
-
self.
|
1414
|
+
self._api_client, response_dict
|
1409
1415
|
)
|
1410
1416
|
else:
|
1411
1417
|
response_dict = _DeleteCachedContentResponse_from_mldev(
|
1412
|
-
self.
|
1418
|
+
self._api_client, response_dict
|
1413
1419
|
)
|
1414
1420
|
|
1415
1421
|
return_value = types.DeleteCachedContentResponse._from_response(
|
1416
1422
|
response_dict, parameter_model
|
1417
1423
|
)
|
1418
|
-
self.
|
1424
|
+
self._api_client._verify_response(return_value)
|
1419
1425
|
return return_value
|
1420
1426
|
|
1421
1427
|
def update(
|
@@ -1441,14 +1447,14 @@ class Caches(_common.BaseModule):
|
|
1441
1447
|
config=config,
|
1442
1448
|
)
|
1443
1449
|
|
1444
|
-
if self.
|
1450
|
+
if self._api_client.vertexai:
|
1445
1451
|
request_dict = _UpdateCachedContentParameters_to_vertex(
|
1446
|
-
self.
|
1452
|
+
self._api_client, parameter_model
|
1447
1453
|
)
|
1448
1454
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1449
1455
|
else:
|
1450
1456
|
request_dict = _UpdateCachedContentParameters_to_mldev(
|
1451
|
-
self.
|
1457
|
+
self._api_client, parameter_model
|
1452
1458
|
)
|
1453
1459
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1454
1460
|
query_params = request_dict.get('_query')
|
@@ -1460,19 +1466,21 @@ class Caches(_common.BaseModule):
|
|
1460
1466
|
request_dict = _common.convert_to_dict(request_dict)
|
1461
1467
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1462
1468
|
|
1463
|
-
response_dict = self.
|
1469
|
+
response_dict = self._api_client.request(
|
1464
1470
|
'patch', path, request_dict, http_options
|
1465
1471
|
)
|
1466
1472
|
|
1467
|
-
if self.
|
1468
|
-
response_dict = _CachedContent_from_vertex(
|
1473
|
+
if self._api_client.vertexai:
|
1474
|
+
response_dict = _CachedContent_from_vertex(
|
1475
|
+
self._api_client, response_dict
|
1476
|
+
)
|
1469
1477
|
else:
|
1470
|
-
response_dict = _CachedContent_from_mldev(self.
|
1478
|
+
response_dict = _CachedContent_from_mldev(self._api_client, response_dict)
|
1471
1479
|
|
1472
1480
|
return_value = types.CachedContent._from_response(
|
1473
1481
|
response_dict, parameter_model
|
1474
1482
|
)
|
1475
|
-
self.
|
1483
|
+
self._api_client._verify_response(return_value)
|
1476
1484
|
return return_value
|
1477
1485
|
|
1478
1486
|
def _list(
|
@@ -1491,14 +1499,14 @@ class Caches(_common.BaseModule):
|
|
1491
1499
|
config=config,
|
1492
1500
|
)
|
1493
1501
|
|
1494
|
-
if self.
|
1502
|
+
if self._api_client.vertexai:
|
1495
1503
|
request_dict = _ListCachedContentsParameters_to_vertex(
|
1496
|
-
self.
|
1504
|
+
self._api_client, parameter_model
|
1497
1505
|
)
|
1498
1506
|
path = 'cachedContents'.format_map(request_dict.get('_url'))
|
1499
1507
|
else:
|
1500
1508
|
request_dict = _ListCachedContentsParameters_to_mldev(
|
1501
|
-
self.
|
1509
|
+
self._api_client, parameter_model
|
1502
1510
|
)
|
1503
1511
|
path = 'cachedContents'.format_map(request_dict.get('_url'))
|
1504
1512
|
query_params = request_dict.get('_query')
|
@@ -1510,23 +1518,23 @@ class Caches(_common.BaseModule):
|
|
1510
1518
|
request_dict = _common.convert_to_dict(request_dict)
|
1511
1519
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1512
1520
|
|
1513
|
-
response_dict = self.
|
1521
|
+
response_dict = self._api_client.request(
|
1514
1522
|
'get', path, request_dict, http_options
|
1515
1523
|
)
|
1516
1524
|
|
1517
|
-
if self.
|
1525
|
+
if self._api_client.vertexai:
|
1518
1526
|
response_dict = _ListCachedContentsResponse_from_vertex(
|
1519
|
-
self.
|
1527
|
+
self._api_client, response_dict
|
1520
1528
|
)
|
1521
1529
|
else:
|
1522
1530
|
response_dict = _ListCachedContentsResponse_from_mldev(
|
1523
|
-
self.
|
1531
|
+
self._api_client, response_dict
|
1524
1532
|
)
|
1525
1533
|
|
1526
1534
|
return_value = types.ListCachedContentsResponse._from_response(
|
1527
1535
|
response_dict, parameter_model
|
1528
1536
|
)
|
1529
|
-
self.
|
1537
|
+
self._api_client._verify_response(return_value)
|
1530
1538
|
return return_value
|
1531
1539
|
|
1532
1540
|
def list(
|
@@ -1574,14 +1582,14 @@ class AsyncCaches(_common.BaseModule):
|
|
1574
1582
|
config=config,
|
1575
1583
|
)
|
1576
1584
|
|
1577
|
-
if self.
|
1585
|
+
if self._api_client.vertexai:
|
1578
1586
|
request_dict = _CreateCachedContentParameters_to_vertex(
|
1579
|
-
self.
|
1587
|
+
self._api_client, parameter_model
|
1580
1588
|
)
|
1581
1589
|
path = 'cachedContents'.format_map(request_dict.get('_url'))
|
1582
1590
|
else:
|
1583
1591
|
request_dict = _CreateCachedContentParameters_to_mldev(
|
1584
|
-
self.
|
1592
|
+
self._api_client, parameter_model
|
1585
1593
|
)
|
1586
1594
|
path = 'cachedContents'.format_map(request_dict.get('_url'))
|
1587
1595
|
query_params = request_dict.get('_query')
|
@@ -1593,19 +1601,21 @@ class AsyncCaches(_common.BaseModule):
|
|
1593
1601
|
request_dict = _common.convert_to_dict(request_dict)
|
1594
1602
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1595
1603
|
|
1596
|
-
response_dict = await self.
|
1604
|
+
response_dict = await self._api_client.async_request(
|
1597
1605
|
'post', path, request_dict, http_options
|
1598
1606
|
)
|
1599
1607
|
|
1600
|
-
if self.
|
1601
|
-
response_dict = _CachedContent_from_vertex(
|
1608
|
+
if self._api_client.vertexai:
|
1609
|
+
response_dict = _CachedContent_from_vertex(
|
1610
|
+
self._api_client, response_dict
|
1611
|
+
)
|
1602
1612
|
else:
|
1603
|
-
response_dict = _CachedContent_from_mldev(self.
|
1613
|
+
response_dict = _CachedContent_from_mldev(self._api_client, response_dict)
|
1604
1614
|
|
1605
1615
|
return_value = types.CachedContent._from_response(
|
1606
1616
|
response_dict, parameter_model
|
1607
1617
|
)
|
1608
|
-
self.
|
1618
|
+
self._api_client._verify_response(return_value)
|
1609
1619
|
return return_value
|
1610
1620
|
|
1611
1621
|
async def get(
|
@@ -1627,14 +1637,14 @@ class AsyncCaches(_common.BaseModule):
|
|
1627
1637
|
config=config,
|
1628
1638
|
)
|
1629
1639
|
|
1630
|
-
if self.
|
1640
|
+
if self._api_client.vertexai:
|
1631
1641
|
request_dict = _GetCachedContentParameters_to_vertex(
|
1632
|
-
self.
|
1642
|
+
self._api_client, parameter_model
|
1633
1643
|
)
|
1634
1644
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1635
1645
|
else:
|
1636
1646
|
request_dict = _GetCachedContentParameters_to_mldev(
|
1637
|
-
self.
|
1647
|
+
self._api_client, parameter_model
|
1638
1648
|
)
|
1639
1649
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1640
1650
|
query_params = request_dict.get('_query')
|
@@ -1646,19 +1656,21 @@ class AsyncCaches(_common.BaseModule):
|
|
1646
1656
|
request_dict = _common.convert_to_dict(request_dict)
|
1647
1657
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1648
1658
|
|
1649
|
-
response_dict = await self.
|
1659
|
+
response_dict = await self._api_client.async_request(
|
1650
1660
|
'get', path, request_dict, http_options
|
1651
1661
|
)
|
1652
1662
|
|
1653
|
-
if self.
|
1654
|
-
response_dict = _CachedContent_from_vertex(
|
1663
|
+
if self._api_client.vertexai:
|
1664
|
+
response_dict = _CachedContent_from_vertex(
|
1665
|
+
self._api_client, response_dict
|
1666
|
+
)
|
1655
1667
|
else:
|
1656
|
-
response_dict = _CachedContent_from_mldev(self.
|
1668
|
+
response_dict = _CachedContent_from_mldev(self._api_client, response_dict)
|
1657
1669
|
|
1658
1670
|
return_value = types.CachedContent._from_response(
|
1659
1671
|
response_dict, parameter_model
|
1660
1672
|
)
|
1661
|
-
self.
|
1673
|
+
self._api_client._verify_response(return_value)
|
1662
1674
|
return return_value
|
1663
1675
|
|
1664
1676
|
async def delete(
|
@@ -1682,14 +1694,14 @@ class AsyncCaches(_common.BaseModule):
|
|
1682
1694
|
config=config,
|
1683
1695
|
)
|
1684
1696
|
|
1685
|
-
if self.
|
1697
|
+
if self._api_client.vertexai:
|
1686
1698
|
request_dict = _DeleteCachedContentParameters_to_vertex(
|
1687
|
-
self.
|
1699
|
+
self._api_client, parameter_model
|
1688
1700
|
)
|
1689
1701
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1690
1702
|
else:
|
1691
1703
|
request_dict = _DeleteCachedContentParameters_to_mldev(
|
1692
|
-
self.
|
1704
|
+
self._api_client, parameter_model
|
1693
1705
|
)
|
1694
1706
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1695
1707
|
query_params = request_dict.get('_query')
|
@@ -1701,23 +1713,23 @@ class AsyncCaches(_common.BaseModule):
|
|
1701
1713
|
request_dict = _common.convert_to_dict(request_dict)
|
1702
1714
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1703
1715
|
|
1704
|
-
response_dict = await self.
|
1716
|
+
response_dict = await self._api_client.async_request(
|
1705
1717
|
'delete', path, request_dict, http_options
|
1706
1718
|
)
|
1707
1719
|
|
1708
|
-
if self.
|
1720
|
+
if self._api_client.vertexai:
|
1709
1721
|
response_dict = _DeleteCachedContentResponse_from_vertex(
|
1710
|
-
self.
|
1722
|
+
self._api_client, response_dict
|
1711
1723
|
)
|
1712
1724
|
else:
|
1713
1725
|
response_dict = _DeleteCachedContentResponse_from_mldev(
|
1714
|
-
self.
|
1726
|
+
self._api_client, response_dict
|
1715
1727
|
)
|
1716
1728
|
|
1717
1729
|
return_value = types.DeleteCachedContentResponse._from_response(
|
1718
1730
|
response_dict, parameter_model
|
1719
1731
|
)
|
1720
|
-
self.
|
1732
|
+
self._api_client._verify_response(return_value)
|
1721
1733
|
return return_value
|
1722
1734
|
|
1723
1735
|
async def update(
|
@@ -1743,14 +1755,14 @@ class AsyncCaches(_common.BaseModule):
|
|
1743
1755
|
config=config,
|
1744
1756
|
)
|
1745
1757
|
|
1746
|
-
if self.
|
1758
|
+
if self._api_client.vertexai:
|
1747
1759
|
request_dict = _UpdateCachedContentParameters_to_vertex(
|
1748
|
-
self.
|
1760
|
+
self._api_client, parameter_model
|
1749
1761
|
)
|
1750
1762
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1751
1763
|
else:
|
1752
1764
|
request_dict = _UpdateCachedContentParameters_to_mldev(
|
1753
|
-
self.
|
1765
|
+
self._api_client, parameter_model
|
1754
1766
|
)
|
1755
1767
|
path = '{name}'.format_map(request_dict.get('_url'))
|
1756
1768
|
query_params = request_dict.get('_query')
|
@@ -1762,19 +1774,21 @@ class AsyncCaches(_common.BaseModule):
|
|
1762
1774
|
request_dict = _common.convert_to_dict(request_dict)
|
1763
1775
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1764
1776
|
|
1765
|
-
response_dict = await self.
|
1777
|
+
response_dict = await self._api_client.async_request(
|
1766
1778
|
'patch', path, request_dict, http_options
|
1767
1779
|
)
|
1768
1780
|
|
1769
|
-
if self.
|
1770
|
-
response_dict = _CachedContent_from_vertex(
|
1781
|
+
if self._api_client.vertexai:
|
1782
|
+
response_dict = _CachedContent_from_vertex(
|
1783
|
+
self._api_client, response_dict
|
1784
|
+
)
|
1771
1785
|
else:
|
1772
|
-
response_dict = _CachedContent_from_mldev(self.
|
1786
|
+
response_dict = _CachedContent_from_mldev(self._api_client, response_dict)
|
1773
1787
|
|
1774
1788
|
return_value = types.CachedContent._from_response(
|
1775
1789
|
response_dict, parameter_model
|
1776
1790
|
)
|
1777
|
-
self.
|
1791
|
+
self._api_client._verify_response(return_value)
|
1778
1792
|
return return_value
|
1779
1793
|
|
1780
1794
|
async def _list(
|
@@ -1793,14 +1807,14 @@ class AsyncCaches(_common.BaseModule):
|
|
1793
1807
|
config=config,
|
1794
1808
|
)
|
1795
1809
|
|
1796
|
-
if self.
|
1810
|
+
if self._api_client.vertexai:
|
1797
1811
|
request_dict = _ListCachedContentsParameters_to_vertex(
|
1798
|
-
self.
|
1812
|
+
self._api_client, parameter_model
|
1799
1813
|
)
|
1800
1814
|
path = 'cachedContents'.format_map(request_dict.get('_url'))
|
1801
1815
|
else:
|
1802
1816
|
request_dict = _ListCachedContentsParameters_to_mldev(
|
1803
|
-
self.
|
1817
|
+
self._api_client, parameter_model
|
1804
1818
|
)
|
1805
1819
|
path = 'cachedContents'.format_map(request_dict.get('_url'))
|
1806
1820
|
query_params = request_dict.get('_query')
|
@@ -1812,23 +1826,23 @@ class AsyncCaches(_common.BaseModule):
|
|
1812
1826
|
request_dict = _common.convert_to_dict(request_dict)
|
1813
1827
|
request_dict = _common.apply_base64_encoding(request_dict)
|
1814
1828
|
|
1815
|
-
response_dict = await self.
|
1829
|
+
response_dict = await self._api_client.async_request(
|
1816
1830
|
'get', path, request_dict, http_options
|
1817
1831
|
)
|
1818
1832
|
|
1819
|
-
if self.
|
1833
|
+
if self._api_client.vertexai:
|
1820
1834
|
response_dict = _ListCachedContentsResponse_from_vertex(
|
1821
|
-
self.
|
1835
|
+
self._api_client, response_dict
|
1822
1836
|
)
|
1823
1837
|
else:
|
1824
1838
|
response_dict = _ListCachedContentsResponse_from_mldev(
|
1825
|
-
self.
|
1839
|
+
self._api_client, response_dict
|
1826
1840
|
)
|
1827
1841
|
|
1828
1842
|
return_value = types.ListCachedContentsResponse._from_response(
|
1829
1843
|
response_dict, parameter_model
|
1830
1844
|
)
|
1831
|
-
self.
|
1845
|
+
self._api_client._verify_response(return_value)
|
1832
1846
|
return return_value
|
1833
1847
|
|
1834
1848
|
async def list(
|
google/genai/chats.py
CHANGED
@@ -21,9 +21,7 @@ from .models import AsyncModels, Models
|
|
21
21
|
from .types import Content, ContentDict, GenerateContentConfigOrDict, GenerateContentResponse, Part, PartUnionDict
|
22
22
|
|
23
23
|
|
24
|
-
def _validate_response(
|
25
|
-
response: GenerateContentResponse
|
26
|
-
) -> bool:
|
24
|
+
def _validate_response(response: GenerateContentResponse) -> bool:
|
27
25
|
if not response.candidates:
|
28
26
|
return False
|
29
27
|
if not response.candidates[0].content:
|
@@ -77,7 +75,7 @@ class Chat(_BaseChat):
|
|
77
75
|
response = chat.send_message('tell me a story')
|
78
76
|
"""
|
79
77
|
|
80
|
-
input_content = t.t_content(self._modules.
|
78
|
+
input_content = t.t_content(self._modules._api_client, message)
|
81
79
|
response = self._modules.generate_content(
|
82
80
|
model=self._model,
|
83
81
|
contents=self._curated_history + [input_content],
|
@@ -109,11 +107,11 @@ class Chat(_BaseChat):
|
|
109
107
|
.. code-block:: python
|
110
108
|
|
111
109
|
chat = client.chats.create(model='gemini-1.5-flash')
|
112
|
-
for chunk in chat.send_message_stream('tell me a story')
|
110
|
+
for chunk in chat.send_message_stream('tell me a story'):
|
113
111
|
print(chunk.text)
|
114
112
|
"""
|
115
113
|
|
116
|
-
input_content = t.t_content(self._modules.
|
114
|
+
input_content = t.t_content(self._modules._api_client, message)
|
117
115
|
output_contents = []
|
118
116
|
finish_reason = None
|
119
117
|
for chunk in self._modules.generate_content_stream(
|
@@ -184,7 +182,7 @@ class AsyncChat(_BaseChat):
|
|
184
182
|
response = await chat.send_message('tell me a story')
|
185
183
|
"""
|
186
184
|
|
187
|
-
input_content = t.t_content(self._modules.
|
185
|
+
input_content = t.t_content(self._modules._api_client, message)
|
188
186
|
response = await self._modules.generate_content(
|
189
187
|
model=self._model,
|
190
188
|
contents=self._curated_history + [input_content],
|
@@ -215,11 +213,11 @@ class AsyncChat(_BaseChat):
|
|
215
213
|
|
216
214
|
.. code-block:: python
|
217
215
|
chat = client.aio.chats.create(model='gemini-1.5-flash')
|
218
|
-
async for chunk in chat.send_message_stream('tell me a story')
|
216
|
+
async for chunk in chat.send_message_stream('tell me a story'):
|
219
217
|
print(chunk.text)
|
220
218
|
"""
|
221
219
|
|
222
|
-
input_content = t.t_content(self._modules.
|
220
|
+
input_content = t.t_content(self._modules._api_client, message)
|
223
221
|
output_contents = []
|
224
222
|
finish_reason = None
|
225
223
|
async for chunk in self._modules.generate_content_stream(
|
@@ -240,7 +238,6 @@ class AsyncChat(_BaseChat):
|
|
240
238
|
class AsyncChats:
|
241
239
|
"""A util class to create async chat sessions."""
|
242
240
|
|
243
|
-
|
244
241
|
def __init__(self, modules: AsyncModels):
|
245
242
|
self._modules = modules
|
246
243
|
|
google/genai/client.py
CHANGED
@@ -14,12 +14,12 @@
|
|
14
14
|
#
|
15
15
|
|
16
16
|
import os
|
17
|
-
from typing import Optional
|
17
|
+
from typing import Optional, Union
|
18
18
|
|
19
19
|
import google.auth
|
20
20
|
import pydantic
|
21
21
|
|
22
|
-
from ._api_client import ApiClient, HttpOptions
|
22
|
+
from ._api_client import ApiClient, HttpOptions, HttpOptionsDict
|
23
23
|
from ._replay_api_client import ReplayApiClient
|
24
24
|
from .batches import AsyncBatches, Batches
|
25
25
|
from .caches import AsyncCaches, Caches
|
@@ -145,7 +145,7 @@ class Client:
|
|
145
145
|
project: Optional[str] = None,
|
146
146
|
location: Optional[str] = None,
|
147
147
|
debug_config: Optional[DebugConfig] = None,
|
148
|
-
http_options: Optional[HttpOptions] = None,
|
148
|
+
http_options: Optional[Union[HttpOptions, HttpOptionsDict]] = None,
|
149
149
|
):
|
150
150
|
"""Initializes the client.
|
151
151
|
|
@@ -179,6 +179,9 @@ class Client:
|
|
179
179
|
debug_config (DebugConfig):
|
180
180
|
Config settings that control network
|
181
181
|
behavior of the client. This is typically used when running test code.
|
182
|
+
http_options (Union[HttpOptions, HttpOptionsDict]):
|
183
|
+
Http options to use for the client. Response_payload can't be
|
184
|
+
set when passing to the client constructor.
|
182
185
|
"""
|
183
186
|
|
184
187
|
self._debug_config = debug_config or DebugConfig()
|