bolt.new/app/routes/api.enhancer.ts
2025-06-25 15:20:44 -04:00

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',
});
}
}