How to store messages generated by AI - Vercel AI SDK and Prisma
Answered
Rhinelander posted this in #help-forum
RhinelanderOP
Hey, I've been losing my mind for the past two days. How do I store messages from AI to db? What do you think is the right approach? I do that by using AI SDK onFinish(), but how should the schema look? I can't get the types to match. Any help is welcome ❤️
Answered by B33fb0n3
I don't know that much about prisma, but this should be a good schema:
I added the threadId as well, so you can get all messages by a specific thread id.
You can also extend this even more, to have a title or other attributes as well for the thread:
model Message {
id String @id @default(cuid())
threadId String
message String
}
I added the threadId as well, so you can get all messages by a specific thread id.
You can also extend this even more, to have a title or other attributes as well for the thread:
model Thread {
id String @id @default(cuid())
title String
}
4 Replies
maybe something like:
That should do the job pretty fine or am I missing something?
{
"id": "someMessageId",
"message": "some markdown **message**"
}
That should do the job pretty fine or am I missing something?
RhinelanderOP
How should prisma schema look like. I always get type error as it is not compatible with message so converstation history can't be made.
I don't know that much about prisma, but this should be a good schema:
I added the threadId as well, so you can get all messages by a specific thread id.
You can also extend this even more, to have a title or other attributes as well for the thread:
model Message {
id String @id @default(cuid())
threadId String
message String
}
I added the threadId as well, so you can get all messages by a specific thread id.
You can also extend this even more, to have a title or other attributes as well for the thread:
model Thread {
id String @id @default(cuid())
title String
}
Answer