Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document typescript usage #310

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,32 @@ const output = await replicate.run(model, { input });
> upload the file to your own storage provider
> and pass a publicly accessible URL.

## TypeScript usage

This library exports TypeScript definitions. You can import them like this:

```ts
import Replicate, { Prediction } from 'replicate';
```

Here's an example that uses the `Prediction` type with a custom `onProgress` callback:

```ts
import Replicate, { Prediction } from 'replicate';

const replicate = new Replicate();
const model = "black-forest-labs/flux-schnell";
const prompt = "a 19th century portrait of a raccoon gentleman wearing a suit";
const onProgress = (prediction: Prediction) => {
console.log({ prediction });
};

const output = await replicate.run(model, { input: { prompt } }, onProgress)
console.log({ output })
```

See the full list of exported types in [index.d.ts](./index.d.ts).

### Webhooks

Webhooks provide real-time updates about your prediction. Specify an endpoint when you create a prediction, and Replicate will send HTTP POST requests to that URL when the prediction is created, updated, and finished.
Expand Down