Skip to content

Commit

Permalink
fix: createStream function in chat.ts` to send response chunks as J…
Browse files Browse the repository at this point in the history
…SON objects
  • Loading branch information
glaucia86 authored and sinedied committed Apr 4, 2024
1 parent fd72e16 commit 12b6e13
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/api/src/functions/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,19 @@ function createStream(chunks: AsyncIterable<{ context: Document[]; answer: strin

const stream = async () => {
for await (const chunk of chunks) {
buffer.push(chunk.answer);
const responseChunk = {
choices: [
{
index: 0,
delta: {
content: chunk.answer,
role: 'assistant',
},
},
],
};

buffer.push(JSON.stringify(responseChunk) + '\n');
}

buffer.push(null);
Expand Down

0 comments on commit 12b6e13

Please sign in to comment.