kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
fix: add support for polyfilled node-fetch on Vercel
rodzic
d4f8abb1e7
commit
dc94e9368a
|
@ -19,8 +19,25 @@ export async function fetchSSE(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
for await (const chunk of streamAsyncIterable(res.body)) {
|
if (!res.body.getReader) {
|
||||||
const str = new TextDecoder().decode(chunk)
|
// Vercel polyfills `fetch` with `node-fetch`, which doesn't conform to
|
||||||
parser.feed(str)
|
// web standards, so this is a workaround...
|
||||||
|
const body: NodeJS.ReadableStream = res.body as any
|
||||||
|
|
||||||
|
if (body.on || !body.read) {
|
||||||
|
throw new Error('unsupported "fetch" implementation')
|
||||||
|
}
|
||||||
|
|
||||||
|
body.on('readable', () => {
|
||||||
|
let chunk: string | Buffer
|
||||||
|
while (null !== (chunk = body.read())) {
|
||||||
|
parser.feed(chunk.toString())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
for await (const chunk of streamAsyncIterable(res.body)) {
|
||||||
|
const str = new TextDecoder().decode(chunk)
|
||||||
|
parser.feed(str)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue