Skip to content

Commit

Permalink
fix: Prompt Enhance
Browse files Browse the repository at this point in the history
Prompt Enhance option stopped, this fixes it
  • Loading branch information
dustinwloring1988 committed Dec 16, 2024
1 parent 0ee3736 commit 05146c1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/routes/api.enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,30 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {

for (const line of lines) {
try {
const parsed = JSON.parse(line);
// Handle token-based streaming format
if (line.includes('0:"')) {
// Extract all token contents and join them
const tokens = line.match(/0:"([^"]+)"/g) || [];
const content = tokens
.map(token => token.slice(3, -1)) // Remove the '0:"' prefix and '"' suffix
.join('');

if (content) {
controller.enqueue(encoder.encode(content));
}
continue;
}

// Try to parse as JSON if it's not token-based format
const parsed = JSON.parse(line);
if (parsed.type === 'text') {
controller.enqueue(encoder.encode(parsed.value));
}
} catch (e) {
// skip invalid JSON lines
console.warn('Failed to parse stream part:', line, e);
// If not JSON and not token-based, treat as plain text
if (!line.includes('e:') && !line.includes('d:')) { // Skip metadata lines
controller.enqueue(encoder.encode(line));
}
}
}
},
Expand Down

0 comments on commit 05146c1

Please sign in to comment.