Skip to content

Commit e33ec28

Browse files
feat: add function for getting deployment
1 parent c6fbd33 commit e33ec28

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

index.d.ts

+26
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ declare module "replicate" {
8989
retry?: number;
9090
}
9191

92+
export interface Deployment {
93+
owner: string;
94+
name: string;
95+
current_release: {
96+
number: number;
97+
model: string;
98+
version: string;
99+
created_at: string;
100+
created_by: {
101+
type: "user" | "organization";
102+
username: string;
103+
name: string;
104+
github_url: string;
105+
};
106+
configuration: {
107+
hardware: string;
108+
min_instances: number;
109+
max_instances: number;
110+
};
111+
};
112+
}
113+
92114
export default class Replicate {
93115
constructor(options?: {
94116
auth?: string;
@@ -169,6 +191,10 @@ declare module "replicate" {
169191
}
170192
): Promise<Prediction>;
171193
};
194+
get(
195+
deployment_owner: string,
196+
deployment_name: string
197+
): Promise<Deployment>;
172198
};
173199

174200
hardware: {

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Replicate {
5858
};
5959

6060
this.deployments = {
61+
get: deployments.get.bind(this),
6162
predictions: {
6263
create: deployments.predictions.create.bind(this),
6364
},

index.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,42 @@ describe("Replicate client", () => {
716716
// Add more tests for error handling, edge cases, etc.
717717
});
718718

719+
describe("deployments.get", () => {
720+
test("Calls the correct API route with the correct payload", async () => {
721+
nock(BASE_URL)
722+
.get("/deployments/replicate/greeter")
723+
.reply(200, {
724+
owner: "replicate",
725+
name: "greeter",
726+
current_release: {
727+
number: 1,
728+
model: "replicate/hello-world",
729+
version:
730+
"5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
731+
created_at: "2022-09-10T09:44:22.165836Z",
732+
created_by: {
733+
type: "organization",
734+
username: "replicate",
735+
name: "Replicate",
736+
github_url: "https://github.com/replicate",
737+
},
738+
configuration: {
739+
hardware: "gpu-a100",
740+
min_instances: 0,
741+
max_instances: 1,
742+
},
743+
},
744+
});
745+
746+
const deployment = await client.deployments.get("replicate", "greeter");
747+
748+
expect(deployment.owner).toBe("replicate");
749+
expect(deployment.name).toBe("greeter");
750+
expect(deployment.current_release.model).toBe("replicate/hello-world");
751+
});
752+
// Add more tests for error handling, edge cases, etc.
753+
});
754+
719755
describe("predictions.create with model", () => {
720756
test("Calls the correct API route with the correct payload", async () => {
721757
nock(BASE_URL)

lib/deployments.js

+18
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,26 @@ async function createPrediction(deployment_owner, deployment_name, options) {
3333
return response.json();
3434
}
3535

36+
/**
37+
* Get a deployment
38+
* @param {string} deployment_owner - Required. The username of the user or organization who owns the deployment
39+
* @param {string} deployment_name - Required. The name of the deployment
40+
* @returns {Promise<object>} Resolves with the deployment data
41+
*/
42+
async function getDeployment(deployment_owner, deployment_name) {
43+
const response = await this.request(
44+
`/deployments/${deployment_owner}/${deployment_name}`,
45+
{
46+
method: "GET",
47+
}
48+
);
49+
50+
return response.json();
51+
}
52+
3653
module.exports = {
3754
predictions: {
3855
create: createPrediction,
3956
},
57+
get: getDeployment,
4058
};

0 commit comments

Comments
 (0)