#2379 Move continue prefill to end of completion

This commit is contained in:
Cohee 2024-06-15 18:00:09 +03:00
parent 3cafc22e1d
commit 339428a4e9
1 changed files with 8 additions and 1 deletions

View File

@ -723,7 +723,7 @@ function populationInjectionPrompts(prompts, messages) {
const jointPrompt = [rolePrompts, extensionPrompt].filter(x => x).map(x => x.trim()).join(separator);
if (jointPrompt && jointPrompt.length) {
roleMessages.push({ 'role': role, 'content': jointPrompt });
roleMessages.push({ 'role': role, 'content': jointPrompt, injected: true });
}
}
@ -795,6 +795,7 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul
// Insert chat messages as long as there is budget available
const chatPool = [...messages].reverse();
const firstNonInjected = chatPool.find(x => !x.injected);
for (let index = 0; index < chatPool.length; index++) {
const chatPrompt = chatPool[index];
@ -813,6 +814,12 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul
}
if (chatCompletion.canAfford(chatMessage)) {
if (type === 'continue' && oai_settings.continue_prefill && chatPrompt === firstNonInjected) {
const collection = new MessageCollection('continuePrefill', chatMessage);
chatCompletion.add(collection, -1);
continue;
}
chatCompletion.insertAtStart(chatMessage, 'chatHistory');
} else {
break;