Skip to content

Commit

Permalink
refactor: use await
Browse files Browse the repository at this point in the history
  • Loading branch information
thucpn committed Nov 25, 2024
1 parent 64a2016 commit 23f283f
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,17 @@ export const chat = async (req: Request, res: Response) => {
data: vercelStreamData,
callbacks: { onCompletion },
});
// TODO: move to LlamaIndexAdapter
const reader = streamResponse.body?.getReader();
function read() {
reader?.read().then(({ done, value }: { done: boolean; value?: any }) => {
if (streamResponse.body) {
const reader = streamResponse.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
res.end();
return;
}
res.write(value);
read();
});
}
}
read();
} catch (error) {
console.error("[LlamaIndex]", error);
return res.status(500).json({
Expand Down

0 comments on commit 23f283f

Please sign in to comment.