You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importOpenAIfrom'openai';import{OpenAIStream,StreamingTextResponse}from'ai';// Optional, but recommended: run on the edge runtime.// See https://vercel.com/docs/concepts/functions/edge-functionsexportconstruntime='edge';constopenai=newOpenAI({apiKey: process.env.OPENAI_API_KEY!,});exportasyncfunctionPOST(req: Request){// Extract the `messages` from the body of the requestconst{ messages }=awaitreq.json();// Request the OpenAI API for the response based on the promptconstresponse=awaitopenai.chat.completions.create({model: 'gpt-3.5-turbo',stream: true,messages: messages,});// Convert the response into a friendly text-streamconststream=OpenAIStream(response);// Respond with the streamreturnnewStreamingTextResponse(stream);}
Description
Since the last update, the AI SDK now fully supports custom file reading.
Code example
I use ReadStream to read stream from OpenAI :
And follow the documentation for the app router :
Additional context
In this file from the Next.js example, I see that the documentation seems to not be updated: https://github.com/vercel/ai/blob/main/examples/next-openai/app/api/chat/route.ts
The text was updated successfully, but these errors were encountered: