bolt.new/packages/bolt/app/routes/api.chat.ts

19 lines
580 B
TypeScript
Raw Normal View History

2024-07-10 16:44:39 +00:00
import { type ActionFunctionArgs } from '@remix-run/cloudflare';
import { streamText, type Messages } from '../lib/.server/llm/stream-text';
2024-07-10 16:44:39 +00:00
export async function action({ context, request }: ActionFunctionArgs) {
const { messages } = await request.json<{ messages: Messages }>();
2024-07-10 16:44:39 +00:00
try {
const result = await streamText(messages, context.cloudflare.env, { toolChoice: 'none' });
2024-07-10 16:44:39 +00:00
return result.toAIStreamResponse();
} catch (error) {
console.log(error);
throw new Response(null, {
status: 500,
statusText: 'Internal Server Error',
});
}
}