How to feed chat history? #3857
Answered
by
patelvivekdev
o1Suleyman
asked this question in
Help
-
Let's say I have the chat history for a particular chat stored in a database and retrieve it, how exactly would the history then be forwarded to the model? |
Beta Was this translation helpful? Give feedback.
Answered by
patelvivekdev
Nov 25, 2024
Replies: 1 comment
-
If you use import { useChat } from 'ai/react';
// fetch the initial messages from db.
const { messages } = useChat({
id,
initialMessages,
}); In API, you can get messages from req export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: openai('gpt-4-turbo'),
messages,
})
} Read more at https://sdk.vercel.ai/examples/next/state-management/restore-messages |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
o1Suleyman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use
useChat,
you can fetch the messages from the db and pass them on as arguments.In API, you can get messages from req
Read more at https://sdk.vercel.ai/examples/next/state-management/restore-messages