|
1 | 1 | declare module "replicate" { |
2 | | - type Status = "starting" | "processing" | "succeeded" | "failed" | "canceled"; |
3 | | - type Visibility = "public" | "private"; |
4 | | - type WebhookEventType = "start" | "output" | "logs" | "completed"; |
| 2 | + export type Status = "starting" | "processing" | "succeeded" | "failed" | "canceled"; |
| 3 | + export type Visibility = "public" | "private"; |
| 4 | + export type WebhookEventType = "start" | "output" | "logs" | "completed"; |
5 | 5 |
|
6 | 6 | export interface ApiError extends Error { |
7 | 7 | request: Request; |
@@ -82,7 +82,7 @@ declare module "replicate" { |
82 | 82 | retry?: number; |
83 | 83 | } |
84 | 84 |
|
85 | | - export default class Replicate { |
| 85 | + export class Replicate { |
86 | 86 | constructor(options?: { |
87 | 87 | auth?: string; |
88 | 88 | userAgent?: string; |
@@ -223,4 +223,74 @@ declare module "replicate" { |
223 | 223 | list(): Promise<Page<Training>>; |
224 | 224 | }; |
225 | 225 | } |
| 226 | + |
| 227 | + /** @deprecated */ |
| 228 | + class DeprecatedReplicate extends Replicate { |
| 229 | + /** @deprecated Use `const Replicate = require("replicate").Replicate` instead */ |
| 230 | + constructor(...args: ConstructorParameters<typeof Replicate>); |
| 231 | + } |
| 232 | + |
| 233 | + |
| 234 | + /** |
| 235 | + * Default instance of the Replicate class that gets the access token |
| 236 | + * from the REPLICATE_API_TOKEN environment variable. |
| 237 | + * |
| 238 | + * Create a new Replicate API client instance. |
| 239 | + * |
| 240 | + * @example |
| 241 | + * |
| 242 | + * import replicate from "replicate"; |
| 243 | + * |
| 244 | + * // Run a model and await the result: |
| 245 | + * const model = 'owner/model:version-id' |
| 246 | + * const input = {text: 'Hello, world!'} |
| 247 | + * const output = await replicate.run(model, { input }); |
| 248 | + * |
| 249 | + * @remarks |
| 250 | + * |
| 251 | + * NOTE: Use of this object as a constructor is deprecated and will |
| 252 | + * be removed in a future version. Import the Replicate constructor |
| 253 | + * instead: |
| 254 | + * |
| 255 | + * ``` |
| 256 | + * const Replicate = require("replicate").Replicate; |
| 257 | + * ``` |
| 258 | + * |
| 259 | + * Or using esm: |
| 260 | + * |
| 261 | + * ``` |
| 262 | + * import replicate from "replicate"; |
| 263 | + * const client = new replicate.Replicate({...}); |
| 264 | + * ``` |
| 265 | + * |
| 266 | + * @type { Replicate & typeof DeprecatedReplicate & {ApiError: ApiError, Replicate: Replicate} } |
| 267 | + */ |
| 268 | + const replicate: Replicate & typeof DeprecatedReplicate & { |
| 269 | + /** |
| 270 | + * Create a new Replicate API client instance. |
| 271 | + * |
| 272 | + * @example |
| 273 | + * // Create a new Replicate API client instance |
| 274 | + * const Replicate = require("replicate"); |
| 275 | + * const replicate = new Replicate({ |
| 276 | + * // get your token from https://replicate.com/account |
| 277 | + * auth: process.env.REPLICATE_API_TOKEN, |
| 278 | + * userAgent: "my-app/1.2.3" |
| 279 | + * }); |
| 280 | + * |
| 281 | + * // Run a model and await the result: |
| 282 | + * const model = 'owner/model:version-id' |
| 283 | + * const input = {text: 'Hello, world!'} |
| 284 | + * const output = await replicate.run(model, { input }); |
| 285 | + * |
| 286 | + * @param {object} options - Configuration options for the client |
| 287 | + * @param {string} options.auth - API access token. Defaults to the `REPLICATE_API_TOKEN` environment variable. |
| 288 | + * @param {string} options.userAgent - Identifier of your app |
| 289 | + * @param {string} [options.baseUrl] - Defaults to https://api.replicate.com/v1 |
| 290 | + * @param {Function} [options.fetch] - Fetch function to use. Defaults to `globalThis.fetch` |
| 291 | + */ |
| 292 | + Replicate: typeof Replicate |
| 293 | + }; |
| 294 | + |
| 295 | + export default replicate; |
226 | 296 | } |
0 commit comments