CC: Only fit entire example dialogue blocks at once
| @@ -798,9 +798,7 @@ async function populateDialogueExamples(prompts, chatCompletion, messageExamples | ||
| 798 | 798 | const newExampleChat = await Message.createAsync('system', substituteParams(oai_settings.new_example_chat_prompt), 'newChat'); |
| 799 | 799 | for (const dialogue of [...messageExamples]) { |
| 800 | 800 | const dialogueIndex = messageExamples.indexOf(dialogue); |
| 801 | 801 | letconst examplesAddedchatMessages = 0[]; |
| 802 | - | |
| 803 | - if (chatCompletion.canAfford(newExampleChat)) chatCompletion.insert(newExampleChat, 'dialogueExamples'); | |
| 804 | 802 | |
| 805 | 803 | for (let promptIndex = 0; promptIndex < dialogue.length; promptIndex++) { |
| 806 | 804 | const prompt = dialogue[promptIndex]; |
| @@ -810,15 +808,17 @@ async function populateDialogueExamples(prompts, chatCompletion, messageExamples | ||
| 810 | 808 | |
| 811 | 809 | const chatMessage = await Message.createAsync(role, content, identifier); |
| 812 | 810 | await chatMessage.setName(prompt.name); |
| 813 | - if (!chatCompletion.canAfford(chatMessage)) { | |
| 811 | + chatMessages.push(chatMessage); | |
| 814 | - break; | |
| 815 | - } | |
| 816 | - chatCompletion.insert(chatMessage, 'dialogueExamples'); | |
| 817 | - examplesAdded++; | |
| 818 | 812 | } |
| 819 | 813 | |
| 820 | - if (0 === examplesAdded) { | |
| 814 | + const canAffordBlock = chatCompletion.canAfford(newExampleChat) && chatCompletion.canAffordAll(chatMessages); | |
| 821 | - chatCompletion.removeLastFrom('dialogueExamples'); | |
| 815 | + if (!canAffordBlock) { | |
| 816 | + break; | |
| 817 | + } | |
| 818 | + | |
| 819 | + chatCompletion.insert(newExampleChat, 'dialogueExamples'); | |
| 820 | + for (const chatMessage of chatMessages) { | |
| 821 | + chatCompletion.insert(chatMessage, 'dialogueExamples'); | |
| 822 | 822 | } |
| 823 | 823 | } |
| 824 | 824 | } |