fix: avoid skipping example chats in a dialogue when close to quota

This commit is contained in:
Aisu Wata 2024-04-01 22:44:16 -03:00
parent 99005d6396
commit ac0a431cbe
1 changed files with 7 additions and 5 deletions

View File

@ -818,18 +818,20 @@ function populateDialogueExamples(prompts, chatCompletion, messageExamples) {
if (chatCompletion.canAfford(newExampleChat)) chatCompletion.insert(newExampleChat, 'dialogueExamples');
dialogue.forEach((prompt, promptIndex) => {
for (let promptIndex = 0; promptIndex < dialogue.length; promptIndex++) {
const prompt = dialogue[promptIndex];
const role = 'system';
const content = prompt.content || '';
const identifier = `dialogueExamples ${dialogueIndex}-${promptIndex}`;
const chatMessage = new Message(role, content, identifier);
chatMessage.setName(prompt.name);
if (chatCompletion.canAfford(chatMessage)) {
chatCompletion.insert(chatMessage, 'dialogueExamples');
examplesAdded++;
if (!chatCompletion.canAfford(chatMessage)) {
break;
}
});
chatCompletion.insert(chatMessage, 'dialogueExamples');
examplesAdded++;
}
if (0 === examplesAdded) {
chatCompletion.removeLastFrom('dialogueExamples');