@@ -57,9 +57,82 @@ async function getDeployment(deployment_owner, deployment_name) {
57
57
return response . json ( ) ;
58
58
}
59
59
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
+
60
130
module . exports = {
61
131
predictions : {
62
132
create : createPrediction ,
63
133
} ,
64
134
get : getDeployment ,
135
+ create : createDeployment ,
136
+ update : updateDeployment ,
137
+ list : listDeployments ,
65
138
} ;
0 commit comments