From 25c7686462e91a44582efc660827a779b54920bc Mon Sep 17 00:00:00 2001 From: kingbri Date: Tue, 22 Aug 2023 10:17:20 -0400 Subject: [PATCH] CFG: Pass entire guidance object If an API doesn't use the negative prompt from generate, allow the negative prompt to be refetched in the specific API. This requires the full guidance scale object instead of just the number. Signed-off-by: kingbri --- public/script.js | 4 +++- public/scripts/nai-settings.js | 4 ++-- public/scripts/textgen-settings.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/public/script.js b/public/script.js index a0d37f792..fd5bb63b5 100644 --- a/public/script.js +++ b/public/script.js @@ -2975,8 +2975,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, // Get the negative prompt first since it has the unmodified mesSend array let negativePrompt = main_api == 'textgenerationwebui' ? getCombinedPrompt(true) : undefined; let finalPromt = getCombinedPrompt(false); + + // Include the entire guidance scale object const cfgValues = { - guidanceScale: cfgGuidanceScale?.value, + guidanceScale: cfgGuidanceScale, negativePrompt: negativePrompt }; diff --git a/public/scripts/nai-settings.js b/public/scripts/nai-settings.js index 85d470c4f..6d5a9d0bc 100644 --- a/public/scripts/nai-settings.js +++ b/public/scripts/nai-settings.js @@ -396,7 +396,7 @@ function getBadWordPermutations(text) { } export function getNovelGenerationData(finalPrompt, this_settings, this_amount_gen, isImpersonate, cfgValues) { - if (cfgValues.guidanceScale && cfgValues.guidanceScale !== 1) { + if (cfgValues.guidanceScale && cfgValues.guidanceScale?.value !== 1) { cfgValues.negativePrompt = (getCfgPrompt(cfgValues.guidanceScale, true))?.value; } @@ -440,7 +440,7 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g "typical_p": parseFloat(nai_settings.typical_p), "mirostat_lr": parseFloat(nai_settings.mirostat_lr), "mirostat_tau": parseFloat(nai_settings.mirostat_tau), - "cfg_scale": cfgValues?.guidanceScale ?? parseFloat(nai_settings.cfg_scale), + "cfg_scale": cfgValues?.guidanceScale?.value ?? parseFloat(nai_settings.cfg_scale), "cfg_uc": cfgValues?.negativePrompt ?? nai_settings.cfg_uc ?? "", "phrase_rep_pen": nai_settings.phrase_rep_pen, "stop_sequences": stopSequences, diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index d61d0dd25..5e41ff2c0 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -251,7 +251,7 @@ export function getTextGenGenerationData(finalPromt, this_amount_gen, isImperson 'penalty_alpha': textgenerationwebui_settings.penalty_alpha, 'length_penalty': textgenerationwebui_settings.length_penalty, 'early_stopping': textgenerationwebui_settings.early_stopping, - 'guidance_scale': isImpersonate ? 1 : cfgValues?.guidanceScale ?? textgenerationwebui_settings.guidance_scale ?? 1, + 'guidance_scale': isImpersonate ? 1 : cfgValues?.guidanceScale?.value ?? textgenerationwebui_settings.guidance_scale ?? 1, 'negative_prompt': isImpersonate ? '' : cfgValues?.negativePrompt ?? textgenerationwebui_settings.negative_prompt ?? '', 'seed': textgenerationwebui_settings.seed, 'add_bos_token': textgenerationwebui_settings.add_bos_token,