Download data/src/elevenlabs/flows/image/raw_client.py from introvoyz045/elevenlabs-python: direct link, hf CLI and curl.
- Browser
- Download file 16.1 kB
-
https://huggingface.co/datasets/introvoyz045/elevenlabs-python/resolve/main/data/src/elevenlabs/flows/image/raw_client.py
- Command line
-
hf download hf://datasets/introvoyz045/elevenlabs-python/data/src/elevenlabs/flows/image/raw_client.py
-
curl -L -o raw_client.py https://huggingface.co/datasets/introvoyz045/elevenlabs-python/resolve/main/data/src/elevenlabs/flows/image/raw_client.py
16.1 kB
| # This file was auto-generated by Fern from our API Definition. | |
| import typing | |
| from json.decoder import JSONDecodeError | |
| from ...core.api_error import ApiError | |
| from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper | |
| from ...core.http_response import AsyncHttpResponse, HttpResponse | |
| from ...core.jsonable_encoder import jsonable_encoder | |
| from ...core.parse_error import ParsingError | |
| from ...core.request_options import RequestOptions | |
| from ...core.serialization import convert_and_respect_annotation_metadata | |
| from ...core.unchecked_base_model import construct_type | |
| from ...errors.unprocessable_entity_error import UnprocessableEntityError | |
| from ...types.image_generation_request import ImageGenerationRequest | |
| from ...types.media_generation_create_response import MediaGenerationCreateResponse | |
| from ...types.media_generation_list_response import MediaGenerationListResponse | |
| from ...types.media_generation_response import MediaGenerationResponse | |
| from .types.image_list_request_status import ImageListRequestStatus | |
| from pydantic import ValidationError | |
| # this is used as the default value for optional parameters | |
| OMIT = typing.cast(typing.Any, ...) | |
| class RawImageClient: | |
| def __init__(self, *, client_wrapper: SyncClientWrapper): | |
| self._client_wrapper = client_wrapper | |
| def list( | |
| self, | |
| *, | |
| cursor: typing.Optional[str] = None, | |
| page_size: typing.Optional[int] = None, | |
| status: typing.Optional[ImageListRequestStatus] = None, | |
| model_id: typing.Optional[str] = None, | |
| request_options: typing.Optional[RequestOptions] = None, | |
| ) -> HttpResponse[MediaGenerationListResponse]: | |
| """ | |
| List the image generations created through this API, newest first. | |
| Parameters | |
| ---------- | |
| cursor : typing.Optional[str] | |
| Pagination cursor: the `next_cursor` value of the previous page's response. Omit it for the first page. | |
| page_size : typing.Optional[int] | |
| How many generations to return per page. | |
| status : typing.Optional[ImageListRequestStatus] | |
| Only return generations with this lifecycle status. | |
| model_id : typing.Optional[str] | |
| Only return generations of this model. | |
| request_options : typing.Optional[RequestOptions] | |
| Request-specific configuration. | |
| Returns | |
| ------- | |
| HttpResponse[MediaGenerationListResponse] | |
| Successful Response | |
| """ | |
| _response = self._client_wrapper.httpx_client.request( | |
| "v1/flows/image", | |
| method="GET", | |
| params={ | |
| "cursor": cursor, | |
| "page_size": page_size, | |
| "status": status, | |
| "model_id": model_id, | |
| }, | |
| request_options=request_options, | |
| ) | |
| try: | |
| if 200 <= _response.status_code < 300: | |
| _data = typing.cast( | |
| MediaGenerationListResponse, | |
| construct_type( | |
| type_=MediaGenerationListResponse, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ) | |
| return HttpResponse(response=_response, data=_data) | |
| if _response.status_code == 422: | |
| raise UnprocessableEntityError( | |
| headers=dict(_response.headers), | |
| body=typing.cast( | |
| typing.Any, | |
| construct_type( | |
| type_=typing.Any, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ), | |
| ) | |
| _response_json = _response.json() | |
| except JSONDecodeError: | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) | |
| except ValidationError as e: | |
| raise ParsingError( | |
| status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e | |
| ) | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) | |
| def create( | |
| self, *, request: ImageGenerationRequest, request_options: typing.Optional[RequestOptions] = None | |
| ) -> HttpResponse[MediaGenerationCreateResponse]: | |
| """ | |
| Start an image generation with the selected model. | |
| Parameters | |
| ---------- | |
| request : ImageGenerationRequest | |
| request_options : typing.Optional[RequestOptions] | |
| Request-specific configuration. | |
| Returns | |
| ------- | |
| HttpResponse[MediaGenerationCreateResponse] | |
| Successful Response | |
| """ | |
| _response = self._client_wrapper.httpx_client.request( | |
| "v1/flows/image", | |
| method="POST", | |
| json=convert_and_respect_annotation_metadata( | |
| object_=request, annotation=ImageGenerationRequest, direction="write" | |
| ), | |
| request_options=request_options, | |
| omit=OMIT, | |
| ) | |
| try: | |
| if 200 <= _response.status_code < 300: | |
| _data = typing.cast( | |
| MediaGenerationCreateResponse, | |
| construct_type( | |
| type_=MediaGenerationCreateResponse, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ) | |
| return HttpResponse(response=_response, data=_data) | |
| if _response.status_code == 422: | |
| raise UnprocessableEntityError( | |
| headers=dict(_response.headers), | |
| body=typing.cast( | |
| typing.Any, | |
| construct_type( | |
| type_=typing.Any, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ), | |
| ) | |
| _response_json = _response.json() | |
| except JSONDecodeError: | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) | |
| except ValidationError as e: | |
| raise ParsingError( | |
| status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e | |
| ) | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) | |
| def get( | |
| self, generation_id: str, *, request_options: typing.Optional[RequestOptions] = None | |
| ) -> HttpResponse[MediaGenerationResponse]: | |
| """ | |
| Retrieve the status of an image generation, and retrieve its output URL once completed. | |
| Parameters | |
| ---------- | |
| generation_id : str | |
| request_options : typing.Optional[RequestOptions] | |
| Request-specific configuration. | |
| Returns | |
| ------- | |
| HttpResponse[MediaGenerationResponse] | |
| Successful Response | |
| """ | |
| _response = self._client_wrapper.httpx_client.request( | |
| f"v1/flows/image/{jsonable_encoder(generation_id)}", | |
| method="GET", | |
| request_options=request_options, | |
| ) | |
| try: | |
| if 200 <= _response.status_code < 300: | |
| _data = typing.cast( | |
| MediaGenerationResponse, | |
| construct_type( | |
| type_=MediaGenerationResponse, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ) | |
| return HttpResponse(response=_response, data=_data) | |
| if _response.status_code == 422: | |
| raise UnprocessableEntityError( | |
| headers=dict(_response.headers), | |
| body=typing.cast( | |
| typing.Any, | |
| construct_type( | |
| type_=typing.Any, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ), | |
| ) | |
| _response_json = _response.json() | |
| except JSONDecodeError: | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) | |
| except ValidationError as e: | |
| raise ParsingError( | |
| status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e | |
| ) | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) | |
| class AsyncRawImageClient: | |
| def __init__(self, *, client_wrapper: AsyncClientWrapper): | |
| self._client_wrapper = client_wrapper | |
| async def list( | |
| self, | |
| *, | |
| cursor: typing.Optional[str] = None, | |
| page_size: typing.Optional[int] = None, | |
| status: typing.Optional[ImageListRequestStatus] = None, | |
| model_id: typing.Optional[str] = None, | |
| request_options: typing.Optional[RequestOptions] = None, | |
| ) -> AsyncHttpResponse[MediaGenerationListResponse]: | |
| """ | |
| List the image generations created through this API, newest first. | |
| Parameters | |
| ---------- | |
| cursor : typing.Optional[str] | |
| Pagination cursor: the `next_cursor` value of the previous page's response. Omit it for the first page. | |
| page_size : typing.Optional[int] | |
| How many generations to return per page. | |
| status : typing.Optional[ImageListRequestStatus] | |
| Only return generations with this lifecycle status. | |
| model_id : typing.Optional[str] | |
| Only return generations of this model. | |
| request_options : typing.Optional[RequestOptions] | |
| Request-specific configuration. | |
| Returns | |
| ------- | |
| AsyncHttpResponse[MediaGenerationListResponse] | |
| Successful Response | |
| """ | |
| _response = await self._client_wrapper.httpx_client.request( | |
| "v1/flows/image", | |
| method="GET", | |
| params={ | |
| "cursor": cursor, | |
| "page_size": page_size, | |
| "status": status, | |
| "model_id": model_id, | |
| }, | |
| request_options=request_options, | |
| ) | |
| try: | |
| if 200 <= _response.status_code < 300: | |
| _data = typing.cast( | |
| MediaGenerationListResponse, | |
| construct_type( | |
| type_=MediaGenerationListResponse, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ) | |
| return AsyncHttpResponse(response=_response, data=_data) | |
| if _response.status_code == 422: | |
| raise UnprocessableEntityError( | |
| headers=dict(_response.headers), | |
| body=typing.cast( | |
| typing.Any, | |
| construct_type( | |
| type_=typing.Any, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ), | |
| ) | |
| _response_json = _response.json() | |
| except JSONDecodeError: | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) | |
| except ValidationError as e: | |
| raise ParsingError( | |
| status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e | |
| ) | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) | |
| async def create( | |
| self, *, request: ImageGenerationRequest, request_options: typing.Optional[RequestOptions] = None | |
| ) -> AsyncHttpResponse[MediaGenerationCreateResponse]: | |
| """ | |
| Start an image generation with the selected model. | |
| Parameters | |
| ---------- | |
| request : ImageGenerationRequest | |
| request_options : typing.Optional[RequestOptions] | |
| Request-specific configuration. | |
| Returns | |
| ------- | |
| AsyncHttpResponse[MediaGenerationCreateResponse] | |
| Successful Response | |
| """ | |
| _response = await self._client_wrapper.httpx_client.request( | |
| "v1/flows/image", | |
| method="POST", | |
| json=convert_and_respect_annotation_metadata( | |
| object_=request, annotation=ImageGenerationRequest, direction="write" | |
| ), | |
| request_options=request_options, | |
| omit=OMIT, | |
| ) | |
| try: | |
| if 200 <= _response.status_code < 300: | |
| _data = typing.cast( | |
| MediaGenerationCreateResponse, | |
| construct_type( | |
| type_=MediaGenerationCreateResponse, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ) | |
| return AsyncHttpResponse(response=_response, data=_data) | |
| if _response.status_code == 422: | |
| raise UnprocessableEntityError( | |
| headers=dict(_response.headers), | |
| body=typing.cast( | |
| typing.Any, | |
| construct_type( | |
| type_=typing.Any, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ), | |
| ) | |
| _response_json = _response.json() | |
| except JSONDecodeError: | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) | |
| except ValidationError as e: | |
| raise ParsingError( | |
| status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e | |
| ) | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) | |
| async def get( | |
| self, generation_id: str, *, request_options: typing.Optional[RequestOptions] = None | |
| ) -> AsyncHttpResponse[MediaGenerationResponse]: | |
| """ | |
| Retrieve the status of an image generation, and retrieve its output URL once completed. | |
| Parameters | |
| ---------- | |
| generation_id : str | |
| request_options : typing.Optional[RequestOptions] | |
| Request-specific configuration. | |
| Returns | |
| ------- | |
| AsyncHttpResponse[MediaGenerationResponse] | |
| Successful Response | |
| """ | |
| _response = await self._client_wrapper.httpx_client.request( | |
| f"v1/flows/image/{jsonable_encoder(generation_id)}", | |
| method="GET", | |
| request_options=request_options, | |
| ) | |
| try: | |
| if 200 <= _response.status_code < 300: | |
| _data = typing.cast( | |
| MediaGenerationResponse, | |
| construct_type( | |
| type_=MediaGenerationResponse, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ) | |
| return AsyncHttpResponse(response=_response, data=_data) | |
| if _response.status_code == 422: | |
| raise UnprocessableEntityError( | |
| headers=dict(_response.headers), | |
| body=typing.cast( | |
| typing.Any, | |
| construct_type( | |
| type_=typing.Any, # type: ignore | |
| object_=_response.json(), | |
| ), | |
| ), | |
| ) | |
| _response_json = _response.json() | |
| except JSONDecodeError: | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) | |
| except ValidationError as e: | |
| raise ParsingError( | |
| status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e | |
| ) | |
| raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) | |