Prevent new example chat message being added for no reason

This commit is contained in:
maver 2023-08-12 18:30:39 +02:00
parent a9fa42524d
commit 03b8bb64fa

View File

@ -479,14 +479,8 @@ function populateChatHistory(prompts, chatCompletion, type = null, cyclePrompt =
function populateDialogueExamples(prompts, chatCompletion) {
chatCompletion.add(new MessageCollection('dialogueExamples'), prompts.index('dialogueExamples'));
if (openai_msgs_example.length) {
// Insert chat message examples if there's enough budget if there is enough budget left for at least one example.
const dialogueExampleChat = new Message('system', oai_settings.new_example_chat_prompt, 'newChat');
const prompt = openai_msgs_example[0];
const dialogueExample = new Message(prompt[0]?.role || 'system', prompt[0]?.content || '', 'dialogueExampleTest');
if (chatCompletion.canAfford(dialogueExampleChat) &&
chatCompletion.canAfford(dialogueExample)) {
chatCompletion.insert(dialogueExampleChat, 'dialogueExamples');
const newExampleChat = new Message('system', oai_settings.new_example_chat_prompt, 'newChat');
chatCompletion.reserveBudget(newExampleChat);
[...openai_msgs_example].forEach((dialogue, dialogueIndex) => {
dialogue.forEach((prompt, promptIndex) => {
@ -500,7 +494,11 @@ function populateDialogueExamples(prompts, chatCompletion) {
}
});
});
}
chatCompletion.freeBudget(newExampleChat);
const chatExamples = chatCompletion.getMessages().getItemByIdentifier('dialogueExamples').getCollection();
if(chatExamples.length) chatCompletion.insertAtStart(newExampleChat,'dialogueExamples');
}
}