Skip to content

Commit cafb2a5

Browse files
authored
improve replicate.stream example (#197)
Update README.md
1 parent 6dd5b21 commit cafb2a5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,23 @@ Returns `AsyncGenerator<ServerSentEvent>` which yields the events of running the
213213
Example:
214214

215215
```js
216-
for await (const event of replicate.stream("meta/llama-2-70b-chat")) {
217-
process.stdout.write(`${event}`);
216+
const model = "meta/llama-2-70b-chat";
217+
const options = {
218+
input: {
219+
prompt: "Write a poem about machine learning in the style of Mary Oliver.",
220+
},
221+
// webhook: "https://smee.io/dMUlmOMkzeyRGjW" // optional
222+
};
223+
const output = [];
224+
225+
for await (const event of replicate.stream(model, options)) {
226+
console.debug({ event });
227+
if (event && event === "output") {
228+
output.push(event.data);
229+
}
218230
}
231+
232+
console.log(output.join("").trim());
219233
```
220234

221235
### Server-sent events

0 commit comments

Comments
 (0)