Skip to content

Commit 9abd212

Browse files
committed
Introduce models module and its client integration
1 parent 5c29a28 commit 9abd212

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

src/neuralaudio/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+

src/neuralaudio/models/client.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
from ..core.client_wrapper import SyncClientWrapper
4+
import typing
5+
from ..core.request_options import RequestOptions
6+
from ..types.model import Model
7+
from ..core.unchecked_base_model import construct_type
8+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
9+
from ..types.http_validation_error import HttpValidationError
10+
from json.decoder import JSONDecodeError
11+
from ..core.api_error import ApiError
12+
from ..core.client_wrapper import AsyncClientWrapper
13+
14+
15+
class ModelsClient:
16+
def __init__(self, *, client_wrapper: SyncClientWrapper):
17+
self._client_wrapper = client_wrapper
18+
19+
def get_all(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Model]:
20+
"""
21+
Gets a list of available models.
22+
23+
Parameters
24+
----------
25+
request_options : typing.Optional[RequestOptions]
26+
Request-specific configuration.
27+
28+
Returns
29+
-------
30+
typing.List[Model]
31+
Successful Response
32+
33+
Examples
34+
--------
35+
from neuralaudio import NeuralAudio
36+
37+
client = NeuralAudio(
38+
api_key="YOUR_API_KEY",
39+
)
40+
client.models.get_all()
41+
"""
42+
_response = self._client_wrapper.httpx_client.request(
43+
"v1/models",
44+
method="GET",
45+
request_options=request_options,
46+
)
47+
try:
48+
if 200 <= _response.status_code < 300:
49+
return typing.cast(
50+
typing.List[Model],
51+
construct_type(
52+
type_=typing.List[Model], # type: ignore
53+
object_=_response.json(),
54+
),
55+
)
56+
if _response.status_code == 422:
57+
raise UnprocessableEntityError(
58+
typing.cast(
59+
HttpValidationError,
60+
construct_type(
61+
type_=HttpValidationError, # type: ignore
62+
object_=_response.json(),
63+
),
64+
)
65+
)
66+
_response_json = _response.json()
67+
except JSONDecodeError:
68+
raise ApiError(status_code=_response.status_code, body=_response.text)
69+
raise ApiError(status_code=_response.status_code, body=_response_json)
70+
71+
72+
class AsyncModelsClient:
73+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
74+
self._client_wrapper = client_wrapper
75+
76+
async def get_all(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Model]:
77+
"""
78+
Gets a list of available models.
79+
80+
Parameters
81+
----------
82+
request_options : typing.Optional[RequestOptions]
83+
Request-specific configuration.
84+
85+
Returns
86+
-------
87+
typing.List[Model]
88+
Successful Response
89+
90+
Examples
91+
--------
92+
import asyncio
93+
94+
from neuralaudio import AsyncNeuralAudio
95+
96+
client = AsyncNeuralAudio(
97+
api_key="YOUR_API_KEY",
98+
)
99+
100+
101+
async def main() -> None:
102+
await client.models.get_all()
103+
104+
105+
asyncio.run(main())
106+
"""
107+
_response = await self._client_wrapper.httpx_client.request(
108+
"v1/models",
109+
method="GET",
110+
request_options=request_options,
111+
)
112+
try:
113+
if 200 <= _response.status_code < 300:
114+
return typing.cast(
115+
typing.List[Model],
116+
construct_type(
117+
type_=typing.List[Model], # type: ignore
118+
object_=_response.json(),
119+
),
120+
)
121+
if _response.status_code == 422:
122+
raise UnprocessableEntityError(
123+
typing.cast(
124+
HttpValidationError,
125+
construct_type(
126+
type_=HttpValidationError, # type: ignore
127+
object_=_response.json(),
128+
),
129+
)
130+
)
131+
_response_json = _response.json()
132+
except JSONDecodeError:
133+
raise ApiError(status_code=_response.status_code, body=_response.text)
134+
raise ApiError(status_code=_response.status_code, body=_response_json)

0 commit comments

Comments
 (0)