cohere-python

Форк
0
571 строка · 29.0 Кб
1
# This file was auto-generated by Fern from our API Definition.
2

3
import typing
4
import urllib.parse
5
from json.decoder import JSONDecodeError
6

7
from ..core.api_error import ApiError
8
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
9
from ..core.jsonable_encoder import jsonable_encoder
10
from ..core.remove_none_from_dict import remove_none_from_dict
11
from ..core.request_options import RequestOptions
12
from ..errors.bad_request_error import BadRequestError
13
from ..errors.internal_server_error import InternalServerError
14
from ..errors.not_found_error import NotFoundError
15
from ..errors.too_many_requests_error import TooManyRequestsError
16
from ..types.create_embed_job_response import CreateEmbedJobResponse
17
from ..types.embed_input_type import EmbedInputType
18
from ..types.embed_job import EmbedJob
19
from ..types.embedding_type import EmbeddingType
20
from ..types.list_embed_job_response import ListEmbedJobResponse
21
from .types.create_embed_job_request_truncate import CreateEmbedJobRequestTruncate
22

23
try:
24
    import pydantic.v1 as pydantic  # type: ignore
25
except ImportError:
26
    import pydantic  # type: ignore
27

28
# this is used as the default value for optional parameters
29
OMIT = typing.cast(typing.Any, ...)
30

31

32
class EmbedJobsClient:
33
    def __init__(self, *, client_wrapper: SyncClientWrapper):
34
        self._client_wrapper = client_wrapper
35

36
    def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> ListEmbedJobResponse:
37
        """
38
        The list embed job endpoint allows users to view all embed jobs history for that specific user.
39

40
        Parameters:
41
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
42
        ---
43
        from cohere.client import Client
44

45
        client = Client(
46
            client_name="YOUR_CLIENT_NAME",
47
            token="YOUR_TOKEN",
48
        )
49
        client.embed_jobs.list()
50
        """
51
        _response = self._client_wrapper.httpx_client.request(
52
            "GET",
53
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "embed-jobs"),
54
            params=jsonable_encoder(
55
                request_options.get("additional_query_parameters") if request_options is not None else None
56
            ),
57
            headers=jsonable_encoder(
58
                remove_none_from_dict(
59
                    {
60
                        **self._client_wrapper.get_headers(),
61
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
62
                    }
63
                )
64
            ),
65
            timeout=request_options.get("timeout_in_seconds")
66
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
67
            else self._client_wrapper.get_timeout(),
68
            retries=0,
69
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
70
        )
71
        if 200 <= _response.status_code < 300:
72
            return pydantic.parse_obj_as(ListEmbedJobResponse, _response.json())  # type: ignore
73
        if _response.status_code == 400:
74
            raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
75
        if _response.status_code == 429:
76
            raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
77
        if _response.status_code == 500:
78
            raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
79
        try:
80
            _response_json = _response.json()
81
        except JSONDecodeError:
82
            raise ApiError(status_code=_response.status_code, body=_response.text)
83
        raise ApiError(status_code=_response.status_code, body=_response_json)
84

85
    def create(
86
        self,
87
        *,
88
        model: str,
89
        dataset_id: str,
90
        input_type: EmbedInputType,
91
        name: typing.Optional[str] = OMIT,
92
        embedding_types: typing.Optional[typing.Sequence[EmbeddingType]] = OMIT,
93
        truncate: typing.Optional[CreateEmbedJobRequestTruncate] = OMIT,
94
        request_options: typing.Optional[RequestOptions] = None,
95
    ) -> CreateEmbedJobResponse:
96
        """
97
        This API launches an async Embed job for a [Dataset](https://docs.cohere.com/docs/datasets) of type `embed-input`. The result of a completed embed job is new Dataset of type `embed-output`, which contains the original text entries and the corresponding embeddings.
98

99
        Parameters:
100
            - model: str. ID of the embedding model.
101

102
                          Available models and corresponding embedding dimensions:
103

104
                          - `embed-english-v3.0` : 1024
105
                          - `embed-multilingual-v3.0` : 1024
106
                          - `embed-english-light-v3.0` : 384
107
                          - `embed-multilingual-light-v3.0` : 384
108

109
            - dataset_id: str. ID of a [Dataset](https://docs.cohere.com/docs/datasets). The Dataset must be of type `embed-input` and must have a validation status `Validated`
110

111
            - input_type: EmbedInputType.
112

113
            - name: typing.Optional[str]. The name of the embed job.
114

115
            - embedding_types: typing.Optional[typing.Sequence[EmbeddingType]]. Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types.
116

117
                                                                                * `"float"`: Use this when you want to get back the default float embeddings. Valid for all models.
118
                                                                                * `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
119
                                                                                * `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
120
                                                                                * `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models.
121
                                                                                * `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.
122
            - truncate: typing.Optional[CreateEmbedJobRequestTruncate]. One of `START|END` to specify how the API will handle inputs longer than the maximum token length.
123

124
                                                                        Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model.
125

126
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
127
        ---
128
        from cohere.client import Client
129

130
        client = Client(
131
            client_name="YOUR_CLIENT_NAME",
132
            token="YOUR_TOKEN",
133
        )
134
        client.embed_jobs.create(
135
            model="model",
136
            dataset_id="dataset_id",
137
            input_type="search_document",
138
        )
139
        """
140
        _request: typing.Dict[str, typing.Any] = {"model": model, "dataset_id": dataset_id, "input_type": input_type}
141
        if name is not OMIT:
142
            _request["name"] = name
143
        if embedding_types is not OMIT:
144
            _request["embedding_types"] = embedding_types
145
        if truncate is not OMIT:
146
            _request["truncate"] = truncate
147
        _response = self._client_wrapper.httpx_client.request(
148
            "POST",
149
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "embed-jobs"),
150
            params=jsonable_encoder(
151
                request_options.get("additional_query_parameters") if request_options is not None else None
152
            ),
153
            json=jsonable_encoder(_request)
154
            if request_options is None or request_options.get("additional_body_parameters") is None
155
            else {
156
                **jsonable_encoder(_request),
157
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
158
            },
159
            headers=jsonable_encoder(
160
                remove_none_from_dict(
161
                    {
162
                        **self._client_wrapper.get_headers(),
163
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
164
                    }
165
                )
166
            ),
167
            timeout=request_options.get("timeout_in_seconds")
168
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
169
            else self._client_wrapper.get_timeout(),
170
            retries=0,
171
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
172
        )
173
        if 200 <= _response.status_code < 300:
174
            return pydantic.parse_obj_as(CreateEmbedJobResponse, _response.json())  # type: ignore
175
        if _response.status_code == 400:
176
            raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
177
        if _response.status_code == 429:
178
            raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
179
        if _response.status_code == 500:
180
            raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
181
        try:
182
            _response_json = _response.json()
183
        except JSONDecodeError:
184
            raise ApiError(status_code=_response.status_code, body=_response.text)
185
        raise ApiError(status_code=_response.status_code, body=_response_json)
186

187
    def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EmbedJob:
188
        """
189
        This API retrieves the details about an embed job started by the same user.
190

191
        Parameters:
192
            - id: str. The ID of the embed job to retrieve.
193

194
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
195
        ---
196
        from cohere.client import Client
197

198
        client = Client(
199
            client_name="YOUR_CLIENT_NAME",
200
            token="YOUR_TOKEN",
201
        )
202
        client.embed_jobs.get(
203
            id="id",
204
        )
205
        """
206
        _response = self._client_wrapper.httpx_client.request(
207
            "GET",
208
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"embed-jobs/{jsonable_encoder(id)}"),
209
            params=jsonable_encoder(
210
                request_options.get("additional_query_parameters") if request_options is not None else None
211
            ),
212
            headers=jsonable_encoder(
213
                remove_none_from_dict(
214
                    {
215
                        **self._client_wrapper.get_headers(),
216
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
217
                    }
218
                )
219
            ),
220
            timeout=request_options.get("timeout_in_seconds")
221
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
222
            else self._client_wrapper.get_timeout(),
223
            retries=0,
224
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
225
        )
226
        if 200 <= _response.status_code < 300:
227
            return pydantic.parse_obj_as(EmbedJob, _response.json())  # type: ignore
228
        if _response.status_code == 400:
229
            raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
230
        if _response.status_code == 404:
231
            raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
232
        if _response.status_code == 429:
233
            raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
234
        if _response.status_code == 500:
235
            raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
236
        try:
237
            _response_json = _response.json()
238
        except JSONDecodeError:
239
            raise ApiError(status_code=_response.status_code, body=_response.text)
240
        raise ApiError(status_code=_response.status_code, body=_response_json)
241

242
    def cancel(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
243
        """
244
        This API allows users to cancel an active embed job. Once invoked, the embedding process will be terminated, and users will be charged for the embeddings processed up to the cancellation point. It's important to note that partial results will not be available to users after cancellation.
245

246
        Parameters:
247
            - id: str. The ID of the embed job to cancel.
248

249
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
250
        ---
251
        from cohere.client import Client
252

253
        client = Client(
254
            client_name="YOUR_CLIENT_NAME",
255
            token="YOUR_TOKEN",
256
        )
257
        client.embed_jobs.cancel(
258
            id="id",
259
        )
260
        """
261
        _response = self._client_wrapper.httpx_client.request(
262
            "POST",
263
            urllib.parse.urljoin(
264
                f"{self._client_wrapper.get_base_url()}/", f"embed-jobs/{jsonable_encoder(id)}/cancel"
265
            ),
266
            params=jsonable_encoder(
267
                request_options.get("additional_query_parameters") if request_options is not None else None
268
            ),
269
            json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))
270
            if request_options is not None
271
            else None,
272
            headers=jsonable_encoder(
273
                remove_none_from_dict(
274
                    {
275
                        **self._client_wrapper.get_headers(),
276
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
277
                    }
278
                )
279
            ),
280
            timeout=request_options.get("timeout_in_seconds")
281
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
282
            else self._client_wrapper.get_timeout(),
283
            retries=0,
284
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
285
        )
286
        if 200 <= _response.status_code < 300:
287
            return
288
        if _response.status_code == 400:
289
            raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
290
        if _response.status_code == 404:
291
            raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
292
        if _response.status_code == 429:
293
            raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
294
        if _response.status_code == 500:
295
            raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
296
        try:
297
            _response_json = _response.json()
298
        except JSONDecodeError:
299
            raise ApiError(status_code=_response.status_code, body=_response.text)
300
        raise ApiError(status_code=_response.status_code, body=_response_json)
301

302

303
class AsyncEmbedJobsClient:
304
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
305
        self._client_wrapper = client_wrapper
306

307
    async def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> ListEmbedJobResponse:
308
        """
309
        The list embed job endpoint allows users to view all embed jobs history for that specific user.
310

311
        Parameters:
312
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
313
        ---
314
        from cohere.client import AsyncClient
315

316
        client = AsyncClient(
317
            client_name="YOUR_CLIENT_NAME",
318
            token="YOUR_TOKEN",
319
        )
320
        await client.embed_jobs.list()
321
        """
322
        _response = await self._client_wrapper.httpx_client.request(
323
            "GET",
324
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "embed-jobs"),
325
            params=jsonable_encoder(
326
                request_options.get("additional_query_parameters") if request_options is not None else None
327
            ),
328
            headers=jsonable_encoder(
329
                remove_none_from_dict(
330
                    {
331
                        **self._client_wrapper.get_headers(),
332
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
333
                    }
334
                )
335
            ),
336
            timeout=request_options.get("timeout_in_seconds")
337
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
338
            else self._client_wrapper.get_timeout(),
339
            retries=0,
340
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
341
        )
342
        if 200 <= _response.status_code < 300:
343
            return pydantic.parse_obj_as(ListEmbedJobResponse, _response.json())  # type: ignore
344
        if _response.status_code == 400:
345
            raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
346
        if _response.status_code == 429:
347
            raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
348
        if _response.status_code == 500:
349
            raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
350
        try:
351
            _response_json = _response.json()
352
        except JSONDecodeError:
353
            raise ApiError(status_code=_response.status_code, body=_response.text)
354
        raise ApiError(status_code=_response.status_code, body=_response_json)
355

356
    async def create(
357
        self,
358
        *,
359
        model: str,
360
        dataset_id: str,
361
        input_type: EmbedInputType,
362
        name: typing.Optional[str] = OMIT,
363
        embedding_types: typing.Optional[typing.Sequence[EmbeddingType]] = OMIT,
364
        truncate: typing.Optional[CreateEmbedJobRequestTruncate] = OMIT,
365
        request_options: typing.Optional[RequestOptions] = None,
366
    ) -> CreateEmbedJobResponse:
367
        """
368
        This API launches an async Embed job for a [Dataset](https://docs.cohere.com/docs/datasets) of type `embed-input`. The result of a completed embed job is new Dataset of type `embed-output`, which contains the original text entries and the corresponding embeddings.
369

370
        Parameters:
371
            - model: str. ID of the embedding model.
372

373
                          Available models and corresponding embedding dimensions:
374

375
                          - `embed-english-v3.0` : 1024
376
                          - `embed-multilingual-v3.0` : 1024
377
                          - `embed-english-light-v3.0` : 384
378
                          - `embed-multilingual-light-v3.0` : 384
379

380
            - dataset_id: str. ID of a [Dataset](https://docs.cohere.com/docs/datasets). The Dataset must be of type `embed-input` and must have a validation status `Validated`
381

382
            - input_type: EmbedInputType.
383

384
            - name: typing.Optional[str]. The name of the embed job.
385

386
            - embedding_types: typing.Optional[typing.Sequence[EmbeddingType]]. Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types.
387

388
                                                                                * `"float"`: Use this when you want to get back the default float embeddings. Valid for all models.
389
                                                                                * `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
390
                                                                                * `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
391
                                                                                * `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models.
392
                                                                                * `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.
393
            - truncate: typing.Optional[CreateEmbedJobRequestTruncate]. One of `START|END` to specify how the API will handle inputs longer than the maximum token length.
394

395
                                                                        Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model.
396

397
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
398
        ---
399
        from cohere.client import AsyncClient
400

401
        client = AsyncClient(
402
            client_name="YOUR_CLIENT_NAME",
403
            token="YOUR_TOKEN",
404
        )
405
        await client.embed_jobs.create(
406
            model="model",
407
            dataset_id="dataset_id",
408
            input_type="search_document",
409
        )
410
        """
411
        _request: typing.Dict[str, typing.Any] = {"model": model, "dataset_id": dataset_id, "input_type": input_type}
412
        if name is not OMIT:
413
            _request["name"] = name
414
        if embedding_types is not OMIT:
415
            _request["embedding_types"] = embedding_types
416
        if truncate is not OMIT:
417
            _request["truncate"] = truncate
418
        _response = await self._client_wrapper.httpx_client.request(
419
            "POST",
420
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "embed-jobs"),
421
            params=jsonable_encoder(
422
                request_options.get("additional_query_parameters") if request_options is not None else None
423
            ),
424
            json=jsonable_encoder(_request)
425
            if request_options is None or request_options.get("additional_body_parameters") is None
426
            else {
427
                **jsonable_encoder(_request),
428
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
429
            },
430
            headers=jsonable_encoder(
431
                remove_none_from_dict(
432
                    {
433
                        **self._client_wrapper.get_headers(),
434
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
435
                    }
436
                )
437
            ),
438
            timeout=request_options.get("timeout_in_seconds")
439
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
440
            else self._client_wrapper.get_timeout(),
441
            retries=0,
442
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
443
        )
444
        if 200 <= _response.status_code < 300:
445
            return pydantic.parse_obj_as(CreateEmbedJobResponse, _response.json())  # type: ignore
446
        if _response.status_code == 400:
447
            raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
448
        if _response.status_code == 429:
449
            raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
450
        if _response.status_code == 500:
451
            raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
452
        try:
453
            _response_json = _response.json()
454
        except JSONDecodeError:
455
            raise ApiError(status_code=_response.status_code, body=_response.text)
456
        raise ApiError(status_code=_response.status_code, body=_response_json)
457

458
    async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EmbedJob:
459
        """
460
        This API retrieves the details about an embed job started by the same user.
461

462
        Parameters:
463
            - id: str. The ID of the embed job to retrieve.
464

465
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
466
        ---
467
        from cohere.client import AsyncClient
468

469
        client = AsyncClient(
470
            client_name="YOUR_CLIENT_NAME",
471
            token="YOUR_TOKEN",
472
        )
473
        await client.embed_jobs.get(
474
            id="id",
475
        )
476
        """
477
        _response = await self._client_wrapper.httpx_client.request(
478
            "GET",
479
            urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"embed-jobs/{jsonable_encoder(id)}"),
480
            params=jsonable_encoder(
481
                request_options.get("additional_query_parameters") if request_options is not None else None
482
            ),
483
            headers=jsonable_encoder(
484
                remove_none_from_dict(
485
                    {
486
                        **self._client_wrapper.get_headers(),
487
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
488
                    }
489
                )
490
            ),
491
            timeout=request_options.get("timeout_in_seconds")
492
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
493
            else self._client_wrapper.get_timeout(),
494
            retries=0,
495
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
496
        )
497
        if 200 <= _response.status_code < 300:
498
            return pydantic.parse_obj_as(EmbedJob, _response.json())  # type: ignore
499
        if _response.status_code == 400:
500
            raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
501
        if _response.status_code == 404:
502
            raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
503
        if _response.status_code == 429:
504
            raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
505
        if _response.status_code == 500:
506
            raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
507
        try:
508
            _response_json = _response.json()
509
        except JSONDecodeError:
510
            raise ApiError(status_code=_response.status_code, body=_response.text)
511
        raise ApiError(status_code=_response.status_code, body=_response_json)
512

513
    async def cancel(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
514
        """
515
        This API allows users to cancel an active embed job. Once invoked, the embedding process will be terminated, and users will be charged for the embeddings processed up to the cancellation point. It's important to note that partial results will not be available to users after cancellation.
516

517
        Parameters:
518
            - id: str. The ID of the embed job to cancel.
519

520
            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
521
        ---
522
        from cohere.client import AsyncClient
523

524
        client = AsyncClient(
525
            client_name="YOUR_CLIENT_NAME",
526
            token="YOUR_TOKEN",
527
        )
528
        await client.embed_jobs.cancel(
529
            id="id",
530
        )
531
        """
532
        _response = await self._client_wrapper.httpx_client.request(
533
            "POST",
534
            urllib.parse.urljoin(
535
                f"{self._client_wrapper.get_base_url()}/", f"embed-jobs/{jsonable_encoder(id)}/cancel"
536
            ),
537
            params=jsonable_encoder(
538
                request_options.get("additional_query_parameters") if request_options is not None else None
539
            ),
540
            json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))
541
            if request_options is not None
542
            else None,
543
            headers=jsonable_encoder(
544
                remove_none_from_dict(
545
                    {
546
                        **self._client_wrapper.get_headers(),
547
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
548
                    }
549
                )
550
            ),
551
            timeout=request_options.get("timeout_in_seconds")
552
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
553
            else self._client_wrapper.get_timeout(),
554
            retries=0,
555
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
556
        )
557
        if 200 <= _response.status_code < 300:
558
            return
559
        if _response.status_code == 400:
560
            raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
561
        if _response.status_code == 404:
562
            raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
563
        if _response.status_code == 429:
564
            raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
565
        if _response.status_code == 500:
566
            raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json()))  # type: ignore
567
        try:
568
            _response_json = _response.json()
569
        except JSONDecodeError:
570
            raise ApiError(status_code=_response.status_code, body=_response.text)
571
        raise ApiError(status_code=_response.status_code, body=_response_json)
572

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.