From dbcc75471f06dc3cbbbf07dd9b4d4c64041ec95e Mon Sep 17 00:00:00 2001 From: valadaptive Date: Thu, 25 Apr 2024 09:00:18 -0400 Subject: [PATCH] Refactor CFG prompt gen in getCombinedPrompt We don't need to create the cfgPrompt variable unless useCfgPrompt is true, so move it inside the if-block. --- public/script.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/public/script.js b/public/script.js index 6218262da..24f189a8d 100644 --- a/public/script.js +++ b/public/script.js @@ -3800,22 +3800,20 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu // Deep clone let finalMesSend = structuredClone(mesSend); - let cfgPrompt = {}; if (useCfgPrompt) { - cfgPrompt = getCfgPrompt(cfgGuidanceScale, isNegative); - } - - if (cfgPrompt && cfgPrompt.value) { - if (cfgPrompt.depth === 0) { - finalMesSend[finalMesSend.length - 1].message += - /\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1)) - ? cfgPrompt.value - : ` ${cfgPrompt.value}`; - } else { - // TODO: Make all extension prompts use an array/splice method - const lengthDiff = mesSend.length - cfgPrompt.depth; - const cfgDepth = lengthDiff >= 0 ? lengthDiff : 0; - finalMesSend[cfgDepth].extensionPrompts.push(`${cfgPrompt.value}\n`); + const cfgPrompt = getCfgPrompt(cfgGuidanceScale, isNegative); + if (cfgPrompt.value) { + if (cfgPrompt.depth === 0) { + finalMesSend[finalMesSend.length - 1].message += + /\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1)) + ? cfgPrompt.value + : ` ${cfgPrompt.value}`; + } else { + // TODO: Make all extension prompts use an array/splice method + const lengthDiff = mesSend.length - cfgPrompt.depth; + const cfgDepth = lengthDiff >= 0 ? lengthDiff : 0; + finalMesSend[cfgDepth].extensionPrompts.push(`${cfgPrompt.value}\n`); + } } }