From fa60bd17e04ee08a906cb48bb2d21f4c18e7a80c Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Mon, 22 Jan 2024 15:10:16 -0800 Subject: [PATCH] improve replicate.stream example Update README.md --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d5bef3..90ed101 100644 --- a/README.md +++ b/README.md @@ -213,9 +213,23 @@ Returns `AsyncGenerator` which yields the events of running the Example: ```js -for await (const event of replicate.stream("meta/llama-2-70b-chat")) { - process.stdout.write(`${event}`); +const model = "meta/llama-2-70b-chat"; +const options = { + input: { + prompt: "Write a poem about machine learning in the style of Mary Oliver.", + }, + // webhook: "https://smee.io/dMUlmOMkzeyRGjW" // optional +}; +const output = []; + +for await (const event of replicate.stream(model, options)) { + console.debug({ event }); + if (event && event === "output") { + output.push(event.data); + } } + +console.log(output.join("").trim()); ``` ### Server-sent events