google-genai 1.33.0__py3-none-any.whl → 1.53.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 +361 -208
- google/genai/_common.py +260 -69
- google/genai/_extra_utils.py +142 -12
- google/genai/_live_converters.py +691 -2746
- google/genai/_local_tokenizer_loader.py +0 -9
- google/genai/_operations_converters.py +186 -99
- google/genai/_replay_api_client.py +48 -51
- google/genai/_tokens_converters.py +169 -489
- google/genai/_transformers.py +193 -90
- google/genai/batches.py +1014 -1307
- google/genai/caches.py +458 -1107
- google/genai/client.py +101 -0
- google/genai/documents.py +532 -0
- google/genai/errors.py +58 -4
- google/genai/file_search_stores.py +1296 -0
- google/genai/files.py +108 -358
- google/genai/live.py +90 -32
- google/genai/live_music.py +24 -27
- google/genai/local_tokenizer.py +36 -3
- google/genai/models.py +2308 -3375
- google/genai/operations.py +129 -21
- google/genai/pagers.py +7 -1
- google/genai/tokens.py +2 -12
- google/genai/tunings.py +770 -436
- google/genai/types.py +4341 -1218
- google/genai/version.py +1 -1
- {google_genai-1.33.0.dist-info → google_genai-1.53.0.dist-info}/METADATA +359 -201
- google_genai-1.53.0.dist-info/RECORD +41 -0
- google_genai-1.33.0.dist-info/RECORD +0 -39
- {google_genai-1.33.0.dist-info → google_genai-1.53.0.dist-info}/WHEEL +0 -0
- {google_genai-1.33.0.dist-info → google_genai-1.53.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.33.0.dist-info → google_genai-1.53.0.dist-info}/top_level.txt +0 -0
google/genai/errors.py
CHANGED
|
@@ -29,7 +29,7 @@ if TYPE_CHECKING:
|
|
|
29
29
|
class APIError(Exception):
|
|
30
30
|
"""General errors raised by the GenAI API."""
|
|
31
31
|
code: int
|
|
32
|
-
response: Union['ReplayResponse', httpx.Response]
|
|
32
|
+
response: Union['ReplayResponse', httpx.Response, 'aiohttp.ClientResponse']
|
|
33
33
|
|
|
34
34
|
status: Optional[str] = None
|
|
35
35
|
message: Optional[str] = None
|
|
@@ -42,6 +42,9 @@ class APIError(Exception):
|
|
|
42
42
|
Union['ReplayResponse', httpx.Response, 'aiohttp.ClientResponse']
|
|
43
43
|
] = None,
|
|
44
44
|
):
|
|
45
|
+
if isinstance(response_json, list) and len(response_json) == 1:
|
|
46
|
+
response_json = response_json[0]
|
|
47
|
+
|
|
45
48
|
self.response = response
|
|
46
49
|
self.details = response_json
|
|
47
50
|
self.message = self._get_message(response_json)
|
|
@@ -100,7 +103,30 @@ class APIError(Exception):
|
|
|
100
103
|
else:
|
|
101
104
|
response_json = response.body_segments[0].get('error', {})
|
|
102
105
|
|
|
103
|
-
status_code
|
|
106
|
+
cls.raise_error(response.status_code, response_json, response)
|
|
107
|
+
|
|
108
|
+
@classmethod
|
|
109
|
+
def raise_error(
|
|
110
|
+
cls,
|
|
111
|
+
status_code: int,
|
|
112
|
+
response_json: Any,
|
|
113
|
+
response: Optional[
|
|
114
|
+
Union['ReplayResponse', httpx.Response, 'aiohttp.ClientResponse']
|
|
115
|
+
],
|
|
116
|
+
) -> None:
|
|
117
|
+
"""Raises an appropriate APIError subclass based on the status code.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
status_code: The HTTP status code of the response.
|
|
121
|
+
response_json: The JSON body of the response, or a dict containing error
|
|
122
|
+
details.
|
|
123
|
+
response: The original response object.
|
|
124
|
+
|
|
125
|
+
Raises:
|
|
126
|
+
ClientError: If the status code is in the 4xx range.
|
|
127
|
+
ServerError: If the status code is in the 5xx range.
|
|
128
|
+
APIError: For other error status codes.
|
|
129
|
+
"""
|
|
104
130
|
if 400 <= status_code < 500:
|
|
105
131
|
raise ClientError(status_code, response_json, response)
|
|
106
132
|
elif 500 <= status_code < 600:
|
|
@@ -131,6 +157,13 @@ class APIError(Exception):
|
|
|
131
157
|
'status': response.reason_phrase,
|
|
132
158
|
}
|
|
133
159
|
status_code = response.status_code
|
|
160
|
+
elif hasattr(response, 'body_segments') and hasattr(
|
|
161
|
+
response, 'status_code'
|
|
162
|
+
):
|
|
163
|
+
if response.status_code == 200:
|
|
164
|
+
return
|
|
165
|
+
response_json = response.body_segments[0].get('error', {})
|
|
166
|
+
status_code = response.status_code
|
|
134
167
|
else:
|
|
135
168
|
try:
|
|
136
169
|
import aiohttp # pylint: disable=g-import-not-at-top
|
|
@@ -148,10 +181,31 @@ class APIError(Exception):
|
|
|
148
181
|
}
|
|
149
182
|
status_code = response.status
|
|
150
183
|
else:
|
|
151
|
-
|
|
184
|
+
raise ValueError(f'Unsupported response type: {type(response)}')
|
|
152
185
|
except ImportError:
|
|
153
|
-
|
|
186
|
+
raise ValueError(f'Unsupported response type: {type(response)}')
|
|
187
|
+
|
|
188
|
+
await cls.raise_error_async(status_code, response_json, response)
|
|
154
189
|
|
|
190
|
+
@classmethod
|
|
191
|
+
async def raise_error_async(
|
|
192
|
+
cls, status_code: int, response_json: Any, response: Optional[
|
|
193
|
+
Union['ReplayResponse', httpx.Response, 'aiohttp.ClientResponse']
|
|
194
|
+
]
|
|
195
|
+
) -> None:
|
|
196
|
+
"""Raises an appropriate APIError subclass based on the status code.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
status_code: The HTTP status code of the response.
|
|
200
|
+
response_json: The JSON body of the response, or a dict containing error
|
|
201
|
+
details.
|
|
202
|
+
response: The original response object.
|
|
203
|
+
|
|
204
|
+
Raises:
|
|
205
|
+
ClientError: If the status code is in the 4xx range.
|
|
206
|
+
ServerError: If the status code is in the 5xx range.
|
|
207
|
+
APIError: For other error status codes.
|
|
208
|
+
"""
|
|
155
209
|
if 400 <= status_code < 500:
|
|
156
210
|
raise ClientError(status_code, response_json, response)
|
|
157
211
|
elif 500 <= status_code < 600:
|