From a12051ee24804bd740048fbb7a9dac546e49a341 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 12 Oct 2024 12:56:52 +0300 Subject: [PATCH] CC: Only fit entire example dialogue blocks at once --- public/scripts/openai.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 15c30a6d3..b85c3db97 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -798,9 +798,7 @@ async function populateDialogueExamples(prompts, chatCompletion, messageExamples const newExampleChat = await Message.createAsync('system', substituteParams(oai_settings.new_example_chat_prompt), 'newChat'); for (const dialogue of [...messageExamples]) { const dialogueIndex = messageExamples.indexOf(dialogue); - let examplesAdded = 0; - - if (chatCompletion.canAfford(newExampleChat)) chatCompletion.insert(newExampleChat, 'dialogueExamples'); + const chatMessages = []; for (let promptIndex = 0; promptIndex < dialogue.length; promptIndex++) { const prompt = dialogue[promptIndex]; @@ -810,15 +808,17 @@ async function populateDialogueExamples(prompts, chatCompletion, messageExamples const chatMessage = await Message.createAsync(role, content, identifier); await chatMessage.setName(prompt.name); - if (!chatCompletion.canAfford(chatMessage)) { - break; - } - chatCompletion.insert(chatMessage, 'dialogueExamples'); - examplesAdded++; + chatMessages.push(chatMessage); } - if (0 === examplesAdded) { - chatCompletion.removeLastFrom('dialogueExamples'); + const canAffordBlock = chatCompletion.canAfford(newExampleChat) && chatCompletion.canAffordAll(chatMessages); + if (!canAffordBlock) { + break; + } + + chatCompletion.insert(newExampleChat, 'dialogueExamples'); + for (const chatMessage of chatMessages) { + chatCompletion.insert(chatMessage, 'dialogueExamples'); } } }