diff --git a/public/index.html b/public/index.html index 9324e47e1..698ebfbc0 100644 --- a/public/index.html +++ b/public/index.html @@ -945,7 +945,7 @@ Influences bot behavior in its responses.
- +
@@ -959,7 +959,7 @@ Prompt that is used for Impersonation function
- +
diff --git a/public/script.js b/public/script.js index 38c16338e..d3d96b96b 100644 --- a/public/script.js +++ b/public/script.js @@ -105,6 +105,7 @@ import { generatePoe, is_get_status_poe, setPoeOnlineStatus, + appendPoeAnchors, } from "./scripts/poe.js"; import { @@ -1901,11 +1902,17 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, } // Extension added strings - const allAnchors = getAllExtensionPrompts(); + let allAnchors = getAllExtensionPrompts(); const afterScenarioAnchor = getExtensionPrompt(extension_prompt_types.AFTER_SCENARIO); let zeroDepthAnchor = getExtensionPrompt(extension_prompt_types.IN_CHAT, 0, ' '); let { worldInfoString, worldInfoBefore, worldInfoAfter } = getWorldInfoPrompt(chat2); + // Moved here to not overflow the Poe context with added prompt bits + if (main_api == 'poe') { + allAnchors = appendPoeAnchors(type, allAnchors); + zeroDepthAnchor = appendPoeAnchors(type, zeroDepthAnchor); + } + // hack for regeneration of the first message if (chat2.length == 0) { chat2.push(''); diff --git a/public/scripts/poe.js b/public/scripts/poe.js index 6371d0ed9..2e1b7e15b 100644 --- a/public/scripts/poe.js +++ b/public/scripts/poe.js @@ -86,6 +86,23 @@ function onBotChange() { saveSettingsDebounced(); } +export function appendPoeAnchors(type, prompt) { + const isImpersonate = type === 'impersonate'; + const isQuiet = type === 'quiet'; + + if (poe_settings.character_nudge && !isQuiet && !isImpersonate) { + let characterNudge = '\n' + substituteParams(poe_settings.character_nudge_message); + prompt += characterNudge; + } + + if (poe_settings.impersonation_prompt && isImpersonate) { + let impersonationNudge = '\n' + substituteParams(poe_settings.impersonation_prompt); + prompt += impersonationNudge; + } + + return prompt; +} + async function generatePoe(type, finalPrompt, signal) { if (poe_settings.auto_purge) { let count_to_delete = -1; @@ -115,28 +132,7 @@ async function generatePoe(type, finalPrompt, signal) { console.log('Could not jailbreak the bot'); } - const isImpersonate = type === 'impersonate'; const isQuiet = type === 'quiet'; - - if (poe_settings.character_nudge && !isQuiet && !isImpersonate) { - let characterNudge = '\n' + substituteParams(poe_settings.character_nudge_message); - finalPrompt += characterNudge; - } - - if (poe_settings.impersonation_prompt && isImpersonate) { - let impersonationNudge = '\n' + substituteParams(poe_settings.impersonation_prompt); - finalPrompt += impersonationNudge; - } - - // If prompt overflows the max context, reduce it (or the generation would fail) - // Split by sentence boundary and remove sentence-by-sentence from the beginning - while (getTokenCount(finalPrompt) > max_context) { - const sentences = finalPrompt.split(/([.?!])\s+/); - const removed = sentences.shift(); - console.log(`Reducing Poe context due to overflow. Sentence dropped from prompt: "${removed}"`); - finalPrompt = sentences.join(''); - } - const reply = await sendMessage(finalPrompt, !isQuiet, signal); got_reply = true; return reply;