CFG: Add per-chat CFG and fixes

Per-chat CFG applies a CFG setting per-chat only rather than character
or globally. This overrides all other CFG settings (this will be changed).

Also add fixes to remove character CFG entries properly and not to
apply CFG if the scale is 1 as that won't do anything to generation.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-08-11 01:35:22 -04:00
parent 63ee7d4e10
commit 5bb6c89868
3 changed files with 74 additions and 25 deletions

View File

@ -1,18 +1,33 @@
import { chat_metadata } from "../../../script.js";
import { extension_settings } from "../../extensions.js"
import { getCharaFilename } from "../../utils.js";
// TODO: Update to use per-chat and per-character CFG
// Gets the CFG value from hierarchy of chat -> character -> global
// Returns undefined values which should be handled in the respective backend APIs
// If the guidance scale is 1, ignore the CFG negative prompt since it won't be used anyways
// TODO: Add the ability to combine negative prompts if specified. Proposed, chat + global and chat + chara
// TODO: Add groupchat support and fetch the CFG values for the current character
export function getCfg() {
if (chat_metadata['guidance_scale'] !== 1) {
return {
guidanceScale: chat_metadata['guidance_scale'],
negativePrompt: chat_metadata['negative_prompt']
}
}
const charaCfg = extension_settings.cfg.chara.find((e) => e.name === getCharaFilename());
if (charaCfg && charaCfg?.useChara) {
return {
guidanceScale: charaCfg.guidance_scale ?? 1.00,
negativePrompt: charaCfg.negative_prompt ?? ''
if (charaCfg.guidance_scale !== 1) {
return {
guidanceScale: charaCfg.guidance_scale,
negativePrompt: charaCfg.negative_prompt
}
}
} else {
return {
guidanceScale: extension_settings.cfg.global.guidance_scale ?? 1.00,
negativePrompt: extension_settings.cfg.global.negative_prompt ?? ''
} else if (extension_settings.cfg.global?.guidance_scale !== 1) {
return {
guidanceScale: extension_settings.cfg.global.guidance_scale,
negativePrompt: extension_settings.cfg.global.negative_prompt
}
}
}