chatgpt-plugin/utils/openai/stream-async-iterable.js
2023-06-23 01:09:12 +08:00

14 lines
278 B
JavaScript

export async function * streamAsyncIterable (stream) {
const reader = stream.getReader()
try {
while (true) {
const { done, value } = await reader.read()
if (done) {
return
}
yield value
}
} finally {
reader.releaseLock()
}
}