(Feature) Vercel AI SDK (#2024)

This commit is contained in:
Saket Aryan
2024-11-19 23:53:58 +05:30
committed by GitHub
parent a02597ed59
commit 13374a12e9
70 changed files with 4074 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
async function filterStream(originalStream: ReadableStream) {
const reader = originalStream.getReader();
const filteredStream = new ReadableStream({
async start(controller) {
while (true) {
const { done, value } = await reader.read();
if (done) {
controller.close();
break;
}
try {
const chunk = JSON.parse(value);
if (chunk.type !== "step-finish") {
controller.enqueue(value);
}
} catch (error) {
if (!(value.type==='step-finish')) {
controller.enqueue(value);
}
}
}
}
});
return filteredStream;
}
export { filterStream };