Skip to content

Commit

Permalink
Add support for deployments.get endpoint (#206)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mattrothenberg and mattt committed Feb 16, 2024
1 parent c0d2a01 commit 184ad23
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
21 changes: 21 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ declare module "replicate" {
models?: Model[];
}

export interface Deployment {
owner: string;
name: string;
current_release: {
number: number;
model: string;
version: string;
created_at: string;
created_by: Account;
configuration: {
hardware: string;
min_instances: number;
max_instances: number;
};
};
}

export interface Hardware {
sku: string;
name: string;
Expand Down Expand Up @@ -173,6 +190,10 @@ declare module "replicate" {
}
): Promise<Prediction>;
};
get(
deployment_owner: string,
deployment_name: string
): Promise<Deployment>;
};

hardware: {
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Replicate {
};

this.deployments = {
get: deployments.get.bind(this),
predictions: {
create: deployments.predictions.create.bind(this),
},
Expand Down
43 changes: 42 additions & 1 deletion index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe("Replicate client", () => {
});
});

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

describe("deployments.get", () => {
test("Calls the correct API route with the correct payload", async () => {
nock(BASE_URL)
.get("/deployments/acme/my-app-image-generator")
.reply(200, {
owner: "acme",
name: "my-app-image-generator",
current_release: {
number: 1,
model: "stability-ai/sdxl",
version:
"da77bc59ee60423279fd632efb4795ab731d9e3ca9705ef3341091fb989b7eaf",
created_at: "2024-02-15T16:32:57.018467Z",
created_by: {
type: "organization",
username: "acme",
name: "Acme Corp, Inc.",
github_url: "https://github.com/acme",
},
configuration: {
hardware: "gpu-t4",
scaling: {
min_instances: 1,
max_instances: 5,
},
},
},
});

const deployment = await client.deployments.get(
"acme",
"my-app-image-generator"
);

expect(deployment.owner).toBe("acme");
expect(deployment.name).toBe("my-app-image-generator");
expect(deployment.current_release.model).toBe("stability-ai/sdxl");
});
// Add more tests for error handling, edge cases, etc.
});

describe("predictions.create with model", () => {
test("Calls the correct API route with the correct payload", async () => {
nock(BASE_URL)
Expand Down
19 changes: 19 additions & 0 deletions lib/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,27 @@ async function createPrediction(deployment_owner, deployment_name, options) {
return response.json();
}

/**
* Get a deployment
*
* @param {string} deployment_owner - Required. The username of the user or organization who owns the deployment
* @param {string} deployment_name - Required. The name of the deployment
* @returns {Promise<object>} Resolves with the deployment data
*/
async function getDeployment(deployment_owner, deployment_name) {
const response = await this.request(
`/deployments/${deployment_owner}/${deployment_name}`,
{
method: "GET",
}
);

return response.json();
}

module.exports = {
predictions: {
create: createPrediction,
},
get: getDeployment,
};

0 comments on commit 184ad23

Please sign in to comment.