From e15b39731ddd11bb875503938b04c956e268fe42 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 24 Sep 2024 13:12:44 -0700 Subject: [PATCH 1/4] document typescript usage tidy up example Co-Authored-By: Charlie Gleason --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index dabee2e..f42b426 100644 --- a/README.md +++ b/README.md @@ -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. From 92c53e1b4bfd47e335343ac173363b32ab8c4529 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 24 Sep 2024 15:20:29 -0700 Subject: [PATCH 2/4] Update README.md Co-authored-by: F --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f42b426..247f741 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ const output = await replicate.run(model, { input }); This library exports TypeScript definitions. You can import them like this: ```ts -import Replicate, { Prediction } from 'replicate'; +import Replicate, { type Prediction } from 'replicate'; ``` Here's an example that uses the `Prediction` type with a custom `onProgress` callback: From 0233f3cbb0f5ae7978f46e10f372b91f8fa2a618 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 24 Sep 2024 15:20:38 -0700 Subject: [PATCH 3/4] Update README.md Co-authored-by: F --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 247f741..b6b8f48 100644 --- a/README.md +++ b/README.md @@ -128,9 +128,9 @@ 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) => { +function onProgress(prediction: Prediction) { console.log({ prediction }); -}; +} const output = await replicate.run(model, { input: { prompt } }, onProgress) console.log({ output }) From dd52b39e6990d74f3580a3be3e9739e4657874ea Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 24 Sep 2024 15:20:45 -0700 Subject: [PATCH 4/4] Update README.md Co-authored-by: F --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6b8f48..d65fe06 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ import Replicate, { type Prediction } from 'replicate'; Here's an example that uses the `Prediction` type with a custom `onProgress` callback: ```ts -import Replicate, { Prediction } from 'replicate'; +import Replicate, { type Prediction } from 'replicate'; const replicate = new Replicate(); const model = "black-forest-labs/flux-schnell";