Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
48 changes: 40 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module "replicate" {
type Status = "starting" | "processing" | "succeeded" | "failed" | "canceled" | "aborted";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we still using aborted, @erbridge? Just noticed it because we were discussing statuses today.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's defined and used in replicate/api, but not yet documented in the OpenAPI schema.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using it, so we should probably update the schema.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝🏼 Shipped.

Copy link
Member Author

@zeke zeke Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this PR: d702154

type Status = "starting" | "processing" | "succeeded" | "failed" | "canceled";
type Visibility = "public" | "private";
type WebhookEventType = "start" | "output" | "logs" | "completed";

Expand All @@ -19,6 +19,7 @@ declare module "replicate" {
username: string;
name: string;
github_url?: string;
avatar_url?: string;
}

export interface Collection {
Expand Down Expand Up @@ -48,11 +49,11 @@ declare module "replicate" {

export interface FileObject {
id: string;
name: string;
content_type: string;
size: number;
etag: string;
checksum: string;
checksums: {
sha256: string;
};
metadata: Record<string, unknown>;
created_at: string;
expires_at: string | null;
Expand Down Expand Up @@ -85,22 +86,26 @@ declare module "replicate" {
export interface ModelVersion {
id: string;
created_at: string;
cog_version: string;
openapi_schema: object;
cog_version: string | null;
openapi_schema: object | null;
}

export interface Prediction {
id: string;
status: Status;
model: string;
version: string;
version: string | "hidden";
input: object;
output?: any; // TODO: this should be `unknown`
source: "api" | "web";
error?: unknown;
logs?: string;
data_removed: boolean;
deadline?: string;
deployment?: string;
metrics?: {
predict_time?: number;
total_time?: number;
};
webhook?: string;
webhook_events_filter?: WebhookEventType[];
Expand All @@ -111,10 +116,37 @@ declare module "replicate" {
get: string;
cancel: string;
stream?: string;
web?: string;
};
}

export type Training = Prediction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeke Do we want to move to training being a standalone type? Currently it mirrors Prediction, so I'm not sure what this will do, if anything, to linting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Training and Prediction have different fields according to the OpenAPI schema, so I think they should be separate types:

Fields in Prediction but NOT in Training:

  • data_removed: boolean
  • deadline?: string
  • deployment?: string

Type differences:

  • version: Prediction is string | "hidden", Training is just string
  • output: Prediction is any, Training is { version?: string; weights?: string }
  • urls: Prediction has stream?, Training does not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these are also just inconsistencies between Training and Prediction in the OpenAPI schema, but I don't actually know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair! I'm not sure. 😔 I wouldn't be surprised if there were inconsistencies there. Good to clean it up.

export interface Training {
id: string;
status: Status;
model: string;
version: string;
input: object;
output?: {
version?: string;
weights?: string;
};
source: "api" | "web";
error?: unknown;
logs?: string;
metrics?: {
predict_time?: number;
total_time?: number;
};
webhook?: string;
webhook_events_filter?: WebhookEventType[];
created_at: string;
started_at?: string;
completed_at?: string;
urls: {
get: string;
cancel: string;
};
}

export type FileEncodingStrategy = "default" | "upload" | "data-uri";

Expand Down
23 changes: 11 additions & 12 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Replicate, {
FileOutput,
Model,
Prediction,
Training,
validateWebhook,
parseProgressFromLogs,
} from "replicate";
Expand Down Expand Up @@ -906,7 +907,7 @@ describe("Replicate client", () => {
next: null,
});

const results: Prediction[] = [];
const results: Training[] = [];
for await (const batch of client.paginate(client.trainings.list)) {
results.push(...batch);
}
Expand Down Expand Up @@ -1176,11 +1177,11 @@ describe("Replicate client", () => {
.post("/files")
.reply(200, {
id: "123",
name: "test-file",
content_type: "application/octet-stream",
size: 1024,
etag: "abc123",
checksum: "sha256:1234567890abcdef",
checksums: {
sha256: "1234567890abcdef",
},
metadata: {},
created_at: "2023-01-01T00:00:00Z",
expires_at: null,
Expand All @@ -1190,7 +1191,6 @@ describe("Replicate client", () => {
});
const file = await client.files.create(testCase.value);
expect(file.id).toBe("123");
expect(file.name).toBe("test-file");
}
});
});
Expand All @@ -1201,11 +1201,11 @@ describe("Replicate client", () => {
.get("/files/123")
.reply(200, {
id: "123",
name: "test-file",
content_type: "application/octet-stream",
size: 1024,
etag: "abc123",
checksum: "sha256:1234567890abcdef",
checksums: {
sha256: "1234567890abcdef",
},
metadata: {},
created_at: "2023-01-01T00:00:00Z",
expires_at: null,
Expand All @@ -1216,7 +1216,6 @@ describe("Replicate client", () => {

const file = await client.files.get("123");
expect(file.id).toBe("123");
expect(file.name).toBe("test-file");
});
});

Expand All @@ -1230,11 +1229,11 @@ describe("Replicate client", () => {
results: [
{
id: "123",
name: "test-file",
content_type: "application/octet-stream",
size: 1024,
etag: "abc123",
checksum: "sha256:1234567890abcdef",
checksums: {
sha256: "1234567890abcdef",
},
metadata: {},
created_at: "2023-01-01T00:00:00Z",
expires_at: null,
Expand Down
Loading