ai icon indicating copy to clipboard operation
ai copied to clipboard

Add remix example

Open laiso opened this issue 1 year ago • 1 comments

This PR is a revision of #593 I've confirmed that workflows pass in my forked repo.

laiso avatar Apr 04 '24 09:04 laiso

! update

broisnischal avatar May 05 '24 12:05 broisnischal

Would you update it with AI SDK 3.1?

wong2 avatar Jun 02 '24 10:06 wong2

Looks like it is supposed to be something like this:

import { createOpenAI } from '@ai-sdk/openai';
import { config } from '#app/config.server';
import { defineAction } from '#app/unstable';
import { StreamingTextResponse, streamText } from 'ai';

export default defineAction(async ({ request }) => {
  const openai = createOpenAI({
    apiKey: config.OPENAI_API_KEY,
    compatibility: 'strict',
  });

  const model = openai('gpt-4o');

  const { messages } = await request.json();

  const response = await streamText({
    messages,
    model,
  });

  return new StreamingTextResponse(response.textStream);
});

lilouartz avatar Jun 23 '24 19:06 lilouartz