forked from replicate/replicate-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
141 lines (124 loc) · 3.62 KB
/
index.d.ts
File metadata and controls
141 lines (124 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { Endpoints } from '@replicate/types-rest-api';
type Status = 'starting' | 'processing' | 'succeeded' | 'failed' | 'canceled';
type WebhookEventType = 'start' | 'output' | 'logs' | 'completed';
interface Page<T> {
previous?: string;
next?: string;
results: T[];
}
/**
* Generic to find out if an object type has any required keys
*/
type NonOptionalKeys<Obj> = {
[K in keyof Obj]: {} extends Pick<Obj, K> ? undefined : K;
}[keyof Obj];
/**
* Make the parameters optional if there is no required parameter
*/
export type ArgumentsTypesForRoute<Route extends string, Parameters extends Record<string, unknown>> = NonOptionalKeys<Parameters> extends undefined ? [Route, Parameters?] : [Route, Parameters];
interface RequestInterface {
<Route extends keyof Endpoints>(...options: ArgumentsTypesForRoute<Route, Endpoints[Route]['parameters']>): Promise<Endpoints[Route]['response']>;
}
export interface Collection {
name: string;
slug: string;
description: string;
models?: Model[];
}
export interface Model {
url: string;
owner: string;
name: string;
description?: string;
visibility: 'public' | 'private';
github_url?: string;
paper_url?: string;
license_url?: string;
run_count: number;
cover_image_url?: string;
default_example?: Prediction;
latest_version?: ModelVersion;
}
export interface ModelVersion {
id: string;
created_at: string;
cog_version: string;
openapi_schema: object;
}
export interface Prediction {
id: string;
status: Status;
version: string;
input: object;
output?: any;
source: 'api' | 'web';
error?: any;
logs?: string;
metrics?: {
predict_time?: number;
};
webhook?: string;
webhook_events_filter?: WebhookEventType[];
created_at: string;
updated_at: string;
completed_at?: string;
}
export type Training = Prediction;
export default class Replicate {
constructor(options: { auth: string; userAgent?: string; baseUrl?: string; fetch?: Function });
auth: string;
userAgent?: string;
baseUrl?: string;
fetch: Function;
run(
identifier: `${string}/${string}:${string}`,
options: {
input: object;
wait?: boolean | { interval?: number; maxAttempts?: number };
webhook?: string;
webhook_events_filter?: WebhookEventType[];
}
): Promise<object>;
request: RequestInterface;
paginate<T>(endpoint: () => Promise<Page<T>>): AsyncGenerator<[T]>;
wait(
prediction: Prediction,
options: {
interval?: number;
maxAttempts?: number;
}
): Promise<Prediction>;
collections: {
list(): Promise<Page<Collection>>;
get(collection_slug: string): Promise<Collection>;
};
models: {
get(model_owner: string, model_name: string): Promise<Model>;
versions: {
list(model_owner: string, model_name: string): Promise<ModelVersion[]>;
get(model_owner: string, model_name: string, version_id: string): Promise<ModelVersion>;
};
};
predictions: {
create(options: { version: string; input: object; webhook?: string; webhook_events_filter?: WebhookEventType[] }): Promise<Prediction>;
get(prediction_id: string): Promise<Prediction>;
cancel(prediction_id: string): Promise<Prediction>;
list(): Promise<Page<Prediction>>;
};
trainings: {
create(
model_owner: string,
model_name: string,
version_id: string,
options: {
destination: `${string}/${string}`;
input: object;
webhook?: string;
webhook_events_filter?: WebhookEventType[];
}
): Promise<Training>;
get(training_id: string): Promise<Training>;
cancel(training_id: string): Promise<Training>;
list(): Promise<Page<Training>>;
};
}