2023-10-17 15:35:56 -07:00
from typing import Any , Dict , Optional
2023-01-27 14:50:50 -08:00
import httpx
from . . . client import Client
2023-10-17 15:35:56 -07:00
from . . . models . ai_feedback import AiFeedback
2023-01-27 14:50:50 -08:00
from . . . models . error import Error
from . . . types import Response
2023-05-04 00:58:06 -07:00
2023-01-27 14:50:50 -08:00
def _get_kwargs (
2023-10-17 15:35:56 -07:00
id : str ,
feedback : AiFeedback ,
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-01-27 14:50:50 -08:00
) - > Dict [ str , Any ] :
2023-11-27 16:01:20 -08:00
url = " {} /user/text-to-cad/ {id} " . format (
client . base_url ,
id = id ,
) # noqa: E501
2023-10-17 15:35:56 -07:00
if feedback is not None :
2024-03-04 12:53:31 -08:00
2023-05-04 00:58:06 -07:00
if " ? " in url :
2023-10-17 15:35:56 -07:00
url = url + " &feedback= " + str ( feedback )
2023-05-04 00:58:06 -07:00
else :
2023-10-17 15:35:56 -07:00
url = url + " ?feedback= " + str ( feedback )
2023-05-04 00:58:06 -07:00
headers : Dict [ str , Any ] = client . get_headers ( )
cookies : Dict [ str , Any ] = client . get_cookies ( )
return {
" url " : url ,
" headers " : headers ,
" cookies " : cookies ,
" timeout " : client . get_timeout ( ) ,
}
2023-01-27 14:50:50 -08:00
2023-11-27 16:01:20 -08:00
def _parse_response ( * , response : httpx . Response ) - > Optional [ Error ] :
return None
if response . status_code == 400 :
2023-11-28 23:50:50 -08:00
response_4XX = Error ( * * response . json ( ) )
2023-11-27 16:01:20 -08:00
return response_4XX
if response . status_code == 500 :
2023-11-28 23:50:50 -08:00
response_5XX = Error ( * * response . json ( ) )
2023-11-27 16:01:20 -08:00
return response_5XX
2023-11-28 23:50:50 -08:00
return Error ( * * response . json ( ) )
2023-01-27 14:50:50 -08:00
2023-11-27 16:01:20 -08:00
def _build_response ( * , response : httpx . Response ) - > Response [ Optional [ 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-10-17 15:35:56 -07:00
id : str ,
feedback : AiFeedback ,
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-11-27 16:01:20 -08:00
) - > Response [ Optional [ Error ] ] :
2023-05-04 00:58:06 -07:00
kwargs = _get_kwargs (
2023-10-17 15:35:56 -07:00
id = id ,
feedback = feedback ,
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-10-17 15:35:56 -07:00
id : str ,
feedback : AiFeedback ,
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-11-27 16:01:20 -08:00
) - > Optional [ Error ] :
2023-12-21 08:14:08 -08:00
""" This endpoint requires authentication by any Zoo user. The user must be the owner of the text-to-CAD model, in order to give feedback. """ # noqa: E501
2023-01-27 14:50:50 -08:00
2023-05-04 00:58:06 -07:00
return sync_detailed (
2023-10-17 15:35:56 -07:00
id = id ,
feedback = feedback ,
2023-05-04 00:58:06 -07:00
client = client ,
) . parsed
2023-01-27 14:50:50 -08:00
async def asyncio_detailed (
2023-10-17 15:35:56 -07:00
id : str ,
feedback : AiFeedback ,
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-11-27 16:01:20 -08:00
) - > Response [ Optional [ Error ] ] :
2023-05-04 00:58:06 -07:00
kwargs = _get_kwargs (
2023-10-17 15:35:56 -07:00
id = id ,
feedback = feedback ,
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-10-17 15:35:56 -07:00
id : str ,
feedback : AiFeedback ,
2023-05-04 00:58:06 -07:00
* ,
client : Client ,
2023-11-27 16:01:20 -08:00
) - > Optional [ Error ] :
2023-12-21 08:14:08 -08:00
""" This endpoint requires authentication by any Zoo user. The user must be the owner of the text-to-CAD model, in order to give feedback. """ # noqa: E501
2023-05-04 00:58:06 -07:00
return (
await asyncio_detailed (
2023-10-17 15:35:56 -07:00
id = id ,
feedback = feedback ,
2023-05-04 00:58:06 -07:00
client = client ,
)
) . parsed