Skip to content

Commit

Permalink
Merge pull request stackblitz-labs#784 from dustinwloring1988/fix/pro…
Browse files Browse the repository at this point in the history
…mpt-enhance #release

fix: prompt enhance patch
  • Loading branch information
thecodacus authored Dec 17, 2024
2 parents a233008 + d51b0dc commit eb6d435
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions app/routes/api.enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { streamText } from '~/lib/.server/llm/stream-text';
import { stripIndents } from '~/utils/stripIndent';
import type { IProviderSetting, ProviderInfo } from '~/types/model';

const encoder = new TextEncoder();
const decoder = new TextDecoder();

export async function action(args: ActionFunctionArgs) {
return enhancerAction(args);
}
Expand Down Expand Up @@ -107,29 +104,7 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
providerSettings,
});

const transformStream = new TransformStream({
transform(chunk, controller) {
const text = decoder.decode(chunk);
const lines = text.split('\n').filter((line) => line.trim() !== '');

for (const line of lines) {
try {
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);
}
}
},
});

const transformedStream = result.toDataStream().pipeThrough(transformStream);

return new Response(transformedStream, {
return new Response(result.textStream, {
status: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
Expand Down

0 comments on commit eb6d435

Please sign in to comment.