Skip to content

Commit

Permalink
fix(server)!: JSON-encode tokens to retain characters such as newline…
Browse files Browse the repository at this point in the history
…s properly
  • Loading branch information
waylaidwanderer committed Feb 27, 2023
1 parent af1b9e8 commit 46bdc57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ server.post('/conversation', async (request, reply) => {
console.debug(token);
}
if (token !== '[DONE]') {
reply.sse({ id: '', data: token });
reply.sse({ id: '', data: JSON.stringify(token) });
}
};
} else {
Expand Down
7 changes: 3 additions & 4 deletions demos/use-api-server-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const opts = {
try {
let reply = '';
const controller = new AbortController();
await fetchEventSource('http://localhost:3000/conversation', {
await fetchEventSource('http://localhost:3001/conversation', {
...opts,
signal: controller.signal,
onopen(response) {
Expand All @@ -40,12 +40,11 @@ try {
}
if (message.event === 'result') {
const result = JSON.parse(message.data);
const { response, conversationId } = result;
console.log({ response, conversationId });
console.log(result);
return;
}
console.log(message);
reply += message.data;
reply += JSON.parse(message.data);
},
});
console.log(reply);
Expand Down

0 comments on commit 46bdc57

Please sign in to comment.