CC: Only fit entire example dialogue blocks at once

This commit is contained in:
Cohee 2024-10-12 12:56:52 +03:00
parent e4dc489609
commit a12051ee24

View File

@ -798,9 +798,7 @@ async function populateDialogueExamples(prompts, chatCompletion, messageExamples
const newExampleChat = await Message.createAsync('system', substituteParams(oai_settings.new_example_chat_prompt), 'newChat'); const newExampleChat = await Message.createAsync('system', substituteParams(oai_settings.new_example_chat_prompt), 'newChat');
for (const dialogue of [...messageExamples]) { for (const dialogue of [...messageExamples]) {
const dialogueIndex = messageExamples.indexOf(dialogue); const dialogueIndex = messageExamples.indexOf(dialogue);
let examplesAdded = 0; const chatMessages = [];
if (chatCompletion.canAfford(newExampleChat)) chatCompletion.insert(newExampleChat, 'dialogueExamples');
for (let promptIndex = 0; promptIndex < dialogue.length; promptIndex++) { for (let promptIndex = 0; promptIndex < dialogue.length; promptIndex++) {
const prompt = dialogue[promptIndex]; const prompt = dialogue[promptIndex];
@ -810,15 +808,17 @@ async function populateDialogueExamples(prompts, chatCompletion, messageExamples
const chatMessage = await Message.createAsync(role, content, identifier); const chatMessage = await Message.createAsync(role, content, identifier);
await chatMessage.setName(prompt.name); await chatMessage.setName(prompt.name);
if (!chatCompletion.canAfford(chatMessage)) { chatMessages.push(chatMessage);
break;
}
chatCompletion.insert(chatMessage, 'dialogueExamples');
examplesAdded++;
} }
if (0 === examplesAdded) { const canAffordBlock = chatCompletion.canAfford(newExampleChat) && chatCompletion.canAffordAll(chatMessages);
chatCompletion.removeLastFrom('dialogueExamples'); if (!canAffordBlock) {
break;
}
chatCompletion.insert(newExampleChat, 'dialogueExamples');
for (const chatMessage of chatMessages) {
chatCompletion.insert(chatMessage, 'dialogueExamples');
} }
} }
} }