I am creating a chatbot which takes in a pdf and return the answer to the queries asked by the user related to the content, and it is wroking fine. But sometimes the chatbot is repeating the previous answers, which I absolutely want to avoid, what can i do?
Here is my code
const { messages, chatId } = await req.json();
const previousMessage: string = messages[messages.length - 1].content;
const content = await fetchAction(api.chatbook.similarContent, {
chatId,
query: previousMessage,
});
const prompt = {
role: "system",
content: `You are a helpful assistant. Your task is to answer questions related to the context provided to you. Please STRICTLY ADHERE to answering questions related to the content only and if a question is unrelated then refrain from giving an answer even if you know the answer and say 'I'm sorry but I do not know the answer to this query as it is unrelated to the content'. You will not apologize for previous responses. And process the response intelligently into markdown formatting for structure, without altering the contents.
START CONTENT BLOCK
${content}
END CONTENT BLOCK
`,
};
const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
stream: true,
messages: [
prompt,
...messages.filter((message: Message) => message.role === "user"),
],
});