simplified the fix
Browse files- app/commit.json +1 -1
- app/routes/api.enhancer.ts +1 -42
app/commit.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{ "commit": "
|
|
|
1 |
+
{ "commit": "05146c18d6e3b5410100089fed99c30d60dccad7" }
|
app/routes/api.enhancer.ts
CHANGED
@@ -5,9 +5,6 @@ import { streamText } from '~/lib/.server/llm/stream-text';
|
|
5 |
import { stripIndents } from '~/utils/stripIndent';
|
6 |
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
7 |
|
8 |
-
const encoder = new TextEncoder();
|
9 |
-
const decoder = new TextDecoder();
|
10 |
-
|
11 |
export async function action(args: ActionFunctionArgs) {
|
12 |
return enhancerAction(args);
|
13 |
}
|
@@ -107,45 +104,7 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
|
|
107 |
providerSettings,
|
108 |
});
|
109 |
|
110 |
-
|
111 |
-
transform(chunk, controller) {
|
112 |
-
const text = decoder.decode(chunk);
|
113 |
-
const lines = text.split('\n').filter((line) => line.trim() !== '');
|
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 |
-
},
|
144 |
-
});
|
145 |
-
|
146 |
-
const transformedStream = result.toDataStream().pipeThrough(transformStream);
|
147 |
-
|
148 |
-
return new Response(transformedStream, {
|
149 |
status: 200,
|
150 |
headers: {
|
151 |
'Content-Type': 'text/plain; charset=utf-8',
|
|
|
5 |
import { stripIndents } from '~/utils/stripIndent';
|
6 |
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
7 |
|
|
|
|
|
|
|
8 |
export async function action(args: ActionFunctionArgs) {
|
9 |
return enhancerAction(args);
|
10 |
}
|
|
|
104 |
providerSettings,
|
105 |
});
|
106 |
|
107 |
+
return new Response(result.textStream, {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
status: 200,
|
109 |
headers: {
|
110 |
'Content-Type': 'text/plain; charset=utf-8',
|