2023-05-04 00:58:06 -07:00
from typing import Any , Dict , Optional , Union
2023-01-27 14:50:50 -08:00
import httpx
from . . . client import Client
from . . . models . error import Error
from . . . models . file_export_format import FileExportFormat
2023-10-17 15:35:56 -07:00
from . . . models . text_to_cad import TextToCad
from . . . models . text_to_cad_create_body import TextToCadCreateBody
2023-01-27 14:50:50 -08:00
from . . . types import Response
2023-05-04 00:58:06 -07:00
2023-01-27 14:50:50 -08:00
def _get_kwargs (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format : FileExportFormat ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
body : TextToCadCreateBody ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-09-29 16:05:40 -07:00
2023-01-27 14:50:50 -08:00
) - > Dict [ str , Any ] :
2023-10-17 15:35:56 -07:00
url = " {} /ai/text-to-cad/ {output_format} " . format ( client . base_url , output_format = output_format , ) # noqa: E501
2023-09-29 16:05:40 -07:00
2023-01-27 14:50:50 -08:00
2023-05-04 00:58:06 -07:00
headers : Dict [ str , Any ] = client . get_headers ( )
cookies : Dict [ str , Any ] = client . get_cookies ( )
2023-01-27 14:50:50 -08:00
2023-05-04 00:58:06 -07:00
return {
" url " : url ,
" headers " : headers ,
" cookies " : cookies ,
" timeout " : client . get_timeout ( ) ,
" content " : body ,
}
2023-01-27 14:50:50 -08:00
2023-10-17 15:35:56 -07:00
def _parse_response ( * , response : httpx . Response ) - > Optional [ Union [ TextToCad , Error ] ] :
if response . status_code == 201 :
response_201 = TextToCad . from_dict ( response . json ( ) )
return response_201
2023-09-29 16:05:40 -07:00
if response . status_code == 400 :
response_4XX = Error . from_dict ( response . json ( ) )
return response_4XX
if response . status_code == 500 :
response_5XX = Error . from_dict ( response . json ( ) )
return response_5XX
return Error . from_dict ( response . json ( ) )
2023-01-27 14:50:50 -08:00
2023-05-08 12:58:35 -07:00
def _build_response (
* , response : httpx . Response
2023-10-17 15:35:56 -07:00
) - > Response [ Optional [ Union [ TextToCad , Error ] ] ] :
2023-05-04 00:58:06 -07:00
return Response (
status_code = response . status_code ,
content = response . content ,
headers = response . headers ,
parsed = _parse_response ( response = response ) ,
)
2023-01-27 14:50:50 -08:00
def sync_detailed (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format : FileExportFormat ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
body : TextToCadCreateBody ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
) - > Response [ Optional [ Union [ TextToCad , Error ] ] ] :
2023-05-04 00:58:06 -07:00
kwargs = _get_kwargs (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format = output_format ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
body = body ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
client = client ,
)
2023-01-27 14:50:50 -08:00
2023-05-04 00:58:06 -07:00
response = httpx . post (
verify = client . verify_ssl ,
* * kwargs ,
)
2023-01-27 14:50:50 -08:00
2023-05-04 00:58:06 -07:00
return _build_response ( response = response )
2023-01-27 14:50:50 -08:00
def sync (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format : FileExportFormat ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
body : TextToCadCreateBody ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
) - > Optional [ Union [ TextToCad , Error ] ] :
""" This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/ {id} ` endpoint.
This is an alpha endpoint . It will change in the future . The current output is honestly pretty bad . So if you find this endpoint , you get what you pay for , which currently is nothing . But in the future will be made a lot better . """ # noqa: E501
2023-01-27 14:50:50 -08:00
2023-05-04 00:58:06 -07:00
return sync_detailed (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format = output_format ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
body = body ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
client = client ,
) . parsed
2023-01-27 14:50:50 -08:00
async def asyncio_detailed (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format : FileExportFormat ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
body : TextToCadCreateBody ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
) - > Response [ Optional [ Union [ TextToCad , Error ] ] ] :
2023-05-04 00:58:06 -07:00
kwargs = _get_kwargs (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format = output_format ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
body = body ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
client = client ,
)
2023-01-27 14:50:50 -08:00
2023-05-04 00:58:06 -07:00
async with httpx . AsyncClient ( verify = client . verify_ssl ) as _client :
response = await _client . post ( * * kwargs )
2023-01-27 14:50:50 -08:00
2023-05-04 00:58:06 -07:00
return _build_response ( response = response )
2023-01-27 14:50:50 -08:00
async def asyncio (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format : FileExportFormat ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
body : TextToCadCreateBody ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-09-29 16:05:40 -07:00
2023-10-17 15:35:56 -07:00
) - > Optional [ Union [ TextToCad , Error ] ] :
""" This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/ {id} ` endpoint.
This is an alpha endpoint . It will change in the future . The current output is honestly pretty bad . So if you find this endpoint , you get what you pay for , which currently is nothing . But in the future will be made a lot better . """ # noqa: E501
2023-05-04 00:58:06 -07:00
return (
await asyncio_detailed (
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
output_format = output_format ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
body = body ,
2023-09-29 16:05:40 -07:00
2023-05-04 00:58:06 -07:00
client = client ,
)
) . parsed