From 046037564789c6a045c8b598ed5435ec55c04482 Mon Sep 17 00:00:00 2001 From: kingbri Date: Wed, 23 Aug 2023 11:27:58 -0400 Subject: [PATCH] CFG: Don't inject anything when guidance scale doesn't exist If the guidance scale is 1, completely disable sending CFG and creating a negative prompt. Signed-off-by: kingbri --- public/script.js | 8 +++++++- public/scripts/extensions/cfg/index.js | 2 +- public/scripts/extensions/cfg/util.js | 10 ++++++---- public/scripts/textgen-settings.js | 4 ---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/public/script.js b/public/script.js index 27ce9a3ba..51d68ecb1 100644 --- a/public/script.js +++ b/public/script.js @@ -2741,6 +2741,12 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, // Fetches the combined prompt for both negative and positive prompts const cfgGuidanceScale = getGuidanceScale(); function getCombinedPrompt(isNegative) { + // Only return if the guidance scale doesn't exist or the value is 1 + // Also don't return if constructing the neutral prompt + if (isNegative && (!cfgGuidanceScale || cfgGuidanceScale?.value === 1)) { + return; + } + let finalMesSend = [...mesSend]; let cfgPrompt = {}; if (cfgGuidanceScale && cfgGuidanceScale?.value !== 1) { @@ -2754,7 +2760,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, ? cfgPrompt.value : ` ${cfgPrompt.value}`; } else { - // TODO: Switch from splice method to insertion depth method + // TODO: Make all extension prompts use an array/splice method finalMesSend.splice(mesSend.length - cfgPrompt.depth, 0, `${cfgPrompt.value}\n`); } } diff --git a/public/scripts/extensions/cfg/index.js b/public/scripts/extensions/cfg/index.js index c850ca6d6..f572d2c63 100644 --- a/public/scripts/extensions/cfg/index.js +++ b/public/scripts/extensions/cfg/index.js @@ -348,7 +348,7 @@ jQuery(async () => { .filter(":checked") .map(function() { return parseInt($(this).val()) }) .get() - .filter((e) => e !== NaN) || []; + .filter((e) => !Number.isNaN(e)) || []; chat_metadata[metadataKeys.prompt_combine] = values; saveMetadataDebounced(); diff --git a/public/scripts/extensions/cfg/util.js b/public/scripts/extensions/cfg/util.js index 850978884..6e156d5d9 100644 --- a/public/scripts/extensions/cfg/util.js +++ b/public/scripts/extensions/cfg/util.js @@ -39,10 +39,12 @@ export function getGuidanceScale() { }; } - return { - type: cfgType.global, - value: extension_settings.cfg.global.guidance_scale - }; + if (extension_settings.cfg.global && extension_settings.cfg.global?.guidance_scale !== 1) { + return { + type: cfgType.global, + value: extension_settings.cfg.global.guidance_scale + }; + } } // Gets the CFG prompt diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index b78347bab..9a921d316 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -234,10 +234,6 @@ async function generateTextGenWithStreaming(generate_data, signal) { } export function getTextGenGenerationData(finalPrompt, this_amount_gen, isImpersonate, cfgValues) { - if (cfgValues?.guidanceScale?.value === 1) { - cfgValues = null; - } - return { 'prompt': finalPrompt, 'max_new_tokens': this_amount_gen,