Next.js Discord

Discord Forum

Storing conversations with the Vercel AI SDK

Unanswered
DisamDev posted this in #help-forum
Open in Discord
I want to save the conversations in the database with Prisma, I saw that there is the onFinish() for when the request ends, the thing is that I do not know how to maintain a flow that in the first message creates a record in the table chats with an id and then in the following messages add them in the table messages but where the conversationId in the db is the id of the conversation, I do not know how to maintain this flow, and whether to use the onFinish() in the api route /api/chat or in the frontend.

Can someone who knows or has done it help me?

1 Reply

.