mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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:
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user