Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};