Skip to content

Commit

Permalink
fix: do not print [object Object] when enhancing prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcabo committed Oct 7, 2024
1 parent 6a9cb78 commit bfe7e12
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/routes/api.enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {

const transformStream = new TransformStream({
transform(chunk, controller) {
const processedChunk = decoder
.decode(chunk)
.split('\n')
.filter((line) => line !== '')
.map(parseStreamPart)
.map((part) => part.value)
.join('');

controller.enqueue(encoder.encode(processedChunk));
const decodedChunk = decoder.decode(chunk);
const parts = decodedChunk.split('\n').filter((line) => line !== '');
for (const part of parts) {
const parsed = parseStreamPart(part);
if (parsed.type === 'text') {
controller.enqueue(encoder.encode(parsed.value));
}
// Non-text chunks are ignored
}
},
});

Expand Down

0 comments on commit bfe7e12

Please sign in to comment.