mirror of
https://github.com/stackblitz/bolt.new
synced 2025-06-26 18:17:50 +00:00
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { type ActionFunctionArgs } from '@remix-run/cloudflare';
|
|
import { streamText } from '~/lib/.server/llm/stream-text';
|
|
import { stripIndents } from '~/utils/stripIndent';
|
|
|
|
export async function action(args: ActionFunctionArgs) {
|
|
return enhancerAction(args);
|
|
}
|
|
|
|
async function enhancerAction({ context, request }: ActionFunctionArgs) {
|
|
const { message } = await request.json<{ message: string }>();
|
|
|
|
try {
|
|
const result = await streamText(
|
|
[
|
|
{
|
|
role: 'user',
|
|
content: stripIndents`
|
|
I want you to improve the user prompt that is wrapped in \`<original_prompt>\` tags.
|
|
|
|
IMPORTANT: Only respond with the improved prompt and nothing else!
|
|
|
|
<original_prompt>
|
|
${message}
|
|
</original_prompt>
|
|
`,
|
|
},
|
|
],
|
|
context.cloudflare.env,
|
|
);
|
|
|
|
/**
|
|
* WARNING: toAIStream has been removed from streamText
|
|
* See migration guide at https://sdk.vercel.ai/docs/migrations.
|
|
*/
|
|
// result.toDataStream().pipeThrough(transformStream);
|
|
|
|
return result.toDataStreamResponse();
|
|
} catch (error) {
|
|
console.log(error);
|
|
|
|
throw new Response(null, {
|
|
status: 500,
|
|
statusText: 'Internal Server Error',
|
|
});
|
|
}
|
|
}
|