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.
This commit is contained in:
valadaptive
2024-04-25 09:00:18 -04:00
parent 2a0497ca9e
commit dbcc75471f

View File

@ -3800,22 +3800,20 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu
// Deep clone // Deep clone
let finalMesSend = structuredClone(mesSend); let finalMesSend = structuredClone(mesSend);
let cfgPrompt = {};
if (useCfgPrompt) { if (useCfgPrompt) {
cfgPrompt = getCfgPrompt(cfgGuidanceScale, isNegative); const cfgPrompt = getCfgPrompt(cfgGuidanceScale, isNegative);
} if (cfgPrompt.value) {
if (cfgPrompt.depth === 0) {
if (cfgPrompt && cfgPrompt.value) { finalMesSend[finalMesSend.length - 1].message +=
if (cfgPrompt.depth === 0) { /\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1))
finalMesSend[finalMesSend.length - 1].message += ? cfgPrompt.value
/\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1)) : ` ${cfgPrompt.value}`;
? cfgPrompt.value } else {
: ` ${cfgPrompt.value}`; // TODO: Make all extension prompts use an array/splice method
} else { const lengthDiff = mesSend.length - cfgPrompt.depth;
// TODO: Make all extension prompts use an array/splice method const cfgDepth = lengthDiff >= 0 ? lengthDiff : 0;
const lengthDiff = mesSend.length - cfgPrompt.depth; finalMesSend[cfgDepth].extensionPrompts.push(`${cfgPrompt.value}\n`);
const cfgDepth = lengthDiff >= 0 ? lengthDiff : 0; }
finalMesSend[cfgDepth].extensionPrompts.push(`${cfgPrompt.value}\n`);
} }
} }