Skip to content

Commit

Permalink
improve replicate.stream example (#197)
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
zeke committed Jan 30, 2024
1 parent 6dd5b21 commit cafb2a5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions README.md
Expand Up @@ -213,9 +213,23 @@ Returns `AsyncGenerator<ServerSentEvent>` 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
Expand Down

0 comments on commit cafb2a5

Please sign in to comment.