Skip to content

Commit 184ad23

Browse files
Add support for deployments.get endpoint (#206)
* feat: add function for getting deployment * Use Account type for created_by property * Add newline separator in jsdoc * Update test case to match OpenAPI spec * Update operation ID for account.get * Formatting --------- Co-authored-by: Mattt Zmuda <mattt@replicate.com>
1 parent c0d2a01 commit 184ad23

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

index.d.ts

+21
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ declare module "replicate" {
2222
models?: Model[];
2323
}
2424

25+
export interface Deployment {
26+
owner: string;
27+
name: string;
28+
current_release: {
29+
number: number;
30+
model: string;
31+
version: string;
32+
created_at: string;
33+
created_by: Account;
34+
configuration: {
35+
hardware: string;
36+
min_instances: number;
37+
max_instances: number;
38+
};
39+
};
40+
}
41+
2542
export interface Hardware {
2643
sku: string;
2744
name: string;
@@ -173,6 +190,10 @@ declare module "replicate" {
173190
}
174191
): Promise<Prediction>;
175192
};
193+
get(
194+
deployment_owner: string,
195+
deployment_name: string
196+
): Promise<Deployment>;
176197
};
177198

178199
hardware: {

index.js

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

6161
this.deployments = {
62+
get: deployments.get.bind(this),
6263
predictions: {
6364
create: deployments.predictions.create.bind(this),
6465
},

index.test.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("Replicate client", () => {
7272
});
7373
});
7474

75-
describe("accounts.current", () => {
75+
describe("account.get", () => {
7676
test("Calls the correct API route", async () => {
7777
nock(BASE_URL).get("/account").reply(200, {
7878
type: "organization",
@@ -721,6 +721,47 @@ describe("Replicate client", () => {
721721
// Add more tests for error handling, edge cases, etc.
722722
});
723723

724+
describe("deployments.get", () => {
725+
test("Calls the correct API route with the correct payload", async () => {
726+
nock(BASE_URL)
727+
.get("/deployments/acme/my-app-image-generator")
728+
.reply(200, {
729+
owner: "acme",
730+
name: "my-app-image-generator",
731+
current_release: {
732+
number: 1,
733+
model: "stability-ai/sdxl",
734+
version:
735+
"da77bc59ee60423279fd632efb4795ab731d9e3ca9705ef3341091fb989b7eaf",
736+
created_at: "2024-02-15T16:32:57.018467Z",
737+
created_by: {
738+
type: "organization",
739+
username: "acme",
740+
name: "Acme Corp, Inc.",
741+
github_url: "https://github.com/acme",
742+
},
743+
configuration: {
744+
hardware: "gpu-t4",
745+
scaling: {
746+
min_instances: 1,
747+
max_instances: 5,
748+
},
749+
},
750+
},
751+
});
752+
753+
const deployment = await client.deployments.get(
754+
"acme",
755+
"my-app-image-generator"
756+
);
757+
758+
expect(deployment.owner).toBe("acme");
759+
expect(deployment.name).toBe("my-app-image-generator");
760+
expect(deployment.current_release.model).toBe("stability-ai/sdxl");
761+
});
762+
// Add more tests for error handling, edge cases, etc.
763+
});
764+
724765
describe("predictions.create with model", () => {
725766
test("Calls the correct API route with the correct payload", async () => {
726767
nock(BASE_URL)

lib/deployments.js

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

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

0 commit comments

Comments
 (0)