Skip to content

Commit 216e2e8

Browse files
committed
Add support for new deployment endpoints
1 parent 20983bc commit 216e2e8

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

index.d.ts

+19
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,25 @@ declare module "replicate" {
194194
deployment_owner: string,
195195
deployment_name: string
196196
): Promise<Deployment>;
197+
create(deployment_config: {
198+
name: string;
199+
model: string;
200+
version: string;
201+
hardware: string;
202+
min_instances: number;
203+
max_instances: number;
204+
}): Promise<Deployment>;
205+
update(
206+
deployment_owner: string,
207+
deployment_name: string,
208+
deployment_config: {
209+
version: string;
210+
hardware: string;
211+
min_instances: number;
212+
max_instances: number;
213+
}
214+
): Promise<Deployment>;
215+
list(): Promise<Page<Deployment>>;
197216
};
198217

199218
hardware: {

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class Replicate {
6666

6767
this.deployments = {
6868
get: deployments.get.bind(this),
69+
create: deployments.create.bind(this),
70+
update: deployments.update.bind(this),
71+
list: deployments.list.bind(this),
6972
predictions: {
7073
create: deployments.predictions.create.bind(this),
7174
},

lib/deployments.js

+73
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,82 @@ async function getDeployment(deployment_owner, deployment_name) {
5757
return response.json();
5858
}
5959

60+
/**
61+
* @typedef {Object} DeploymentCreateRequest - Request body for `deployments.create`
62+
* @property {string} name - the name of the deployment
63+
* @property {string} model - the full name of the model that you want to deploy e.g. stability-ai/sdxl
64+
* @property {string} version - the 64-character string ID of the model version that you want to deploy
65+
* @property {string} hardware - the SKU for the hardware used to run the model, via `replicate.hardware.list()`
66+
* @property {number} min_instances - the minimum number of instances for scaling
67+
* @property {number} max_instances - the maximum number of instances for scaling
68+
*/
69+
70+
/**
71+
* Create a deployment
72+
*
73+
* @param {DeploymentCreateRequest} config - Required. The deployment config.
74+
* @returns {Promise<object>} Resolves with the deployment data
75+
*/
76+
async function createDeployment(deployment_config) {
77+
const response = await this.request(`/deployments`, {
78+
method: "POST",
79+
data: deployment_config,
80+
});
81+
82+
return response.json();
83+
}
84+
85+
/**
86+
* @typedef {Object} DeploymentUpdateRequest - Request body for `deployments.update`
87+
* @property {string} version - the 64-character string ID of the model version that you want to deploy
88+
* @property {string} hardware - the SKU for the hardware used to run the model, via `replicate.hardware.list()`
89+
* @property {number} min_instances - the minimum number of instances for scaling
90+
* @property {number} max_instances - the maximum number of instances for scaling
91+
*/
92+
93+
/**
94+
* Update an existing deployment
95+
*
96+
* @param {string} deployment_owner - Required. The username of the user or organization who owns the deployment
97+
* @param {string} deployment_name - Required. The name of the deployment
98+
* @param {DeploymentUpdateRequest} deployment_config - Required. The deployment changes.
99+
* @returns {Promise<object>} Resolves with the deployment data
100+
*/
101+
async function updateDeployment(
102+
deployment_owner,
103+
deployment_name,
104+
deployment_config
105+
) {
106+
const response = await this.request(
107+
`/deployments/${deployment_owner}/${deployment_name}`,
108+
{
109+
method: "PATCH",
110+
data: deployment_config,
111+
}
112+
);
113+
114+
return response.json();
115+
}
116+
117+
/**
118+
* List all deployments
119+
*
120+
* @returns {Promise<object>} - Resolves with a page of deployments
121+
*/
122+
async function listDeployments() {
123+
const response = await this.request("/deployments", {
124+
method: "GET",
125+
});
126+
127+
return response.json();
128+
}
129+
60130
module.exports = {
61131
predictions: {
62132
create: createPrediction,
63133
},
64134
get: getDeployment,
135+
create: createDeployment,
136+
update: updateDeployment,
137+
list: listDeployments,
65138
};

tsconfig.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@
55
"strict": true,
66
"allowJs": true
77
},
8-
"exclude": [
9-
"**/node_modules"
10-
]
11-
}
8+
"exclude": ["**/node_modules", "integration"]
9+
}

0 commit comments

Comments
 (0)