Commit
·
05146c1
1
Parent(s):
0ee3736
fix: Prompt Enhance
Browse filesPrompt Enhance option stopped, this fixes it
- app/routes/api.enhancer.ts +19 -3
app/routes/api.enhancer.ts
CHANGED
@@ -114,14 +114,30 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
|
|
114 |
|
115 |
for (const line of lines) {
|
116 |
try {
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
|
|
|
|
119 |
if (parsed.type === 'text') {
|
120 |
controller.enqueue(encoder.encode(parsed.value));
|
121 |
}
|
122 |
} catch (e) {
|
123 |
-
//
|
124 |
-
|
|
|
|
|
125 |
}
|
126 |
}
|
127 |
},
|
|
|
114 |
|
115 |
for (const line of lines) {
|
116 |
try {
|
117 |
+
// Handle token-based streaming format
|
118 |
+
if (line.includes('0:"')) {
|
119 |
+
// Extract all token contents and join them
|
120 |
+
const tokens = line.match(/0:"([^"]+)"/g) || [];
|
121 |
+
const content = tokens
|
122 |
+
.map(token => token.slice(3, -1)) // Remove the '0:"' prefix and '"' suffix
|
123 |
+
.join('');
|
124 |
+
|
125 |
+
if (content) {
|
126 |
+
controller.enqueue(encoder.encode(content));
|
127 |
+
}
|
128 |
+
continue;
|
129 |
+
}
|
130 |
|
131 |
+
// Try to parse as JSON if it's not token-based format
|
132 |
+
const parsed = JSON.parse(line);
|
133 |
if (parsed.type === 'text') {
|
134 |
controller.enqueue(encoder.encode(parsed.value));
|
135 |
}
|
136 |
} catch (e) {
|
137 |
+
// If not JSON and not token-based, treat as plain text
|
138 |
+
if (!line.includes('e:') && !line.includes('d:')) { // Skip metadata lines
|
139 |
+
controller.enqueue(encoder.encode(line));
|
140 |
+
}
|
141 |
}
|
142 |
}
|
143 |
},
|