-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathindex.d.ts
More file actions
296 lines (270 loc) · 7.61 KB
/
index.d.ts
File metadata and controls
296 lines (270 loc) · 7.61 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
declare module "replicate" {
export type Status = "starting" | "processing" | "succeeded" | "failed" | "canceled";
export type Visibility = "public" | "private";
export type WebhookEventType = "start" | "output" | "logs" | "completed";
export interface ApiError extends Error {
request: Request;
response: Response;
}
export interface Collection {
name: string;
slug: string;
description: string;
models?: Model[];
}
export interface Hardware {
sku: string;
name: string;
}
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;
model: string;
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;
started_at?: string;
completed_at?: string;
urls: {
get: string;
cancel: string;
stream?: string;
};
}
export type Training = Prediction;
export interface Page<T> {
previous?: string;
next?: string;
results: T[];
}
export interface ServerSentEvent {
event: string;
data: string;
id?: string;
retry?: number;
}
export class Replicate {
constructor(options?: {
auth?: string;
userAgent?: string;
baseUrl?: string;
fetch?: (
input: Request | string,
init?: RequestInit
) => Promise<Response>;
});
auth: string;
userAgent?: string;
baseUrl?: string;
fetch: (input: Request | string, init?: RequestInit) => Promise<Response>;
run(
identifier: `${string}/${string}` | `${string}/${string}:${string}`,
options: {
input: object;
wait?: { interval?: number };
webhook?: string;
webhook_events_filter?: WebhookEventType[];
signal?: AbortSignal;
},
progress?: (prediction: Prediction) => void
): Promise<object>;
stream(
identifier: `${string}/${string}` | `${string}/${string}:${string}`,
options: {
input: object;
webhook?: string;
webhook_events_filter?: WebhookEventType[];
signal?: AbortSignal;
}
): AsyncGenerator<ServerSentEvent>;
request(
route: string | URL,
options: {
method?: string;
headers?: object | Headers;
params?: object;
data?: object;
}
): Promise<Response>;
paginate<T>(endpoint: () => Promise<Page<T>>): AsyncGenerator<[T]>;
wait(
prediction: Prediction,
options?: {
interval?: number;
},
stop?: (prediction: Prediction) => Promise<boolean>
): Promise<Prediction>;
collections: {
list(): Promise<Page<Collection>>;
get(collection_slug: string): Promise<Collection>;
};
deployments: {
predictions: {
create(
deployment_owner: string,
deployment_name: string,
options: {
input: object;
stream?: boolean;
webhook?: string;
webhook_events_filter?: WebhookEventType[];
}
): Promise<Prediction>;
};
};
hardware: {
list(): Promise<Hardware[]>;
};
models: {
get(model_owner: string, model_name: string): Promise<Model>;
list(): Promise<Page<Model>>;
create(
model_owner: string,
model_name: string,
options: {
visibility: Visibility;
hardware: string;
description?: string;
github_url?: string;
paper_url?: string;
license_url?: string;
cover_image_url?: 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: {
model?: string;
version?: string;
input: object;
stream?: boolean;
webhook?: string;
webhook_events_filter?: WebhookEventType[];
} & ({ version: string } | { model: string })
): 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>>;
};
}
/** @deprecated */
class DeprecatedReplicate extends Replicate {
/** @deprecated Use `const Replicate = require("replicate").Replicate` instead */
constructor(...args: ConstructorParameters<typeof Replicate>);
}
/**
* Default instance of the Replicate class that gets the access token
* from the REPLICATE_API_TOKEN environment variable.
*
* Create a new Replicate API client instance.
*
* @example
*
* import replicate from "replicate";
*
* // Run a model and await the result:
* const model = 'owner/model:version-id'
* const input = {text: 'Hello, world!'}
* const output = await replicate.run(model, { input });
*
* @remarks
*
* NOTE: Use of this object as a constructor is deprecated and will
* be removed in a future version. Import the Replicate constructor
* instead:
*
* ```
* const Replicate = require("replicate").Replicate;
* ```
*
* Or using esm:
*
* ```
* import replicate from "replicate";
* const client = new replicate.Replicate({...});
* ```
*
* @type { Replicate & typeof DeprecatedReplicate & {ApiError: ApiError, Replicate: Replicate} }
*/
const replicate: Replicate & typeof DeprecatedReplicate & {
/**
* Create a new Replicate API client instance.
*
* @example
* // Create a new Replicate API client instance
* const Replicate = require("replicate");
* const replicate = new Replicate({
* // get your token from https://replicate.com/account
* auth: process.env.REPLICATE_API_TOKEN,
* userAgent: "my-app/1.2.3"
* });
*
* // Run a model and await the result:
* const model = 'owner/model:version-id'
* const input = {text: 'Hello, world!'}
* const output = await replicate.run(model, { input });
*
* @param {object} options - Configuration options for the client
* @param {string} options.auth - API access token. Defaults to the `REPLICATE_API_TOKEN` environment variable.
* @param {string} options.userAgent - Identifier of your app
* @param {string} [options.baseUrl] - Defaults to https://api.replicate.com/v1
* @param {Function} [options.fetch] - Fetch function to use. Defaults to `globalThis.fetch`
*/
Replicate: typeof Replicate
};
export default replicate;
}