Spaces:
Sleeping
Sleeping
File size: 675 Bytes
983f705 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | async function stream() {
const response = await fetch(`http://127.0.0.1:8000/dynamo/?prompt=tell+me+a+joke`);
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value);
const lines = text.split("\n\n").filter(line => line.startsWith("data: "));
for (const line of lines) {
const data = line.replace("data: ", "").trim();
if (data === "[DONE]") return;
const { token } = JSON.parse(data);
console.log(token);
}
}
}
stream(); |