google-genai 1.52.0__tar.gz → 1.54.0__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.52.0/google_genai.egg-info → google_genai-1.54.0}/PKG-INFO +51 -30
- {google_genai-1.52.0 → google_genai-1.54.0}/README.md +49 -28
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_api_client.py +6 -6
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/batches.py +11 -15
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/caches.py +40 -20
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/documents.py +3 -23
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/errors.py +16 -1
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/file_search_stores.py +9 -25
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/files.py +47 -45
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/live.py +8 -1
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/tunings.py +121 -43
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/types.py +197 -127
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/version.py +1 -1
- {google_genai-1.52.0 → google_genai-1.54.0/google_genai.egg-info}/PKG-INFO +51 -30
- {google_genai-1.52.0 → google_genai-1.54.0}/google_genai.egg-info/requires.txt +1 -1
- {google_genai-1.52.0 → google_genai-1.54.0}/pyproject.toml +11 -7
- {google_genai-1.52.0 → google_genai-1.54.0}/LICENSE +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/MANIFEST.in +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/__init__.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_adapters.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_api_module.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_automatic_function_calling_util.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_base_transformers.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_base_url.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_common.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_extra_utils.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_live_converters.py +3 -3
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_local_tokenizer_loader.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_mcp_utils.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_operations_converters.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_replay_api_client.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_test_api_client.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_tokens_converters.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/_transformers.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/chats.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/client.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/live_music.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/local_tokenizer.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/models.py +3 -3
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/operations.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/pagers.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/py.typed +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google/genai/tokens.py +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google_genai.egg-info/SOURCES.txt +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google_genai.egg-info/dependency_links.txt +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/google_genai.egg-info/top_level.txt +0 -0
- {google_genai-1.52.0 → google_genai-1.54.0}/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.54.0
|
|
4
4
|
Summary: GenAI Python SDK
|
|
5
5
|
Author-email: Google LLC <googleapis-packages@google.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -20,7 +20,7 @@ Requires-Python: >=3.10
|
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
License-File: LICENSE
|
|
22
22
|
Requires-Dist: anyio<5.0.0,>=4.8.0
|
|
23
|
-
Requires-Dist: google-auth<3.0.0,>=2.14.1
|
|
23
|
+
Requires-Dist: google-auth[requests]<3.0.0,>=2.14.1
|
|
24
24
|
Requires-Dist: httpx<1.0.0,>=0.28.1
|
|
25
25
|
Requires-Dist: pydantic<3.0.0,>=2.9.0
|
|
26
26
|
Requires-Dist: requests<3.0.0,>=2.28.1
|
|
@@ -51,6 +51,16 @@ Google's generative models into their Python applications. It supports the
|
|
|
51
51
|
[Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/overview)
|
|
52
52
|
APIs.
|
|
53
53
|
|
|
54
|
+
## Code Generation
|
|
55
|
+
|
|
56
|
+
Generative models are often unaware of recent API and SDK updates and may suggest outdated or legacy code.
|
|
57
|
+
|
|
58
|
+
We recommend using our Code Generation instructions [codegen_instructions.md](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md) when generating Google Gen AI SDK code to guide your model towards using the more recent SDK features.
|
|
59
|
+
|
|
60
|
+
Copy and paste the instructions from [this file](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md)
|
|
61
|
+
into your development environment to provide the model with the necessary
|
|
62
|
+
context
|
|
63
|
+
|
|
54
64
|
## Installation
|
|
55
65
|
|
|
56
66
|
```sh
|
|
@@ -91,6 +101,44 @@ client = genai.Client(
|
|
|
91
101
|
)
|
|
92
102
|
```
|
|
93
103
|
|
|
104
|
+
## Using types
|
|
105
|
+
|
|
106
|
+
All API methods support Pydantic types and dictionaries, which you can access
|
|
107
|
+
from `google.genai.types`. You can import the types module with the following:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from google.genai import types
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Below is an example `generate_content()` call using types from the types module:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
response = client.models.generate_content(
|
|
117
|
+
model='gemini-2.0-flash-001',
|
|
118
|
+
contents=types.Part.from_text(text='Why is the sky blue?'),
|
|
119
|
+
config=types.GenerateContentConfig(
|
|
120
|
+
temperature=0,
|
|
121
|
+
top_p=0.95,
|
|
122
|
+
top_k=20,
|
|
123
|
+
),
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Alternatively, you can accomplish the same request using dictionaries instead of
|
|
128
|
+
types:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
response = client.models.generate_content(
|
|
132
|
+
model='gemini-2.0-flash-001',
|
|
133
|
+
contents={'text': 'Why is the sky blue?'},
|
|
134
|
+
config={
|
|
135
|
+
'temperature': 0,
|
|
136
|
+
'top_p': 0.95,
|
|
137
|
+
'top_k': 20,
|
|
138
|
+
},
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
94
142
|
**(Optional) Using environment variables:**
|
|
95
143
|
|
|
96
144
|
You can create a client by configuring the necessary environment variables.
|
|
@@ -165,7 +213,7 @@ await aclient.aclose()
|
|
|
165
213
|
## Client context managers
|
|
166
214
|
|
|
167
215
|
By using the sync client context manager, it will close the underlying
|
|
168
|
-
sync client when exiting the with block.
|
|
216
|
+
sync client when exiting the with block and avoid httpx "client has been closed" error like [issues#1763](https://github.com/googleapis/python-genai/issues/1763).
|
|
169
217
|
|
|
170
218
|
```python
|
|
171
219
|
from google.genai import Client
|
|
@@ -583,33 +631,6 @@ response = client.models.generate_content(
|
|
|
583
631
|
print(response.text)
|
|
584
632
|
```
|
|
585
633
|
|
|
586
|
-
### Typed Config
|
|
587
|
-
|
|
588
|
-
All API methods support Pydantic types for parameters as well as
|
|
589
|
-
dictionaries. You can get the type from `google.genai.types`.
|
|
590
|
-
|
|
591
|
-
```python
|
|
592
|
-
from google.genai import types
|
|
593
|
-
|
|
594
|
-
response = client.models.generate_content(
|
|
595
|
-
model='gemini-2.0-flash-001',
|
|
596
|
-
contents=types.Part.from_text(text='Why is the sky blue?'),
|
|
597
|
-
config=types.GenerateContentConfig(
|
|
598
|
-
temperature=0,
|
|
599
|
-
top_p=0.95,
|
|
600
|
-
top_k=20,
|
|
601
|
-
candidate_count=1,
|
|
602
|
-
seed=5,
|
|
603
|
-
max_output_tokens=100,
|
|
604
|
-
stop_sequences=['STOP!'],
|
|
605
|
-
presence_penalty=0.0,
|
|
606
|
-
frequency_penalty=0.0,
|
|
607
|
-
),
|
|
608
|
-
)
|
|
609
|
-
|
|
610
|
-
print(response.text)
|
|
611
|
-
```
|
|
612
|
-
|
|
613
634
|
### List Base Models
|
|
614
635
|
|
|
615
636
|
To retrieve tuned models, see [list tuned models](#list-tuned-models).
|
|
@@ -15,6 +15,16 @@ Google's generative models into their Python applications. It supports the
|
|
|
15
15
|
[Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/overview)
|
|
16
16
|
APIs.
|
|
17
17
|
|
|
18
|
+
## Code Generation
|
|
19
|
+
|
|
20
|
+
Generative models are often unaware of recent API and SDK updates and may suggest outdated or legacy code.
|
|
21
|
+
|
|
22
|
+
We recommend using our Code Generation instructions [codegen_instructions.md](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md) when generating Google Gen AI SDK code to guide your model towards using the more recent SDK features.
|
|
23
|
+
|
|
24
|
+
Copy and paste the instructions from [this file](https://raw.githubusercontent.com/googleapis/python-genai/refs/heads/main/codegen_instructions.md)
|
|
25
|
+
into your development environment to provide the model with the necessary
|
|
26
|
+
context
|
|
27
|
+
|
|
18
28
|
## Installation
|
|
19
29
|
|
|
20
30
|
```sh
|
|
@@ -55,6 +65,44 @@ client = genai.Client(
|
|
|
55
65
|
)
|
|
56
66
|
```
|
|
57
67
|
|
|
68
|
+
## Using types
|
|
69
|
+
|
|
70
|
+
All API methods support Pydantic types and dictionaries, which you can access
|
|
71
|
+
from `google.genai.types`. You can import the types module with the following:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from google.genai import types
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Below is an example `generate_content()` call using types from the types module:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
response = client.models.generate_content(
|
|
81
|
+
model='gemini-2.0-flash-001',
|
|
82
|
+
contents=types.Part.from_text(text='Why is the sky blue?'),
|
|
83
|
+
config=types.GenerateContentConfig(
|
|
84
|
+
temperature=0,
|
|
85
|
+
top_p=0.95,
|
|
86
|
+
top_k=20,
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Alternatively, you can accomplish the same request using dictionaries instead of
|
|
92
|
+
types:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
response = client.models.generate_content(
|
|
96
|
+
model='gemini-2.0-flash-001',
|
|
97
|
+
contents={'text': 'Why is the sky blue?'},
|
|
98
|
+
config={
|
|
99
|
+
'temperature': 0,
|
|
100
|
+
'top_p': 0.95,
|
|
101
|
+
'top_k': 20,
|
|
102
|
+
},
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
58
106
|
**(Optional) Using environment variables:**
|
|
59
107
|
|
|
60
108
|
You can create a client by configuring the necessary environment variables.
|
|
@@ -129,7 +177,7 @@ await aclient.aclose()
|
|
|
129
177
|
## Client context managers
|
|
130
178
|
|
|
131
179
|
By using the sync client context manager, it will close the underlying
|
|
132
|
-
sync client when exiting the with block.
|
|
180
|
+
sync client when exiting the with block and avoid httpx "client has been closed" error like [issues#1763](https://github.com/googleapis/python-genai/issues/1763).
|
|
133
181
|
|
|
134
182
|
```python
|
|
135
183
|
from google.genai import Client
|
|
@@ -547,33 +595,6 @@ response = client.models.generate_content(
|
|
|
547
595
|
print(response.text)
|
|
548
596
|
```
|
|
549
597
|
|
|
550
|
-
### Typed Config
|
|
551
|
-
|
|
552
|
-
All API methods support Pydantic types for parameters as well as
|
|
553
|
-
dictionaries. You can get the type from `google.genai.types`.
|
|
554
|
-
|
|
555
|
-
```python
|
|
556
|
-
from google.genai import types
|
|
557
|
-
|
|
558
|
-
response = client.models.generate_content(
|
|
559
|
-
model='gemini-2.0-flash-001',
|
|
560
|
-
contents=types.Part.from_text(text='Why is the sky blue?'),
|
|
561
|
-
config=types.GenerateContentConfig(
|
|
562
|
-
temperature=0,
|
|
563
|
-
top_p=0.95,
|
|
564
|
-
top_k=20,
|
|
565
|
-
candidate_count=1,
|
|
566
|
-
seed=5,
|
|
567
|
-
max_output_tokens=100,
|
|
568
|
-
stop_sequences=['STOP!'],
|
|
569
|
-
presence_penalty=0.0,
|
|
570
|
-
frequency_penalty=0.0,
|
|
571
|
-
),
|
|
572
|
-
)
|
|
573
|
-
|
|
574
|
-
print(response.text)
|
|
575
|
-
```
|
|
576
|
-
|
|
577
598
|
### List Base Models
|
|
578
599
|
|
|
579
600
|
To retrieve tuned models, see [list tuned models](#list-tuned-models).
|
|
@@ -1254,7 +1254,7 @@ class BaseApiClient:
|
|
|
1254
1254
|
url=http_request.url,
|
|
1255
1255
|
headers=http_request.headers,
|
|
1256
1256
|
data=data,
|
|
1257
|
-
timeout=aiohttp.ClientTimeout(
|
|
1257
|
+
timeout=aiohttp.ClientTimeout(total=http_request.timeout),
|
|
1258
1258
|
**self._async_client_session_request_args,
|
|
1259
1259
|
)
|
|
1260
1260
|
except (
|
|
@@ -1276,7 +1276,7 @@ class BaseApiClient:
|
|
|
1276
1276
|
url=http_request.url,
|
|
1277
1277
|
headers=http_request.headers,
|
|
1278
1278
|
data=data,
|
|
1279
|
-
timeout=aiohttp.ClientTimeout(
|
|
1279
|
+
timeout=aiohttp.ClientTimeout(total=http_request.timeout),
|
|
1280
1280
|
**self._async_client_session_request_args,
|
|
1281
1281
|
)
|
|
1282
1282
|
|
|
@@ -1306,7 +1306,7 @@ class BaseApiClient:
|
|
|
1306
1306
|
url=http_request.url,
|
|
1307
1307
|
headers=http_request.headers,
|
|
1308
1308
|
data=data,
|
|
1309
|
-
timeout=aiohttp.ClientTimeout(
|
|
1309
|
+
timeout=aiohttp.ClientTimeout(total=http_request.timeout),
|
|
1310
1310
|
**self._async_client_session_request_args,
|
|
1311
1311
|
)
|
|
1312
1312
|
await errors.APIError.raise_for_async_response(response)
|
|
@@ -1330,7 +1330,7 @@ class BaseApiClient:
|
|
|
1330
1330
|
url=http_request.url,
|
|
1331
1331
|
headers=http_request.headers,
|
|
1332
1332
|
data=data,
|
|
1333
|
-
timeout=aiohttp.ClientTimeout(
|
|
1333
|
+
timeout=aiohttp.ClientTimeout(total=http_request.timeout),
|
|
1334
1334
|
**self._async_client_session_request_args,
|
|
1335
1335
|
)
|
|
1336
1336
|
await errors.APIError.raise_for_async_response(response)
|
|
@@ -1718,7 +1718,7 @@ class BaseApiClient:
|
|
|
1718
1718
|
url=upload_url,
|
|
1719
1719
|
data=file_chunk,
|
|
1720
1720
|
headers=upload_headers,
|
|
1721
|
-
timeout=aiohttp.ClientTimeout(
|
|
1721
|
+
timeout=aiohttp.ClientTimeout(total=timeout_in_seconds),
|
|
1722
1722
|
)
|
|
1723
1723
|
|
|
1724
1724
|
if response.headers.get('X-Goog-Upload-Status'):
|
|
@@ -1864,7 +1864,7 @@ class BaseApiClient:
|
|
|
1864
1864
|
url=http_request.url,
|
|
1865
1865
|
headers=http_request.headers,
|
|
1866
1866
|
data=data,
|
|
1867
|
-
timeout=aiohttp.ClientTimeout(
|
|
1867
|
+
timeout=aiohttp.ClientTimeout(total=http_request.timeout),
|
|
1868
1868
|
)
|
|
1869
1869
|
await errors.APIError.raise_for_async_response(response)
|
|
1870
1870
|
|
|
@@ -2012,16 +2012,15 @@ class Batches(_api_module.BaseModule):
|
|
|
2012
2012
|
Usage:
|
|
2013
2013
|
|
|
2014
2014
|
.. code-block:: python
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
print(f"Batch job: {batch_job.name}, state {batch_job.state}")
|
|
2015
|
+
config = {'page_size': 10}
|
|
2016
|
+
for batch_job in client.batches.list(config):
|
|
2017
|
+
print(batch_job.name)
|
|
2019
2018
|
"""
|
|
2020
|
-
|
|
2021
|
-
|
|
2019
|
+
|
|
2020
|
+
list_request = self._list
|
|
2022
2021
|
return Pager(
|
|
2023
2022
|
'batch_jobs',
|
|
2024
|
-
|
|
2023
|
+
list_request,
|
|
2025
2024
|
self._list(config=config),
|
|
2026
2025
|
config,
|
|
2027
2026
|
)
|
|
@@ -2568,17 +2567,14 @@ class AsyncBatches(_api_module.BaseModule):
|
|
|
2568
2567
|
Usage:
|
|
2569
2568
|
|
|
2570
2569
|
.. code-block:: python
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
print(f"current page: {batch_jobs.page}")
|
|
2574
|
-
await batch_jobs_pager.next_page()
|
|
2575
|
-
print(f"next page: {batch_jobs_pager.page}")
|
|
2570
|
+
async for batch_job in await client.aio.batches.list():
|
|
2571
|
+
print(batch_job.name)
|
|
2576
2572
|
"""
|
|
2577
|
-
|
|
2578
|
-
|
|
2573
|
+
|
|
2574
|
+
list_request = self._list
|
|
2579
2575
|
return AsyncPager(
|
|
2580
2576
|
'batch_jobs',
|
|
2581
|
-
|
|
2577
|
+
list_request,
|
|
2582
2578
|
await self._list(config=config),
|
|
2583
2579
|
config,
|
|
2584
2580
|
)
|
|
@@ -1129,15 +1129,6 @@ class Caches(_api_module.BaseModule):
|
|
|
1129
1129
|
def _list(
|
|
1130
1130
|
self, *, config: Optional[types.ListCachedContentsConfigOrDict] = None
|
|
1131
1131
|
) -> types.ListCachedContentsResponse:
|
|
1132
|
-
"""Lists cached content configurations.
|
|
1133
|
-
|
|
1134
|
-
.. code-block:: python
|
|
1135
|
-
|
|
1136
|
-
cached_contents = client.caches.list(config={'page_size': 2})
|
|
1137
|
-
for cached_content in cached_contents:
|
|
1138
|
-
print(cached_content)
|
|
1139
|
-
"""
|
|
1140
|
-
|
|
1141
1132
|
parameter_model = types._ListCachedContentsParameters(
|
|
1142
1133
|
config=config,
|
|
1143
1134
|
)
|
|
@@ -1196,9 +1187,28 @@ class Caches(_api_module.BaseModule):
|
|
|
1196
1187
|
def list(
|
|
1197
1188
|
self, *, config: Optional[types.ListCachedContentsConfigOrDict] = None
|
|
1198
1189
|
) -> Pager[types.CachedContent]:
|
|
1190
|
+
"""Lists cached contents.
|
|
1191
|
+
|
|
1192
|
+
Args:
|
|
1193
|
+
config (ListCachedContentsConfig): Optional configuration for the list
|
|
1194
|
+
request.
|
|
1195
|
+
|
|
1196
|
+
Returns:
|
|
1197
|
+
A Pager object that contains one page of cached contents. When iterating
|
|
1198
|
+
over
|
|
1199
|
+
the pager, it automatically fetches the next page if there are more.
|
|
1200
|
+
|
|
1201
|
+
Usage:
|
|
1202
|
+
|
|
1203
|
+
.. code-block:: python
|
|
1204
|
+
for cached_content in client.caches.list():
|
|
1205
|
+
print(cached_content.name)
|
|
1206
|
+
"""
|
|
1207
|
+
|
|
1208
|
+
list_request = self._list
|
|
1199
1209
|
return Pager(
|
|
1200
1210
|
'cached_contents',
|
|
1201
|
-
|
|
1211
|
+
list_request,
|
|
1202
1212
|
self._list(config=config),
|
|
1203
1213
|
config,
|
|
1204
1214
|
)
|
|
@@ -1505,15 +1515,6 @@ class AsyncCaches(_api_module.BaseModule):
|
|
|
1505
1515
|
async def _list(
|
|
1506
1516
|
self, *, config: Optional[types.ListCachedContentsConfigOrDict] = None
|
|
1507
1517
|
) -> types.ListCachedContentsResponse:
|
|
1508
|
-
"""Lists cached content configurations.
|
|
1509
|
-
|
|
1510
|
-
.. code-block:: python
|
|
1511
|
-
|
|
1512
|
-
cached_contents = await client.aio.caches.list(config={'page_size': 2})
|
|
1513
|
-
async for cached_content in cached_contents:
|
|
1514
|
-
print(cached_content)
|
|
1515
|
-
"""
|
|
1516
|
-
|
|
1517
1518
|
parameter_model = types._ListCachedContentsParameters(
|
|
1518
1519
|
config=config,
|
|
1519
1520
|
)
|
|
@@ -1574,9 +1575,28 @@ class AsyncCaches(_api_module.BaseModule):
|
|
|
1574
1575
|
async def list(
|
|
1575
1576
|
self, *, config: Optional[types.ListCachedContentsConfigOrDict] = None
|
|
1576
1577
|
) -> AsyncPager[types.CachedContent]:
|
|
1578
|
+
"""Lists cached contents asynchronously.
|
|
1579
|
+
|
|
1580
|
+
Args:
|
|
1581
|
+
config (ListCachedContentsConfig): Optional configuration for the list
|
|
1582
|
+
request.
|
|
1583
|
+
|
|
1584
|
+
Returns:
|
|
1585
|
+
A Pager object that contains one page of cached contents. When iterating
|
|
1586
|
+
over
|
|
1587
|
+
the pager, it automatically fetches the next page if there are more.
|
|
1588
|
+
|
|
1589
|
+
Usage:
|
|
1590
|
+
|
|
1591
|
+
.. code-block:: python
|
|
1592
|
+
async for cached_content in await client.aio.caches.list():
|
|
1593
|
+
print(cached_content.name)
|
|
1594
|
+
"""
|
|
1595
|
+
|
|
1596
|
+
list_request = self._list
|
|
1577
1597
|
return AsyncPager(
|
|
1578
1598
|
'cached_contents',
|
|
1579
|
-
|
|
1599
|
+
list_request,
|
|
1580
1600
|
await self._list(config=config),
|
|
1581
1601
|
config,
|
|
1582
1602
|
)
|
|
@@ -249,17 +249,6 @@ class Documents(_api_module.BaseModule):
|
|
|
249
249
|
parent: str,
|
|
250
250
|
config: Optional[types.ListDocumentsConfigOrDict] = None,
|
|
251
251
|
) -> types.ListDocumentsResponse:
|
|
252
|
-
"""Lists all Documents in a FileSearchStore.
|
|
253
|
-
|
|
254
|
-
Args:
|
|
255
|
-
parent (str): The name of the FileSearchStore containing the Documents.
|
|
256
|
-
config (ListDocumentsConfig | None): Optional parameters for the request,
|
|
257
|
-
such as page_size.
|
|
258
|
-
|
|
259
|
-
Returns:
|
|
260
|
-
ListDocumentsResponse: A paginated list of Documents.
|
|
261
|
-
"""
|
|
262
|
-
|
|
263
252
|
parameter_model = types._ListDocumentsParameters(
|
|
264
253
|
parent=parent,
|
|
265
254
|
config=config,
|
|
@@ -328,6 +317,7 @@ class Documents(_api_module.BaseModule):
|
|
|
328
317
|
for document in client.documents.list(parent='rag_store_name'):
|
|
329
318
|
print(f"document: {document.name} - {document.display_name}")
|
|
330
319
|
"""
|
|
320
|
+
|
|
331
321
|
list_request = partial(self._list, parent=parent)
|
|
332
322
|
return Pager(
|
|
333
323
|
'documents',
|
|
@@ -461,17 +451,6 @@ class AsyncDocuments(_api_module.BaseModule):
|
|
|
461
451
|
parent: str,
|
|
462
452
|
config: Optional[types.ListDocumentsConfigOrDict] = None,
|
|
463
453
|
) -> types.ListDocumentsResponse:
|
|
464
|
-
"""Lists all Documents in a FileSearchStore.
|
|
465
|
-
|
|
466
|
-
Args:
|
|
467
|
-
parent (str): The name of the FileSearchStore containing the Documents.
|
|
468
|
-
config (ListDocumentsConfig | None): Optional parameters for the request,
|
|
469
|
-
such as page_size.
|
|
470
|
-
|
|
471
|
-
Returns:
|
|
472
|
-
ListDocumentsResponse: A paginated list of Documents.
|
|
473
|
-
"""
|
|
474
|
-
|
|
475
454
|
parameter_model = types._ListDocumentsParameters(
|
|
476
455
|
parent=parent,
|
|
477
456
|
config=config,
|
|
@@ -540,9 +519,10 @@ class AsyncDocuments(_api_module.BaseModule):
|
|
|
540
519
|
Usage:
|
|
541
520
|
.. code-block:: python
|
|
542
521
|
async for document in await
|
|
543
|
-
client.documents.list(parent='rag_store_name'):
|
|
522
|
+
client.aio.documents.list(parent='rag_store_name'):
|
|
544
523
|
print(f"document: {document.name} - {document.display_name}")
|
|
545
524
|
"""
|
|
525
|
+
|
|
546
526
|
list_request = partial(self._list, parent=parent)
|
|
547
527
|
return AsyncPager(
|
|
548
528
|
'documents',
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
"""Error classes for the GenAI SDK."""
|
|
17
17
|
|
|
18
|
-
from typing import Any, Optional, TYPE_CHECKING, Union
|
|
18
|
+
from typing import Any, Callable, Optional, TYPE_CHECKING, Union
|
|
19
19
|
import httpx
|
|
20
20
|
import json
|
|
21
21
|
from . import _common
|
|
@@ -53,6 +53,21 @@ class APIError(Exception):
|
|
|
53
53
|
|
|
54
54
|
super().__init__(f'{self.code} {self.status}. {self.details}')
|
|
55
55
|
|
|
56
|
+
def __reduce__(
|
|
57
|
+
self,
|
|
58
|
+
) -> tuple[Callable[..., 'APIError'], tuple[dict[str, Any]]]:
|
|
59
|
+
"""Returns a tuple that can be used to reconstruct the error for pickling."""
|
|
60
|
+
state = self.__dict__.copy()
|
|
61
|
+
return (self.__class__._rebuild, (state,))
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def _rebuild(state: dict[str, Any]) -> 'APIError':
|
|
65
|
+
"""Rebuilds the error from the state."""
|
|
66
|
+
obj = APIError.__new__(APIError)
|
|
67
|
+
obj.__dict__.update(state)
|
|
68
|
+
Exception.__init__(obj, f'{obj.code} {obj.status}. {obj.details}')
|
|
69
|
+
return obj
|
|
70
|
+
|
|
56
71
|
def _get_status(self, response_json: Any) -> Any:
|
|
57
72
|
return response_json.get(
|
|
58
73
|
'status', response_json.get('error', {}).get('status', None)
|
|
@@ -499,16 +499,6 @@ class FileSearchStores(_api_module.BaseModule):
|
|
|
499
499
|
def _list(
|
|
500
500
|
self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
|
|
501
501
|
) -> types.ListFileSearchStoresResponse:
|
|
502
|
-
"""Lists all FileSearchStore owned by the user.
|
|
503
|
-
|
|
504
|
-
Args:
|
|
505
|
-
config (ListFileSearchStoresConfig | None): Optional parameters for the
|
|
506
|
-
request, such as page_size.
|
|
507
|
-
|
|
508
|
-
Returns:
|
|
509
|
-
ListFileSearchStoresResponse: A paginated list of FileSearchStore.
|
|
510
|
-
"""
|
|
511
|
-
|
|
512
502
|
parameter_model = types._ListFileSearchStoresParameters(
|
|
513
503
|
config=config,
|
|
514
504
|
)
|
|
@@ -802,9 +792,11 @@ class FileSearchStores(_api_module.BaseModule):
|
|
|
802
792
|
print(f"file search store: {file_search_store.name} -
|
|
803
793
|
{file_search_store.display_name}")
|
|
804
794
|
"""
|
|
795
|
+
|
|
796
|
+
list_request = self._list
|
|
805
797
|
return Pager(
|
|
806
798
|
'file_search_stores',
|
|
807
|
-
|
|
799
|
+
list_request,
|
|
808
800
|
self._list(config=config),
|
|
809
801
|
config,
|
|
810
802
|
)
|
|
@@ -999,16 +991,6 @@ class AsyncFileSearchStores(_api_module.BaseModule):
|
|
|
999
991
|
async def _list(
|
|
1000
992
|
self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None
|
|
1001
993
|
) -> types.ListFileSearchStoresResponse:
|
|
1002
|
-
"""Lists all FileSearchStore owned by the user.
|
|
1003
|
-
|
|
1004
|
-
Args:
|
|
1005
|
-
config (ListFileSearchStoresConfig | None): Optional parameters for the
|
|
1006
|
-
request, such as page_size.
|
|
1007
|
-
|
|
1008
|
-
Returns:
|
|
1009
|
-
ListFileSearchStoresResponse: A paginated list of FileSearchStore.
|
|
1010
|
-
"""
|
|
1011
|
-
|
|
1012
994
|
parameter_model = types._ListFileSearchStoresParameters(
|
|
1013
995
|
config=config,
|
|
1014
996
|
)
|
|
@@ -1289,8 +1271,8 @@ class AsyncFileSearchStores(_api_module.BaseModule):
|
|
|
1289
1271
|
"""Lists FileSearchStores asynchronously.
|
|
1290
1272
|
|
|
1291
1273
|
Args:
|
|
1292
|
-
config (ListFileSearchStoresConfig): Optional
|
|
1293
|
-
|
|
1274
|
+
config (ListFileSearchStoresConfig): Optional parameters for the request,
|
|
1275
|
+
such as page_size.
|
|
1294
1276
|
|
|
1295
1277
|
Returns:
|
|
1296
1278
|
A Pager object that contains one page of FileSearchStores. When iterating
|
|
@@ -1300,13 +1282,15 @@ class AsyncFileSearchStores(_api_module.BaseModule):
|
|
|
1300
1282
|
Usage:
|
|
1301
1283
|
|
|
1302
1284
|
.. code-block:: python
|
|
1303
|
-
async for file_search_store in await client.file_search_stores.list():
|
|
1285
|
+
async for file_search_store in await client.aio.file_search_stores.list():
|
|
1304
1286
|
print(f"file search store: {file_search_store.name} -
|
|
1305
1287
|
{file_search_store.display_name}")
|
|
1306
1288
|
"""
|
|
1289
|
+
|
|
1290
|
+
list_request = self._list
|
|
1307
1291
|
return AsyncPager(
|
|
1308
1292
|
'file_search_stores',
|
|
1309
|
-
|
|
1293
|
+
list_request,
|
|
1310
1294
|
await self._list(config=config),
|
|
1311
1295
|
config,
|
|
1312
1296
|
)
|