google-genai 1.38.0__tar.gz → 1.39.1__tar.gz
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-1.38.0/google_genai.egg-info → google_genai-1.39.1}/PKG-INFO +82 -1
- {google_genai-1.38.0 → google_genai-1.39.1}/README.md +81 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_api_client.py +29 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_common.py +25 -10
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_live_converters.py +2074 -1924
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_operations_converters.py +108 -117
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_replay_api_client.py +8 -4
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_tokens_converters.py +465 -458
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_transformers.py +44 -26
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/batches.py +1101 -1138
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/caches.py +747 -771
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/client.py +87 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/files.py +110 -123
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/local_tokenizer.py +7 -2
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/models.py +2716 -2814
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/operations.py +10 -22
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/tunings.py +358 -391
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/types.py +192 -4
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/version.py +1 -1
- {google_genai-1.38.0 → google_genai-1.39.1/google_genai.egg-info}/PKG-INFO +82 -1
- {google_genai-1.38.0 → google_genai-1.39.1}/pyproject.toml +1 -1
- {google_genai-1.38.0 → google_genai-1.39.1}/LICENSE +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/MANIFEST.in +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/__init__.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_adapters.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_api_module.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_automatic_function_calling_util.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_base_transformers.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_base_url.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_extra_utils.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_local_tokenizer_loader.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_mcp_utils.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/_test_api_client.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/chats.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/errors.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/live.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/live_music.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/pagers.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/py.typed +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google/genai/tokens.py +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google_genai.egg-info/SOURCES.txt +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google_genai.egg-info/dependency_links.txt +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google_genai.egg-info/requires.txt +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/google_genai.egg-info/top_level.txt +0 -0
- {google_genai-1.38.0 → google_genai-1.39.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: google-genai
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.39.1
|
4
4
|
Summary: GenAI Python SDK
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
6
6
|
License: Apache-2.0
|
@@ -122,6 +122,87 @@ from google import genai
|
|
122
122
|
client = genai.Client()
|
123
123
|
```
|
124
124
|
|
125
|
+
## Close a client
|
126
|
+
|
127
|
+
Explicitly close the sync client to ensure that resources, such as the
|
128
|
+
underlying HTTP connections, are properly cleaned up and closed.
|
129
|
+
|
130
|
+
```python
|
131
|
+
|
132
|
+
from google.genai import Client
|
133
|
+
|
134
|
+
client = Client()
|
135
|
+
response_1 = client.models.generate_content(
|
136
|
+
model=MODEL_ID,
|
137
|
+
contents='Hello',
|
138
|
+
)
|
139
|
+
response_2 = client.models.generate_content(
|
140
|
+
model=MODEL_ID,
|
141
|
+
contents='Ask a question',
|
142
|
+
)
|
143
|
+
# Close the sync client to release resources.
|
144
|
+
client.close()
|
145
|
+
```
|
146
|
+
|
147
|
+
To explicitly close the async client:
|
148
|
+
|
149
|
+
```python
|
150
|
+
|
151
|
+
from google.genai import Client
|
152
|
+
|
153
|
+
aclient = Client(
|
154
|
+
vertexai=True, project='my-project-id', location='us-central1'
|
155
|
+
).aio
|
156
|
+
response_1 = await aclient.models.generate_content(
|
157
|
+
model=MODEL_ID,
|
158
|
+
contents='Hello',
|
159
|
+
)
|
160
|
+
response_2 = await aclient.models.generate_content(
|
161
|
+
model=MODEL_ID,
|
162
|
+
contents='Ask a question',
|
163
|
+
)
|
164
|
+
# Close the async client to release resources.
|
165
|
+
await aclient.aclose()
|
166
|
+
```
|
167
|
+
|
168
|
+
## Client context managers
|
169
|
+
|
170
|
+
By using the sync client context manager, it will close the underlying
|
171
|
+
sync client when exiting the with block.
|
172
|
+
|
173
|
+
```python
|
174
|
+
from google.genai import Client
|
175
|
+
|
176
|
+
with Client() as client:
|
177
|
+
response_1 = client.models.generate_content(
|
178
|
+
model=MODEL_ID,
|
179
|
+
contents='Hello',
|
180
|
+
)
|
181
|
+
response_2 = client.models.generate_content(
|
182
|
+
model=MODEL_ID,
|
183
|
+
contents='Ask a question',
|
184
|
+
)
|
185
|
+
|
186
|
+
```
|
187
|
+
|
188
|
+
By using the async client context manager, it will close the underlying
|
189
|
+
async client when exiting the with block.
|
190
|
+
|
191
|
+
```python
|
192
|
+
from google.genai import Client
|
193
|
+
|
194
|
+
async with Client().aio as aclient:
|
195
|
+
response_1 = await aclient.models.generate_content(
|
196
|
+
model=MODEL_ID,
|
197
|
+
contents='Hello',
|
198
|
+
)
|
199
|
+
response_2 = await aclient.models.generate_content(
|
200
|
+
model=MODEL_ID,
|
201
|
+
contents='Ask a question',
|
202
|
+
)
|
203
|
+
|
204
|
+
```
|
205
|
+
|
125
206
|
### API Selection
|
126
207
|
|
127
208
|
By default, the SDK uses the beta API endpoints provided by Google to support
|
@@ -85,6 +85,87 @@ from google import genai
|
|
85
85
|
client = genai.Client()
|
86
86
|
```
|
87
87
|
|
88
|
+
## Close a client
|
89
|
+
|
90
|
+
Explicitly close the sync client to ensure that resources, such as the
|
91
|
+
underlying HTTP connections, are properly cleaned up and closed.
|
92
|
+
|
93
|
+
```python
|
94
|
+
|
95
|
+
from google.genai import Client
|
96
|
+
|
97
|
+
client = Client()
|
98
|
+
response_1 = client.models.generate_content(
|
99
|
+
model=MODEL_ID,
|
100
|
+
contents='Hello',
|
101
|
+
)
|
102
|
+
response_2 = client.models.generate_content(
|
103
|
+
model=MODEL_ID,
|
104
|
+
contents='Ask a question',
|
105
|
+
)
|
106
|
+
# Close the sync client to release resources.
|
107
|
+
client.close()
|
108
|
+
```
|
109
|
+
|
110
|
+
To explicitly close the async client:
|
111
|
+
|
112
|
+
```python
|
113
|
+
|
114
|
+
from google.genai import Client
|
115
|
+
|
116
|
+
aclient = Client(
|
117
|
+
vertexai=True, project='my-project-id', location='us-central1'
|
118
|
+
).aio
|
119
|
+
response_1 = await aclient.models.generate_content(
|
120
|
+
model=MODEL_ID,
|
121
|
+
contents='Hello',
|
122
|
+
)
|
123
|
+
response_2 = await aclient.models.generate_content(
|
124
|
+
model=MODEL_ID,
|
125
|
+
contents='Ask a question',
|
126
|
+
)
|
127
|
+
# Close the async client to release resources.
|
128
|
+
await aclient.aclose()
|
129
|
+
```
|
130
|
+
|
131
|
+
## Client context managers
|
132
|
+
|
133
|
+
By using the sync client context manager, it will close the underlying
|
134
|
+
sync client when exiting the with block.
|
135
|
+
|
136
|
+
```python
|
137
|
+
from google.genai import Client
|
138
|
+
|
139
|
+
with Client() as client:
|
140
|
+
response_1 = client.models.generate_content(
|
141
|
+
model=MODEL_ID,
|
142
|
+
contents='Hello',
|
143
|
+
)
|
144
|
+
response_2 = client.models.generate_content(
|
145
|
+
model=MODEL_ID,
|
146
|
+
contents='Ask a question',
|
147
|
+
)
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
By using the async client context manager, it will close the underlying
|
152
|
+
async client when exiting the with block.
|
153
|
+
|
154
|
+
```python
|
155
|
+
from google.genai import Client
|
156
|
+
|
157
|
+
async with Client().aio as aclient:
|
158
|
+
response_1 = await aclient.models.generate_content(
|
159
|
+
model=MODEL_ID,
|
160
|
+
contents='Hello',
|
161
|
+
)
|
162
|
+
response_2 = await aclient.models.generate_content(
|
163
|
+
model=MODEL_ID,
|
164
|
+
contents='Ask a question',
|
165
|
+
)
|
166
|
+
|
167
|
+
```
|
168
|
+
|
88
169
|
### API Selection
|
89
170
|
|
90
171
|
By default, the SDK uses the beta API endpoints provided by Google to support
|
@@ -37,6 +37,7 @@ import time
|
|
37
37
|
from typing import Any, AsyncIterator, Iterator, Optional, Tuple, TYPE_CHECKING, Union
|
38
38
|
from urllib.parse import urlparse
|
39
39
|
from urllib.parse import urlunparse
|
40
|
+
import warnings
|
40
41
|
|
41
42
|
import anyio
|
42
43
|
import certifi
|
@@ -1763,3 +1764,31 @@ class BaseApiClient:
|
|
1763
1764
|
# recorded response.
|
1764
1765
|
def _verify_response(self, response_model: _common.BaseModel) -> None:
|
1765
1766
|
pass
|
1767
|
+
|
1768
|
+
def close(self) -> None:
|
1769
|
+
"""Closes the API client."""
|
1770
|
+
self._httpx_client.close()
|
1771
|
+
|
1772
|
+
async def aclose(self) -> None:
|
1773
|
+
"""Closes the API async client."""
|
1774
|
+
|
1775
|
+
await self._async_httpx_client.aclose()
|
1776
|
+
if self._aiohttp_session:
|
1777
|
+
await self._aiohttp_session.close()
|
1778
|
+
|
1779
|
+
def __del__(self) -> None:
|
1780
|
+
"""Closes the API client when the object is garbage collected.
|
1781
|
+
|
1782
|
+
ADK uses this client so cannot rely on the genai.[Async]Client.__del__
|
1783
|
+
for cleanup.
|
1784
|
+
"""
|
1785
|
+
|
1786
|
+
try:
|
1787
|
+
self.close()
|
1788
|
+
except Exception: # pylint: disable=broad-except
|
1789
|
+
pass
|
1790
|
+
|
1791
|
+
try:
|
1792
|
+
asyncio.get_running_loop().create_task(self.aclose())
|
1793
|
+
except Exception: # pylint: disable=broad-except
|
1794
|
+
pass
|
@@ -314,8 +314,15 @@ def _pretty_repr(
|
|
314
314
|
elif isinstance(obj, collections.abc.Mapping):
|
315
315
|
if not obj:
|
316
316
|
return '{}'
|
317
|
+
|
318
|
+
# Check if the next level of recursion for keys/values will exceed the depth limit.
|
319
|
+
if depth <= 0:
|
320
|
+
item_count_str = f"{len(obj)} item{'s' if len(obj) != 1 else ''}"
|
321
|
+
return f'{{<... {item_count_str} at Max depth ...>}}'
|
322
|
+
|
317
323
|
if len(obj) > max_items:
|
318
324
|
return f'<dict len={len(obj)}>'
|
325
|
+
|
319
326
|
items = []
|
320
327
|
try:
|
321
328
|
sorted_keys = sorted(obj.keys(), key=str)
|
@@ -374,10 +381,12 @@ def _format_collection(
|
|
374
381
|
"""Formats a collection (list, tuple, set)."""
|
375
382
|
if isinstance(obj, list):
|
376
383
|
brackets = ('[', ']')
|
384
|
+
internal_obj = obj
|
377
385
|
elif isinstance(obj, tuple):
|
378
386
|
brackets = ('(', ')')
|
387
|
+
internal_obj = list(obj)
|
379
388
|
elif isinstance(obj, set):
|
380
|
-
|
389
|
+
internal_obj = list(obj)
|
381
390
|
if obj:
|
382
391
|
brackets = ('{', '}')
|
383
392
|
else:
|
@@ -385,19 +394,21 @@ def _format_collection(
|
|
385
394
|
else:
|
386
395
|
raise ValueError(f"Unsupported collection type: {type(obj)}")
|
387
396
|
|
388
|
-
if not
|
397
|
+
if not internal_obj:
|
389
398
|
return brackets[0] + brackets[1]
|
390
399
|
|
400
|
+
# If the call to _pretty_repr for elements will have depth < 0
|
401
|
+
if depth <= 0:
|
402
|
+
item_count_str = f"{len(internal_obj)} item{'s'*(len(internal_obj)!=1)}"
|
403
|
+
return f'{brackets[0]}<... {item_count_str} at Max depth ...>{brackets[1]}'
|
404
|
+
|
391
405
|
indent = ' ' * indent_level
|
392
406
|
next_indent_str = ' ' * (indent_level + indent_delta)
|
393
407
|
elements = []
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
)
|
399
|
-
break
|
400
|
-
# Each element starts on a new line, fully indented
|
408
|
+
num_to_show = min(len(internal_obj), max_items)
|
409
|
+
|
410
|
+
for i in range(num_to_show):
|
411
|
+
elem = internal_obj[i]
|
401
412
|
elements.append(
|
402
413
|
next_indent_str
|
403
414
|
+ _pretty_repr(
|
@@ -411,8 +422,12 @@ def _format_collection(
|
|
411
422
|
)
|
412
423
|
)
|
413
424
|
|
414
|
-
|
425
|
+
if len(internal_obj) > max_items:
|
426
|
+
elements.append(
|
427
|
+
f'{next_indent_str}<... {len(internal_obj) - max_items} more items ...>'
|
428
|
+
)
|
415
429
|
|
430
|
+
return f'{brackets[0]}\n' + ',\n'.join(elements) + f',\n{indent}{brackets[1]}'
|
416
431
|
|
417
432
|
class BaseModel(pydantic.BaseModel):
|
418
433
|
|