CFG: Add insertion depth and custom separator

Insertion depth allows for CFG to variably inject itself into the
negative prompt. This is similar to how Author's note works.

However, this method of insertion depth conflicts with AN and
world info where negatives can be meshed between two lines
of those specific insertions.

A custom separator must be wrapped in quotes, otherwise the default
separator is a newline for negative cascading.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-08-19 01:19:22 -04:00
parent cdbca6d9fd
commit 7191f7a8ad
6 changed files with 79 additions and 45 deletions

View File

@ -182,6 +182,24 @@ function loadSettings() {
});
}
// Display the negative separator in quotes if not quoted already
let negativeSeparatorDisplay = [];
const negativeSeparator = chat_metadata[metadataKeys.negative_separator];
if (negativeSeparator) {
negativeSeparatorDisplay.push(negativeSeparator);
if (!negativeSeparator.startsWith(`"`)) {
negativeSeparatorDisplay.unshift(`"`);
}
if (!negativeSeparator.endsWith(`"`)) {
negativeSeparatorDisplay.push(`"`);
}
}
$('#cfg_negative_separator').val(negativeSeparatorDisplay.length === 0 ? '' : negativeSeparatorDisplay.join(''));
$('#cfg_negative_insertion_depth').val(chat_metadata[metadataKeys.negative_insertion_depth] ?? 1);
// Set character CFG if it exists
if (!selected_group) {
const charaCfg = extension_settings.cfg.chara.find((e) => e.name === getCharaFilename());
@ -273,7 +291,6 @@ jQuery(async () => {
saveSettingsDebounced();
});
// TODO: Add negative insertion depth
windowHtml.find('#global_cfg_negative_prompt').on('input', function() {
extension_settings.cfg.global.negative_prompt = $(this).val();
saveSettingsDebounced();
@ -290,6 +307,16 @@ jQuery(async () => {
saveMetadataDebounced();
});
windowHtml.find(`#cfg_negative_insertion_depth`).on('input', function() {
chat_metadata[metadataKeys.negative_insertion_depth] = Number($(this).val());
saveMetadataDebounced();
});
windowHtml.find(`#cfg_negative_separator`).on('input', function() {
chat_metadata[metadataKeys.negative_separator] = $(this).val();
saveMetadataDebounced();
});
windowHtml.find('#groupchat_cfg_use_chara').on('input', function() {
const checked = !!$(this).prop('checked');
chat_metadata[metadataKeys.groupchat_individual_chars] = checked