-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathapi.ts
More file actions
154 lines (145 loc) · 4.21 KB
/
Copy pathapi.ts
File metadata and controls
154 lines (145 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* Model deployment HTTP API wrappers.
*
* Thin functions over `requestJson`. They return the parsed body verbatim
* (snake_case) so callers can decide how to surface fields.
*/
import {
deploymentsPath,
deploymentPath,
deploymentScalePath,
deploymentUpdatePath,
deploymentsModelsPath,
} from "../client/endpoints.ts";
import type { Client } from "../client/client.ts";
import type {
CreateDeploymentRequest,
CreateDeploymentResponse,
ListDeploymentsResponse,
GetDeploymentResponse,
DeleteDeploymentResponse,
ListDeployableModelsResponse,
ScaleDeploymentRequest,
ScaleDeploymentResponse,
UpdateDeploymentRequest,
UpdateDeploymentResponse,
} from "./types.ts";
/** POST /api/v1/deployments */
export async function createDeployment(
client: Client,
body: CreateDeploymentRequest,
signal?: AbortSignal,
): Promise<CreateDeploymentResponse> {
return client.requestJson<CreateDeploymentResponse>({
path: deploymentsPath(),
method: "POST",
body,
signal,
});
}
export interface ListDeploymentsParams {
pageNo?: number;
pageSize?: number;
status?: string;
signal?: AbortSignal;
}
/** GET /api/v1/deployments */
export async function listDeployments(
client: Client,
params: ListDeploymentsParams = {},
): Promise<ListDeploymentsResponse> {
const qs = new URLSearchParams();
if (params.pageNo !== undefined) qs.set("page_no", String(params.pageNo));
if (params.pageSize !== undefined) qs.set("page_size", String(params.pageSize));
if (params.status) qs.set("status", params.status);
const base = deploymentsPath();
const path = qs.toString() ? `${base}?${qs.toString()}` : base;
return client.requestJson<ListDeploymentsResponse>({
path,
method: "GET",
signal: params.signal,
});
}
/** GET /api/v1/deployments/{deployed_model} */
export async function getDeployment(
client: Client,
deployedModel: string,
signal?: AbortSignal,
): Promise<GetDeploymentResponse> {
return client.requestJson<GetDeploymentResponse>({
path: deploymentPath(deployedModel),
method: "GET",
signal,
});
}
/** DELETE /api/v1/deployments/{deployed_model} */
export async function deleteDeployment(
client: Client,
deployedModel: string,
signal?: AbortSignal,
): Promise<DeleteDeploymentResponse> {
return client.requestJson<DeleteDeploymentResponse>({
path: deploymentPath(deployedModel),
method: "DELETE",
signal,
});
}
export interface ListDeployableModelsParams {
pageNo?: number;
pageSize?: number;
/** Catalog version filter, e.g. "v1.0". */
version?: string;
/** Source filter: "custom" (fine-tuned outputs) | "public" | …. */
modelSource?: string;
signal?: AbortSignal;
}
/** GET /api/v1/deployments/models */
export async function listDeployableModels(
client: Client,
params: ListDeployableModelsParams = {},
): Promise<ListDeployableModelsResponse> {
const qs = new URLSearchParams();
if (params.pageNo !== undefined) qs.set("page_no", String(params.pageNo));
if (params.pageSize !== undefined) qs.set("page_size", String(params.pageSize));
if (params.version) qs.set("version", params.version);
if (params.modelSource) qs.set("model_source", params.modelSource);
const base = deploymentsModelsPath();
const path = qs.toString() ? `${base}?${qs.toString()}` : base;
return client.requestJson<ListDeployableModelsResponse>({
path,
method: "GET",
signal: params.signal,
});
}
/** PUT /api/v1/deployments/{deployed_model}/scale */
export async function scaleDeployment(
client: Client,
deployedModel: string,
body: ScaleDeploymentRequest,
signal?: AbortSignal,
): Promise<ScaleDeploymentResponse> {
return client.requestJson<ScaleDeploymentResponse>({
path: deploymentScalePath(deployedModel),
method: "PUT",
body,
signal,
});
}
/**
* PUT /api/v1/deployments/{deployed_model}/update
*
* Update rate limits. At least one of `rpm_limit` / `tpm_limit` must be set.
*/
export async function updateDeployment(
client: Client,
deployedModel: string,
body: UpdateDeploymentRequest,
signal?: AbortSignal,
): Promise<UpdateDeploymentResponse> {
return client.requestJson<UpdateDeploymentResponse>({
path: deploymentUpdatePath(deployedModel),
method: "PUT",
body,
signal,
});
}