|
11 | 11 | from json.decoder import JSONDecodeError
|
12 | 12 | from ..core.api_error import ApiError
|
13 | 13 | from ..types.parse_response import ParseResponse
|
| 14 | +from ..types.extract_constants_response import ExtractConstantsResponse |
14 | 15 | from ..core.client_wrapper import AsyncClientWrapper
|
15 | 16 |
|
16 | 17 | # this is used as the default value for optional parameters
|
@@ -175,6 +176,69 @@ def parse(
|
175 | 176 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
176 | 177 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
177 | 178 |
|
| 179 | + def constants( |
| 180 | + self, |
| 181 | + *, |
| 182 | + file: core.File, |
| 183 | + constants: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, |
| 184 | + request_options: typing.Optional[RequestOptions] = None, |
| 185 | + ) -> ExtractConstantsResponse: |
| 186 | + """ |
| 187 | + Extracts specific constants from documents |
| 188 | +
|
| 189 | + Parameters |
| 190 | + ---------- |
| 191 | + file : core.File |
| 192 | + See core.File for more documentation |
| 193 | +
|
| 194 | + constants : typing.Optional[typing.Union[str, typing.Sequence[str]]] |
| 195 | + List of constants to extract |
| 196 | +
|
| 197 | + request_options : typing.Optional[RequestOptions] |
| 198 | + Request-specific configuration. |
| 199 | +
|
| 200 | + Returns |
| 201 | + ------- |
| 202 | + ExtractConstantsResponse |
| 203 | + Successful Response |
| 204 | + """ |
| 205 | + _response = self._client_wrapper.httpx_client.request( |
| 206 | + "document/constants", |
| 207 | + method="POST", |
| 208 | + params={ |
| 209 | + "constants": constants, |
| 210 | + }, |
| 211 | + data={}, |
| 212 | + files={ |
| 213 | + "file": file, |
| 214 | + }, |
| 215 | + request_options=request_options, |
| 216 | + omit=OMIT, |
| 217 | + ) |
| 218 | + try: |
| 219 | + if 200 <= _response.status_code < 300: |
| 220 | + return typing.cast( |
| 221 | + ExtractConstantsResponse, |
| 222 | + parse_obj_as( |
| 223 | + type_=ExtractConstantsResponse, # type: ignore |
| 224 | + object_=_response.json(), |
| 225 | + ), |
| 226 | + ) |
| 227 | + if _response.status_code == 422: |
| 228 | + raise UnprocessableEntityError( |
| 229 | + typing.cast( |
| 230 | + HttpValidationError, |
| 231 | + parse_obj_as( |
| 232 | + type_=HttpValidationError, # type: ignore |
| 233 | + object_=_response.json(), |
| 234 | + ), |
| 235 | + ) |
| 236 | + ) |
| 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 | + |
178 | 242 |
|
179 | 243 | class AsyncDocumentClient:
|
180 | 244 | def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
@@ -349,3 +413,66 @@ async def main() -> None:
|
349 | 413 | except JSONDecodeError:
|
350 | 414 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
351 | 415 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
| 416 | + |
| 417 | + async def constants( |
| 418 | + self, |
| 419 | + *, |
| 420 | + file: core.File, |
| 421 | + constants: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, |
| 422 | + request_options: typing.Optional[RequestOptions] = None, |
| 423 | + ) -> ExtractConstantsResponse: |
| 424 | + """ |
| 425 | + Extracts specific constants from documents |
| 426 | +
|
| 427 | + Parameters |
| 428 | + ---------- |
| 429 | + file : core.File |
| 430 | + See core.File for more documentation |
| 431 | +
|
| 432 | + constants : typing.Optional[typing.Union[str, typing.Sequence[str]]] |
| 433 | + List of constants to extract |
| 434 | +
|
| 435 | + request_options : typing.Optional[RequestOptions] |
| 436 | + Request-specific configuration. |
| 437 | +
|
| 438 | + Returns |
| 439 | + ------- |
| 440 | + ExtractConstantsResponse |
| 441 | + Successful Response |
| 442 | + """ |
| 443 | + _response = await self._client_wrapper.httpx_client.request( |
| 444 | + "document/constants", |
| 445 | + method="POST", |
| 446 | + params={ |
| 447 | + "constants": constants, |
| 448 | + }, |
| 449 | + data={}, |
| 450 | + files={ |
| 451 | + "file": file, |
| 452 | + }, |
| 453 | + request_options=request_options, |
| 454 | + omit=OMIT, |
| 455 | + ) |
| 456 | + try: |
| 457 | + if 200 <= _response.status_code < 300: |
| 458 | + return typing.cast( |
| 459 | + ExtractConstantsResponse, |
| 460 | + parse_obj_as( |
| 461 | + type_=ExtractConstantsResponse, # type: ignore |
| 462 | + object_=_response.json(), |
| 463 | + ), |
| 464 | + ) |
| 465 | + if _response.status_code == 422: |
| 466 | + raise UnprocessableEntityError( |
| 467 | + typing.cast( |
| 468 | + HttpValidationError, |
| 469 | + parse_obj_as( |
| 470 | + type_=HttpValidationError, # type: ignore |
| 471 | + object_=_response.json(), |
| 472 | + ), |
| 473 | + ) |
| 474 | + ) |
| 475 | + _response_json = _response.json() |
| 476 | + except JSONDecodeError: |
| 477 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 478 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
0 commit comments