mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-01-23 11:17:02 +00:00
Merge pull request #784 from dustinwloring1988/fix/prompt-enhance #release
fix: prompt enhance patch
This commit is contained in:
commit
eb6d435356
@ -5,9 +5,6 @@ import { streamText } from '~/lib/.server/llm/stream-text';
|
|||||||
import { stripIndents } from '~/utils/stripIndent';
|
import { stripIndents } from '~/utils/stripIndent';
|
||||||
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
||||||
|
|
||||||
const encoder = new TextEncoder();
|
|
||||||
const decoder = new TextDecoder();
|
|
||||||
|
|
||||||
export async function action(args: ActionFunctionArgs) {
|
export async function action(args: ActionFunctionArgs) {
|
||||||
return enhancerAction(args);
|
return enhancerAction(args);
|
||||||
}
|
}
|
||||||
@ -107,29 +104,7 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) {
|
|||||||
providerSettings,
|
providerSettings,
|
||||||
});
|
});
|
||||||
|
|
||||||
const transformStream = new TransformStream({
|
return new Response(result.textStream, {
|
||||||
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, {
|
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/plain; charset=utf-8',
|
'Content-Type': 'text/plain; charset=utf-8',
|
||||||
|
Loading…
Reference in New Issue
Block a user