fix: move prefill continuation handling to populateChatHistory

aae934a84937a7219ca79f79a8562301e8b66ea2

Carsten Kragelund <carsten@kragelund.me>

1 files changed, +7 -1Ignore whitespace
public/scripts/openai.js+7 -1
@@ -724,6 +724,12 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul
724724
725725 if (chatCompletion.canAfford(chatMessage)) {
726726 if (type === 'continue' && oai_settings.continue_prefill && chatPrompt === firstNonInjected) {
727+ // in case we are using continue_prefill and the latest message is an assistant message, we want to prepend the users assistant prefill on the message
728+ if (chatPrompt.role === 'assistant') {
729+ const collection = new MessageCollection('continuePrefill', new Message(chatMessage.role, substituteParams(oai_settings.assistant_prefill + '\n\n') + chatMessage.content, chatMessage.identifier));
730+ chatCompletion.add(collection, -1);
731+ continue;
732+ }
727733 const collection = new MessageCollection('continuePrefill', chatMessage);
728734 chatCompletion.add(collection, -1);
729735 continue;
@@ -1771,7 +1777,7 @@ async function sendOpenAIRequest(type, messages, signal) {
17711777 generate_data['stop'] = getCustomStoppingStrings(); // Claude shouldn't have limits on stop strings.
17721778 generate_data['human_sysprompt_message'] = substituteParams(oai_settings.human_sysprompt_message);
17731779 // Don't add a prefill on quiet gens (summarization)
17741780 if (!isQuiet && !isContinue) {
17751781 generate_data['assistant_prefill'] = isImpersonate ? substituteParams(oai_settings.assistant_impersonation) : substituteParams(oai_settings.assistant_prefill);
17761782 }
17771783 }