mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Require single quotes
This commit is contained in:
@ -5,17 +5,17 @@ import {
|
||||
eventSource,
|
||||
event_types,
|
||||
saveSettingsDebounced,
|
||||
} from "../script.js";
|
||||
import { extension_settings, saveMetadataDebounced } from "./extensions.js"
|
||||
import { selected_group } from "./group-chats.js";
|
||||
import { getCharaFilename, delay } from "./utils.js";
|
||||
import { power_user } from "./power-user.js";
|
||||
} from '../script.js';
|
||||
import { extension_settings, saveMetadataDebounced } from './extensions.js'
|
||||
import { selected_group } from './group-chats.js';
|
||||
import { getCharaFilename, delay } from './utils.js';
|
||||
import { power_user } from './power-user.js';
|
||||
|
||||
const extensionName = 'cfg';
|
||||
const defaultSettings = {
|
||||
global: {
|
||||
"guidance_scale": 1,
|
||||
"negative_prompt": ''
|
||||
'guidance_scale': 1,
|
||||
'negative_prompt': ''
|
||||
},
|
||||
chara: []
|
||||
};
|
||||
@ -41,13 +41,13 @@ function setCharCfg(tempValue, setting) {
|
||||
|
||||
switch(setting) {
|
||||
case settingType.guidance_scale:
|
||||
tempCharaCfg["guidance_scale"] = Number(tempValue);
|
||||
tempCharaCfg['guidance_scale'] = Number(tempValue);
|
||||
break;
|
||||
case settingType.negative_prompt:
|
||||
tempCharaCfg["negative_prompt"] = tempValue;
|
||||
tempCharaCfg['negative_prompt'] = tempValue;
|
||||
break;
|
||||
case settingType.positive_prompt:
|
||||
tempCharaCfg["positive_prompt"] = tempValue;
|
||||
tempCharaCfg['positive_prompt'] = tempValue;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -79,7 +79,7 @@ function setCharCfg(tempValue, setting) {
|
||||
|
||||
extension_settings.cfg.chara.push(tempCharaCfg);
|
||||
} else {
|
||||
console.debug("Character CFG error: No avatar name key could be found.");
|
||||
console.debug('Character CFG error: No avatar name key could be found.');
|
||||
|
||||
// Don't save settings if something went wrong
|
||||
return false;
|
||||
@ -114,46 +114,46 @@ function setChatCfg(tempValue, setting) {
|
||||
function onCfgMenuItemClick() {
|
||||
if (selected_group || this_chid) {
|
||||
//show CFG config if it's hidden
|
||||
if ($("#cfgConfig").css("display") !== 'flex') {
|
||||
$("#cfgConfig").addClass('resizing')
|
||||
$("#cfgConfig").css("display", "flex");
|
||||
$("#cfgConfig").css("opacity", 0.0);
|
||||
$("#cfgConfig").transition({
|
||||
if ($('#cfgConfig').css('display') !== 'flex') {
|
||||
$('#cfgConfig').addClass('resizing')
|
||||
$('#cfgConfig').css('display', 'flex');
|
||||
$('#cfgConfig').css('opacity', 0.0);
|
||||
$('#cfgConfig').transition({
|
||||
opacity: 1.0,
|
||||
duration: 250,
|
||||
}, async function () {
|
||||
await delay(50);
|
||||
$("#cfgConfig").removeClass('resizing')
|
||||
$('#cfgConfig').removeClass('resizing')
|
||||
});
|
||||
|
||||
//auto-open the main AN inline drawer
|
||||
if ($("#CFGBlockToggle")
|
||||
if ($('#CFGBlockToggle')
|
||||
.siblings('.inline-drawer-content')
|
||||
.css('display') !== 'block') {
|
||||
$("#floatingPrompt").addClass('resizing')
|
||||
$("#CFGBlockToggle").click();
|
||||
$('#floatingPrompt').addClass('resizing')
|
||||
$('#CFGBlockToggle').click();
|
||||
}
|
||||
} else {
|
||||
//hide AN if it's already displayed
|
||||
$("#cfgConfig").addClass('resizing')
|
||||
$("#cfgConfig").transition({
|
||||
$('#cfgConfig').addClass('resizing')
|
||||
$('#cfgConfig').transition({
|
||||
opacity: 0.0,
|
||||
duration: 250,
|
||||
},
|
||||
async function () {
|
||||
await delay(50);
|
||||
$("#cfgConfig").removeClass('resizing')
|
||||
$('#cfgConfig').removeClass('resizing')
|
||||
});
|
||||
setTimeout(function () {
|
||||
$("#cfgConfig").hide();
|
||||
$('#cfgConfig').hide();
|
||||
}, 250);
|
||||
|
||||
}
|
||||
//duplicate options menu close handler from script.js
|
||||
//because this listener takes priority
|
||||
$("#options").stop().fadeOut(250);
|
||||
$('#options').stop().fadeOut(250);
|
||||
} else {
|
||||
toastr.warning(`Select a character before trying to configure CFG`, '', { timeOut: 2000 });
|
||||
toastr.warning('Select a character before trying to configure CFG', '', { timeOut: 2000 });
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,11 +165,11 @@ async function onChatChanged() {
|
||||
// Rearrange the panel if a group chat is present
|
||||
async function modifyCharaHtml() {
|
||||
if (selected_group) {
|
||||
$("#chara_cfg_container").hide();
|
||||
$("#groupchat_cfg_use_chara_container").show();
|
||||
$('#chara_cfg_container').hide();
|
||||
$('#groupchat_cfg_use_chara_container').show();
|
||||
} else {
|
||||
$("#chara_cfg_container").show();
|
||||
$("#groupchat_cfg_use_chara_container").hide();
|
||||
$('#chara_cfg_container').show();
|
||||
$('#groupchat_cfg_use_chara_container').hide();
|
||||
// TODO: Remove chat checkbox here
|
||||
}
|
||||
}
|
||||
@ -185,7 +185,7 @@ function loadSettings() {
|
||||
if (chat_metadata[metadataKeys.prompt_combine]?.length > 0) {
|
||||
chat_metadata[metadataKeys.prompt_combine].forEach((element) => {
|
||||
$(`input[name="cfg_prompt_combine"][value="${element}"]`)
|
||||
.prop("checked", true);
|
||||
.prop('checked', true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -194,12 +194,12 @@ function loadSettings() {
|
||||
const promptSeparator = chat_metadata[metadataKeys.prompt_separator];
|
||||
if (promptSeparator) {
|
||||
promptSeparatorDisplay.push(promptSeparator);
|
||||
if (!promptSeparator.startsWith(`"`)) {
|
||||
promptSeparatorDisplay.unshift(`"`);
|
||||
if (!promptSeparator.startsWith('"')) {
|
||||
promptSeparatorDisplay.unshift('"');
|
||||
}
|
||||
|
||||
if (!promptSeparator.endsWith(`"`)) {
|
||||
promptSeparatorDisplay.push(`"`);
|
||||
if (!promptSeparator.endsWith('"')) {
|
||||
promptSeparatorDisplay.push('"');
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,21 +249,21 @@ function migrateSettings() {
|
||||
performSettingsSave = true;
|
||||
}
|
||||
|
||||
if (chat_metadata["cfg_negative_combine"]) {
|
||||
chat_metadata[metadataKeys.prompt_combine] = chat_metadata["cfg_negative_combine"];
|
||||
chat_metadata["cfg_negative_combine"] = undefined;
|
||||
if (chat_metadata['cfg_negative_combine']) {
|
||||
chat_metadata[metadataKeys.prompt_combine] = chat_metadata['cfg_negative_combine'];
|
||||
chat_metadata['cfg_negative_combine'] = undefined;
|
||||
performMetaSave = true;
|
||||
}
|
||||
|
||||
if (chat_metadata["cfg_negative_insertion_depth"]) {
|
||||
chat_metadata[metadataKeys.prompt_insertion_depth] = chat_metadata["cfg_negative_insertion_depth"];
|
||||
chat_metadata["cfg_negative_insertion_depth"] = undefined;
|
||||
if (chat_metadata['cfg_negative_insertion_depth']) {
|
||||
chat_metadata[metadataKeys.prompt_insertion_depth] = chat_metadata['cfg_negative_insertion_depth'];
|
||||
chat_metadata['cfg_negative_insertion_depth'] = undefined;
|
||||
performMetaSave = true;
|
||||
}
|
||||
|
||||
if (chat_metadata["cfg_negative_separator"]) {
|
||||
chat_metadata[metadataKeys.prompt_separator] = chat_metadata["cfg_negative_separator"];
|
||||
chat_metadata["cfg_negative_separator"] = undefined;
|
||||
if (chat_metadata['cfg_negative_separator']) {
|
||||
chat_metadata[metadataKeys.prompt_separator] = chat_metadata['cfg_negative_separator'];
|
||||
chat_metadata['cfg_negative_separator'] = undefined;
|
||||
performMetaSave = true;
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ function migrateSettings() {
|
||||
// This function is called when the extension is loaded
|
||||
export function initCfg() {
|
||||
$('#CFGClose').on('click', function () {
|
||||
$("#cfgConfig").transition({
|
||||
$('#cfgConfig').transition({
|
||||
opacity: 0,
|
||||
duration: 200,
|
||||
easing: 'ease-in-out',
|
||||
@ -335,9 +335,9 @@ export function initCfg() {
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$(`input[name="cfg_prompt_combine"]`).on('input', function() {
|
||||
const values = $('#cfgConfig').find(`input[name="cfg_prompt_combine"]`)
|
||||
.filter(":checked")
|
||||
$('input[name="cfg_prompt_combine"]').on('input', function() {
|
||||
const values = $('#cfgConfig').find('input[name="cfg_prompt_combine"]')
|
||||
.filter(':checked')
|
||||
.map(function() { return Number($(this).val()) })
|
||||
.get()
|
||||
.filter((e) => !Number.isNaN(e)) || [];
|
||||
@ -346,12 +346,12 @@ export function initCfg() {
|
||||
saveMetadataDebounced();
|
||||
});
|
||||
|
||||
$(`#cfg_prompt_insertion_depth`).on('input', function() {
|
||||
$('#cfg_prompt_insertion_depth').on('input', function() {
|
||||
chat_metadata[metadataKeys.prompt_insertion_depth] = Number($(this).val());
|
||||
saveMetadataDebounced();
|
||||
});
|
||||
|
||||
$(`#cfg_prompt_separator`).on('input', function() {
|
||||
$('#cfg_prompt_separator').on('input', function() {
|
||||
chat_metadata[metadataKeys.prompt_separator] = $(this).val();
|
||||
saveMetadataDebounced();
|
||||
});
|
||||
@ -361,7 +361,7 @@ export function initCfg() {
|
||||
chat_metadata[metadataKeys.groupchat_individual_chars] = checked
|
||||
|
||||
if (checked) {
|
||||
toastr.info("You can edit character CFG values in their respective character chats.");
|
||||
toastr.info('You can edit character CFG values in their respective character chats.');
|
||||
}
|
||||
|
||||
saveMetadataDebounced();
|
||||
@ -388,20 +388,20 @@ export const cfgType = {
|
||||
}
|
||||
|
||||
export const metadataKeys = {
|
||||
guidance_scale: "cfg_guidance_scale",
|
||||
negative_prompt: "cfg_negative_prompt",
|
||||
positive_prompt: "cfg_positive_prompt",
|
||||
prompt_combine: "cfg_prompt_combine",
|
||||
groupchat_individual_chars: "cfg_groupchat_individual_chars",
|
||||
prompt_insertion_depth: "cfg_prompt_insertion_depth",
|
||||
prompt_separator: "cfg_prompt_separator"
|
||||
guidance_scale: 'cfg_guidance_scale',
|
||||
negative_prompt: 'cfg_negative_prompt',
|
||||
positive_prompt: 'cfg_positive_prompt',
|
||||
prompt_combine: 'cfg_prompt_combine',
|
||||
groupchat_individual_chars: 'cfg_groupchat_individual_chars',
|
||||
prompt_insertion_depth: 'cfg_prompt_insertion_depth',
|
||||
prompt_separator: 'cfg_prompt_separator'
|
||||
}
|
||||
|
||||
// Gets the CFG guidance scale
|
||||
// If the guidance scale is 1, ignore the CFG prompt(s) since it won't be used anyways
|
||||
export function getGuidanceScale() {
|
||||
if (!extension_settings.cfg) {
|
||||
console.warn("CFG extension is not enabled. Skipping CFG guidance.");
|
||||
console.warn('CFG extension is not enabled. Skipping CFG guidance.');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -436,7 +436,7 @@ export function getGuidanceScale() {
|
||||
* @returns {string} The CFG prompt separator
|
||||
*/
|
||||
function getCustomSeparator() {
|
||||
const defaultSeparator = "\n";
|
||||
const defaultSeparator = '\n';
|
||||
|
||||
try {
|
||||
if (chat_metadata[metadataKeys.prompt_separator]) {
|
||||
@ -445,7 +445,7 @@ function getCustomSeparator() {
|
||||
|
||||
return defaultSeparator;
|
||||
} catch {
|
||||
console.warn("Invalid JSON detected for prompt separator. Using default separator.");
|
||||
console.warn('Invalid JSON detected for prompt separator. Using default separator.');
|
||||
return defaultSeparator;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user