fix: move prefill continuation handling to populateChatHistory

aae934a84937a7219ca79f79a8562301e8b66ea2

Carsten Kragelund <carsten@kragelund.me>

1 files changed, +7 -1Showing whitespace changes
public/scripts/openai.js+7 -1
@@ -724,6 +724,12 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul
724724
725 if (chatCompletion.canAfford(chatMessage)) {725 if (chatCompletion.canAfford(chatMessage)) {
726 if (type === 'continue' && oai_settings.continue_prefill && chatPrompt === firstNonInjected) {726 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 }
727 const collection = new MessageCollection('continuePrefill', chatMessage);733 const collection = new MessageCollection('continuePrefill', chatMessage);
728 chatCompletion.add(collection, -1);734 chatCompletion.add(collection, -1);
729 continue;735 continue;
@@ -1771,7 +1777,7 @@ async function sendOpenAIRequest(type, messages, signal) {
1771 generate_data['stop'] = getCustomStoppingStrings(); // Claude shouldn't have limits on stop strings.1777 generate_data['stop'] = getCustomStoppingStrings(); // Claude shouldn't have limits on stop strings.
1772 generate_data['human_sysprompt_message'] = substituteParams(oai_settings.human_sysprompt_message);1778 generate_data['human_sysprompt_message'] = substituteParams(oai_settings.human_sysprompt_message);
1773 // Don't add a prefill on quiet gens (summarization)1779 // Don't add a prefill on quiet gens (summarization)
1774 if (!isQuiet) {1780 if (!isQuiet && !isContinue) {
1775 generate_data['assistant_prefill'] = isImpersonate ? substituteParams(oai_settings.assistant_impersonation) : substituteParams(oai_settings.assistant_prefill);1781 generate_data['assistant_prefill'] = isImpersonate ? substituteParams(oai_settings.assistant_impersonation) : substituteParams(oai_settings.assistant_prefill);
1776 }1782 }
1777 }1783 }