Skip to content

Commit a7fd417

Browse files
authored
feat(inference): add support v1 (#1906)
1 parent 5a8f85e commit a7fd417

File tree

6 files changed

+1319
-0
lines changed

6 files changed

+1319
-0
lines changed
Lines changed: 372 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,372 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
API as ParentAPI,
5+
enrichForPagination,
6+
urlParams,
7+
validatePathParam,
8+
waitForResource,
9+
} from '../../../bridge'
10+
import type { Region as ScwRegion, WaitForOptions } from '../../../bridge'
11+
import {
12+
DEPLOYMENT_TRANSIENT_STATUSES,
13+
MODEL_TRANSIENT_STATUSES,
14+
} from './content.gen'
15+
import {
16+
marshalCreateDeploymentRequest,
17+
marshalCreateEndpointRequest,
18+
marshalCreateModelRequest,
19+
marshalUpdateDeploymentRequest,
20+
marshalUpdateEndpointRequest,
21+
unmarshalDeployment,
22+
unmarshalEndpoint,
23+
unmarshalListDeploymentsResponse,
24+
unmarshalListModelsResponse,
25+
unmarshalListNodeTypesResponse,
26+
unmarshalModel,
27+
} from './marshalling.gen'
28+
import type {
29+
CreateDeploymentRequest,
30+
CreateEndpointRequest,
31+
CreateModelRequest,
32+
DeleteDeploymentRequest,
33+
DeleteEndpointRequest,
34+
DeleteModelRequest,
35+
Deployment,
36+
Endpoint,
37+
GetDeploymentCertificateRequest,
38+
GetDeploymentRequest,
39+
GetModelRequest,
40+
ListDeploymentsRequest,
41+
ListDeploymentsResponse,
42+
ListModelsRequest,
43+
ListModelsResponse,
44+
ListNodeTypesRequest,
45+
ListNodeTypesResponse,
46+
Model,
47+
UpdateDeploymentRequest,
48+
UpdateEndpointRequest,
49+
} from './types.gen'
50+
51+
const jsonContentHeaders = {
52+
'Content-Type': 'application/json; charset=utf-8',
53+
}
54+
55+
/**
56+
* Managed Inference API.
57+
*
58+
* This API allows you to handle your Managed Inference services.
59+
*/
60+
export class API extends ParentAPI {
61+
/** Lists the available regions of the API. */
62+
public static readonly LOCALITIES: ScwRegion[] = ['fr-par']
63+
64+
protected pageOfListDeployments = (
65+
request: Readonly<ListDeploymentsRequest> = {},
66+
) =>
67+
this.client.fetch<ListDeploymentsResponse>(
68+
{
69+
method: 'GET',
70+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/deployments`,
71+
urlParams: urlParams(
72+
['name', request.name],
73+
['order_by', request.orderBy],
74+
['organization_id', request.organizationId],
75+
['page', request.page],
76+
[
77+
'page_size',
78+
request.pageSize ?? this.client.settings.defaultPageSize,
79+
],
80+
['project_id', request.projectId],
81+
['tags', request.tags],
82+
),
83+
},
84+
unmarshalListDeploymentsResponse,
85+
)
86+
87+
/**
88+
* List inference deployments. List all your inference deployments.
89+
*
90+
* @param request - The request {@link ListDeploymentsRequest}
91+
* @returns A Promise of ListDeploymentsResponse
92+
*/
93+
listDeployments = (request: Readonly<ListDeploymentsRequest> = {}) =>
94+
enrichForPagination('deployments', this.pageOfListDeployments, request)
95+
96+
/**
97+
* Get a deployment. Get the deployment for the given ID.
98+
*
99+
* @param request - The request {@link GetDeploymentRequest}
100+
* @returns A Promise of Deployment
101+
*/
102+
getDeployment = (request: Readonly<GetDeploymentRequest>) =>
103+
this.client.fetch<Deployment>(
104+
{
105+
method: 'GET',
106+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/deployments/${validatePathParam('deploymentId', request.deploymentId)}`,
107+
},
108+
unmarshalDeployment,
109+
)
110+
111+
/**
112+
* Waits for {@link Deployment} to be in a final state.
113+
*
114+
* @param request - The request {@link GetDeploymentRequest}
115+
* @param options - The waiting options
116+
* @returns A Promise of Deployment
117+
*/
118+
waitForDeployment = (
119+
request: Readonly<GetDeploymentRequest>,
120+
options?: Readonly<WaitForOptions<Deployment>>,
121+
) =>
122+
waitForResource(
123+
options?.stop ??
124+
(res =>
125+
Promise.resolve(!DEPLOYMENT_TRANSIENT_STATUSES.includes(res.status))),
126+
this.getDeployment,
127+
request,
128+
options,
129+
)
130+
131+
/**
132+
* Create a deployment. Create a new inference deployment related to a
133+
* specific model.
134+
*
135+
* @param request - The request {@link CreateDeploymentRequest}
136+
* @returns A Promise of Deployment
137+
*/
138+
createDeployment = (request: Readonly<CreateDeploymentRequest>) =>
139+
this.client.fetch<Deployment>(
140+
{
141+
body: JSON.stringify(
142+
marshalCreateDeploymentRequest(request, this.client.settings),
143+
),
144+
headers: jsonContentHeaders,
145+
method: 'POST',
146+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/deployments`,
147+
},
148+
unmarshalDeployment,
149+
)
150+
151+
/**
152+
* Update a deployment. Update an existing inference deployment.
153+
*
154+
* @param request - The request {@link UpdateDeploymentRequest}
155+
* @returns A Promise of Deployment
156+
*/
157+
updateDeployment = (request: Readonly<UpdateDeploymentRequest>) =>
158+
this.client.fetch<Deployment>(
159+
{
160+
body: JSON.stringify(
161+
marshalUpdateDeploymentRequest(request, this.client.settings),
162+
),
163+
headers: jsonContentHeaders,
164+
method: 'PATCH',
165+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/deployments/${validatePathParam('deploymentId', request.deploymentId)}`,
166+
},
167+
unmarshalDeployment,
168+
)
169+
170+
/**
171+
* Delete a deployment. Delete an existing inference deployment.
172+
*
173+
* @param request - The request {@link DeleteDeploymentRequest}
174+
* @returns A Promise of Deployment
175+
*/
176+
deleteDeployment = (request: Readonly<DeleteDeploymentRequest>) =>
177+
this.client.fetch<Deployment>(
178+
{
179+
method: 'DELETE',
180+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/deployments/${validatePathParam('deploymentId', request.deploymentId)}`,
181+
},
182+
unmarshalDeployment,
183+
)
184+
185+
/**
186+
* Get the CA certificate. Get the CA certificate used for the deployment of
187+
* private endpoints. The CA certificate will be returned as a PEM file.
188+
*
189+
* @param request - The request {@link GetDeploymentCertificateRequest}
190+
* @returns A Promise of Blob
191+
*/
192+
getDeploymentCertificate = (
193+
request: Readonly<GetDeploymentCertificateRequest>,
194+
) =>
195+
this.client.fetch<Blob>({
196+
method: 'GET',
197+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/deployments/${validatePathParam('deploymentId', request.deploymentId)}/certificate`,
198+
urlParams: urlParams(['dl', 1]),
199+
responseType: 'blob',
200+
})
201+
202+
/**
203+
* Create an endpoint. Create a new Endpoint related to a specific deployment.
204+
*
205+
* @param request - The request {@link CreateEndpointRequest}
206+
* @returns A Promise of Endpoint
207+
*/
208+
createEndpoint = (request: Readonly<CreateEndpointRequest>) =>
209+
this.client.fetch<Endpoint>(
210+
{
211+
body: JSON.stringify(
212+
marshalCreateEndpointRequest(request, this.client.settings),
213+
),
214+
headers: jsonContentHeaders,
215+
method: 'POST',
216+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/endpoints`,
217+
},
218+
unmarshalEndpoint,
219+
)
220+
221+
/**
222+
* Update an endpoint. Update an existing Endpoint.
223+
*
224+
* @param request - The request {@link UpdateEndpointRequest}
225+
* @returns A Promise of Endpoint
226+
*/
227+
updateEndpoint = (request: Readonly<UpdateEndpointRequest>) =>
228+
this.client.fetch<Endpoint>(
229+
{
230+
body: JSON.stringify(
231+
marshalUpdateEndpointRequest(request, this.client.settings),
232+
),
233+
headers: jsonContentHeaders,
234+
method: 'PATCH',
235+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/endpoints/${validatePathParam('endpointId', request.endpointId)}`,
236+
},
237+
unmarshalEndpoint,
238+
)
239+
240+
/**
241+
* Delete an endpoint. Delete an existing Endpoint.
242+
*
243+
* @param request - The request {@link DeleteEndpointRequest}
244+
*/
245+
deleteEndpoint = (request: Readonly<DeleteEndpointRequest>) =>
246+
this.client.fetch<void>({
247+
method: 'DELETE',
248+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/endpoints/${validatePathParam('endpointId', request.endpointId)}`,
249+
})
250+
251+
protected pageOfListModels = (request: Readonly<ListModelsRequest> = {}) =>
252+
this.client.fetch<ListModelsResponse>(
253+
{
254+
method: 'GET',
255+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/models`,
256+
urlParams: urlParams(
257+
['name', request.name],
258+
['order_by', request.orderBy],
259+
['page', request.page],
260+
[
261+
'page_size',
262+
request.pageSize ?? this.client.settings.defaultPageSize,
263+
],
264+
['project_id', request.projectId],
265+
['tags', request.tags],
266+
),
267+
},
268+
unmarshalListModelsResponse,
269+
)
270+
271+
/**
272+
* List models. List all available models.
273+
*
274+
* @param request - The request {@link ListModelsRequest}
275+
* @returns A Promise of ListModelsResponse
276+
*/
277+
listModels = (request: Readonly<ListModelsRequest> = {}) =>
278+
enrichForPagination('models', this.pageOfListModels, request)
279+
280+
/**
281+
* Get a model. Get the model for the given ID.
282+
*
283+
* @param request - The request {@link GetModelRequest}
284+
* @returns A Promise of Model
285+
*/
286+
getModel = (request: Readonly<GetModelRequest>) =>
287+
this.client.fetch<Model>(
288+
{
289+
method: 'GET',
290+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/models/${validatePathParam('modelId', request.modelId)}`,
291+
},
292+
unmarshalModel,
293+
)
294+
295+
/**
296+
* Waits for {@link Model} to be in a final state.
297+
*
298+
* @param request - The request {@link GetModelRequest}
299+
* @param options - The waiting options
300+
* @returns A Promise of Model
301+
*/
302+
waitForModel = (
303+
request: Readonly<GetModelRequest>,
304+
options?: Readonly<WaitForOptions<Model>>,
305+
) =>
306+
waitForResource(
307+
options?.stop ??
308+
(res =>
309+
Promise.resolve(!MODEL_TRANSIENT_STATUSES.includes(res.status))),
310+
this.getModel,
311+
request,
312+
options,
313+
)
314+
315+
/**
316+
* Import a model. Import a new model to your model library.
317+
*
318+
* @param request - The request {@link CreateModelRequest}
319+
* @returns A Promise of Model
320+
*/
321+
createModel = (request: Readonly<CreateModelRequest>) =>
322+
this.client.fetch<Model>(
323+
{
324+
body: JSON.stringify(
325+
marshalCreateModelRequest(request, this.client.settings),
326+
),
327+
headers: jsonContentHeaders,
328+
method: 'POST',
329+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/models`,
330+
},
331+
unmarshalModel,
332+
)
333+
334+
/**
335+
* Delete a model. Delete an existing model from your model library.
336+
*
337+
* @param request - The request {@link DeleteModelRequest}
338+
*/
339+
deleteModel = (request: Readonly<DeleteModelRequest>) =>
340+
this.client.fetch<void>({
341+
method: 'DELETE',
342+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/models/${validatePathParam('modelId', request.modelId)}`,
343+
})
344+
345+
protected pageOfListNodeTypes = (request: Readonly<ListNodeTypesRequest>) =>
346+
this.client.fetch<ListNodeTypesResponse>(
347+
{
348+
method: 'GET',
349+
path: `/inference/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/node-types`,
350+
urlParams: urlParams(
351+
['include_disabled_types', request.includeDisabledTypes],
352+
['page', request.page],
353+
[
354+
'page_size',
355+
request.pageSize ?? this.client.settings.defaultPageSize,
356+
],
357+
),
358+
},
359+
unmarshalListNodeTypesResponse,
360+
)
361+
362+
/**
363+
* List available node types. List all available node types. By default, the
364+
* node types returned in the list are ordered by creation date in ascending
365+
* order, though this can be modified via the `order_by` field.
366+
*
367+
* @param request - The request {@link ListNodeTypesRequest}
368+
* @returns A Promise of ListNodeTypesResponse
369+
*/
370+
listNodeTypes = (request: Readonly<ListNodeTypesRequest>) =>
371+
enrichForPagination('nodeTypes', this.pageOfListNodeTypes, request)
372+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import type { DeploymentStatus, ModelStatus } from './types.gen'
4+
5+
/** Lists transient statutes of the enum {@link DeploymentStatus}. */
6+
export const DEPLOYMENT_TRANSIENT_STATUSES: DeploymentStatus[] = [
7+
'creating',
8+
'deploying',
9+
'deleting',
10+
]
11+
12+
/** Lists transient statutes of the enum {@link ModelStatus}. */
13+
export const MODEL_TRANSIENT_STATUSES: ModelStatus[] = [
14+
'preparing',
15+
'downloading',
16+
]

0 commit comments

Comments
 (0)