For an idea context we should input an array of all questions and answers in each request.
As this is not possible for long conversations (there is a limit of tokens to be used as input) the usual practice is to limit the number of previous interactions. We could use the last 5 for example.
So before sending the request we should prepare a conversation history that after will pass to the "message" property.
// Prepare the conversation history
const conversation = [
{
role: 'system',
content:
'You are an expert programming tutor. Help students understand coding concepts without giving direct code examples. Use clear explanations.',
},
...recentMessages.map((message) => ({
role: message.sender === 'user' ? 'user' : 'assistant',
content: message.content,
})),
{
role: 'user',
content: content,
},
];
For an idea context we should input an array of all questions and answers in each request. As this is not possible for long conversations (there is a limit of tokens to be used as input) the usual practice is to limit the number of previous interactions. We could use the last 5 for example.
So before sending the request we should prepare a conversation history that after will pass to the "message" property.