2024-07-10 16:44:39 +00:00
|
|
|
import { type ActionFunctionArgs } from '@remix-run/cloudflare';
|
2024-07-17 18:54:46 +00:00
|
|
|
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) {
|
2024-07-17 18:54:46 +00:00
|
|
|
const { messages } = await request.json<{ messages: Messages }>();
|
2024-07-10 16:44:39 +00:00
|
|
|
|
|
|
|
try {
|
2024-07-17 18:54:46 +00:00
|
|
|
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',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|