mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Migrate advanced formatting settings to settings.json
This commit is contained in:
@ -39,16 +39,9 @@ import {
|
||||
} from "./scripts/group-chats.js";
|
||||
|
||||
import {
|
||||
force_pygmalion_formatting,
|
||||
collapse_newlines,
|
||||
pin_examples,
|
||||
collapseNewlines,
|
||||
disable_description_formatting,
|
||||
disable_personality_formatting,
|
||||
disable_scenario_formatting,
|
||||
always_force_name2,
|
||||
custom_chat_separator,
|
||||
multigen,
|
||||
loadPowerUserSettings,
|
||||
power_user,
|
||||
} from "./scripts/power-user.js";
|
||||
|
||||
import {
|
||||
@ -479,7 +472,7 @@ async function getStatus() {
|
||||
if (online_status == undefined) {
|
||||
online_status = "no_connection";
|
||||
}
|
||||
if (online_status.toLowerCase().indexOf("pygmalion") != -1 || (online_status !== "no_connection" && force_pygmalion_formatting)) {
|
||||
if (online_status.toLowerCase().indexOf("pygmalion") != -1 || (online_status !== "no_connection" && power_user.force_pygmalion_formatting)) {
|
||||
is_pygmalion = true;
|
||||
online_status += " (Pyg. formatting on)";
|
||||
} else {
|
||||
@ -1071,7 +1064,7 @@ function baseChatReplace(value, name1, name2) {
|
||||
value = value.replace(/<USER>/gi, name1);
|
||||
value = value.replace(/<BOT>/gi, name2);
|
||||
|
||||
if (collapse_newlines) {
|
||||
if (power_user.collapse_newlines) {
|
||||
value = collapseNewlines(value);
|
||||
}
|
||||
}
|
||||
@ -1222,12 +1215,12 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
}
|
||||
|
||||
if (is_pygmalion) {
|
||||
storyString += appendToStoryString(charDescription, disable_description_formatting ? '' : name2 + "'s Persona: ");
|
||||
storyString += appendToStoryString(charPersonality, disable_personality_formatting ? '' : 'Personality: ');
|
||||
storyString += appendToStoryString(Scenario, disable_scenario_formatting ? '' : 'Scenario: ');
|
||||
storyString += appendToStoryString(charDescription, power_user.disable_description_formatting ? '' : name2 + "'s Persona: ");
|
||||
storyString += appendToStoryString(charPersonality, power_user.disable_personality_formatting ? '' : 'Personality: ');
|
||||
storyString += appendToStoryString(Scenario, power_user.disable_scenario_formatting ? '' : 'Scenario: ');
|
||||
} else {
|
||||
if (charDescription !== undefined) {
|
||||
if (charPersonality.length > 0 && !disable_personality_formatting) {
|
||||
if (charPersonality.length > 0 && !power_user.disable_personality_formatting) {
|
||||
charPersonality = name2 + "'s personality: " + charPersonality;
|
||||
}
|
||||
}
|
||||
@ -1243,13 +1236,13 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
}
|
||||
}
|
||||
|
||||
if (custom_chat_separator && custom_chat_separator.length) {
|
||||
if (power_user.custom_chat_separator && power_user.custom_chat_separator.length) {
|
||||
for (let i = 0; i < mesExamplesArray.length; i++) {
|
||||
mesExamplesArray[i] = mesExamplesArray[i].replace(/<START>/gi, custom_chat_separator);
|
||||
mesExamplesArray[i] = mesExamplesArray[i].replace(/<START>/gi, power_user.custom_chat_separator);
|
||||
}
|
||||
}
|
||||
|
||||
if (pin_examples && main_api !== 'openai') {
|
||||
if (power_user.pin_examples && main_api !== 'openai') {
|
||||
for (let example of mesExamplesArray) {
|
||||
if (!is_pygmalion) {
|
||||
if (!storyString.endsWith('\n')) {
|
||||
@ -1262,7 +1255,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
}
|
||||
|
||||
// Pygmalion does that anyway
|
||||
if (always_force_name2 && !is_pygmalion) {
|
||||
if (power_user.always_force_name2 && !is_pygmalion) {
|
||||
force_name2 = true;
|
||||
}
|
||||
|
||||
@ -1382,7 +1375,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
count_exm_add = 0;
|
||||
|
||||
if (i === chat2.length - 1) {
|
||||
if (!pin_examples) {
|
||||
if (!power_user.pin_examples) {
|
||||
let mesExmString = '';
|
||||
for (let iii = 0; iii < mesExamplesArray.length; iii++) {
|
||||
mesExmString += mesExamplesArray[iii];
|
||||
@ -1402,7 +1395,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
if (!storyString.endsWith('\n')) {
|
||||
storyString += '\n';
|
||||
}
|
||||
storyString += !disable_scenario_formatting ? `Circumstances and context of the dialogue: ${Scenario}\n` : `${Scenario}\n`;
|
||||
storyString += !power_user.disable_scenario_formatting ? `Circumstances and context of the dialogue: ${Scenario}\n` : `${Scenario}\n`;
|
||||
}
|
||||
console.log('calling runGenerate');
|
||||
await runGenerate();
|
||||
@ -1535,8 +1528,8 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
}
|
||||
|
||||
// add a custom dingus (if defined)
|
||||
if (custom_chat_separator && custom_chat_separator.length) {
|
||||
mesSendString = custom_chat_separator + '\n' + mesSendString;
|
||||
if (power_user.custom_chat_separator && power_user.custom_chat_separator.length) {
|
||||
mesSendString = power_user.custom_chat_separator + '\n' + mesSendString;
|
||||
}
|
||||
// add non-pygma dingus
|
||||
else if (!is_pygmalion) {
|
||||
@ -1568,7 +1561,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
|
||||
finalPromt = finalPromt.replace(/\r/gm, '');
|
||||
|
||||
if (collapse_newlines) {
|
||||
if (power_user.collapse_newlines) {
|
||||
finalPromt = collapseNewlines(finalPromt);
|
||||
}
|
||||
|
||||
@ -1733,7 +1726,7 @@ async function Generate(type, automatic_trigger, force_name2) {
|
||||
getMessage = data;
|
||||
}
|
||||
|
||||
if (collapse_newlines) {
|
||||
if (power_user.collapse_newlines) {
|
||||
getMessage = collapseNewlines(getMessage);
|
||||
}
|
||||
|
||||
@ -1875,7 +1868,7 @@ function saveReply(type, getMessage, this_mes_is_name) {
|
||||
}
|
||||
|
||||
function isMultigenEnabled() {
|
||||
return multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel');
|
||||
return power_user.multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel');
|
||||
}
|
||||
|
||||
function activateSendButtons() {
|
||||
@ -2331,6 +2324,9 @@ async function getSettings(type) {
|
||||
// Horde
|
||||
loadHordeSettings(settings);
|
||||
|
||||
// Load power user settings
|
||||
loadPowerUserSettings(settings);
|
||||
|
||||
//Enable GUI deference settings if GUI is selected for Kobold
|
||||
if (main_api === "kobold") {
|
||||
if (preset_settings == "gui") {
|
||||
@ -2427,6 +2423,7 @@ async function saveSettings(type) {
|
||||
textgenerationwebui_settings: textgenerationwebui_settings,
|
||||
swipes: swipes,
|
||||
horde_settings: horde_settings,
|
||||
power_user: power_user,
|
||||
...nai_settings,
|
||||
...kai_settings,
|
||||
...oai_settings,
|
||||
|
@ -15,8 +15,7 @@ import {
|
||||
} from "../script.js";
|
||||
|
||||
import {
|
||||
fast_ui_mode,
|
||||
pin_examples,
|
||||
power_user,
|
||||
} from "./power-user.js";
|
||||
|
||||
import { LoadLocal, SaveLocal, ClearLocal, CheckLocal, LoadLocalBool } from "./f-localStorage.js";
|
||||
@ -156,7 +155,7 @@ function RA_CountCharTokens() {
|
||||
characters[this_chid].description +
|
||||
characters[this_chid].personality +
|
||||
characters[this_chid].scenario +
|
||||
(pin_examples ? characters[this_chid].mes_example : '') // add examples to permanent if they are pinned
|
||||
(power_user.pin_examples ? characters[this_chid].mes_example : '') // add examples to permanent if they are pinned
|
||||
)).length;
|
||||
} else { console.log("RA_TC -- no valid char found, closing."); } // if neither, probably safety char or some error in loading
|
||||
}
|
||||
@ -206,7 +205,7 @@ function RA_checkOnlineStatus() {
|
||||
} else {
|
||||
if (online_status !== undefined && online_status !== "no_connection") {
|
||||
$("#send_textarea").attr("placeholder", "Type a message..."); //on connect, placeholder tells user to type message
|
||||
const formColor = fast_ui_mode ? "var(--black90a)" : "var(--black60a)";
|
||||
const formColor = power_user.fast_ui_mode ? "var(--black90a)" : "var(--black60a)";
|
||||
$("#send_form").css("background-color", formColor); //on connect, form BG changes to transprent black
|
||||
$("#API-status-top").removeClass("redOverlayGlow");
|
||||
connection_made = true;
|
||||
|
@ -25,7 +25,7 @@ import {
|
||||
import { groups, selected_group } from "./group-chats.js";
|
||||
|
||||
import {
|
||||
pin_examples,
|
||||
power_user,
|
||||
} from "./power-user.js";
|
||||
|
||||
import {
|
||||
@ -294,7 +294,7 @@ async function prepareOpenAIMessages(name2, storyString, worldInfoBefore, worldI
|
||||
}
|
||||
|
||||
// The user wants to always have all example messages in the context
|
||||
if (pin_examples) {
|
||||
if (power_user.pin_examples) {
|
||||
// first we send *all* example messages
|
||||
// we don't check their token size since if it's bigger than the context, the user is fucked anyway
|
||||
// and should've have selected that option (maybe have some warning idk, too hard to add)
|
||||
|
@ -1,28 +1,24 @@
|
||||
import { saveSettingsDebounced } from "../script.js";
|
||||
|
||||
export {
|
||||
loadPowerUserSettings,
|
||||
collapseNewlines,
|
||||
collapse_newlines,
|
||||
force_pygmalion_formatting,
|
||||
pin_examples,
|
||||
disable_description_formatting,
|
||||
disable_scenario_formatting,
|
||||
disable_personality_formatting,
|
||||
always_force_name2,
|
||||
custom_chat_separator,
|
||||
fast_ui_mode,
|
||||
multigen,
|
||||
power_user,
|
||||
};
|
||||
|
||||
let collapse_newlines = false;
|
||||
let force_pygmalion_formatting = false;
|
||||
let pin_examples = false;
|
||||
let disable_description_formatting = false;
|
||||
let disable_scenario_formatting = false;
|
||||
let disable_personality_formatting = false;
|
||||
let always_force_name2 = false;
|
||||
let fast_ui_mode = false;
|
||||
let multigen = false;
|
||||
let avatar_style = 0;
|
||||
let custom_chat_separator = '';
|
||||
let power_user = {
|
||||
collapse_newlines: false,
|
||||
force_pygmalion_formatting: false,
|
||||
pin_examples: false,
|
||||
disable_description_formatting: false,
|
||||
disable_scenario_formatting: false,
|
||||
disable_personality_formatting: false,
|
||||
always_force_name2: false,
|
||||
multigen: false,
|
||||
custom_chat_separator: '',
|
||||
fast_ui_mode: false,
|
||||
avatar_style: 0,
|
||||
};
|
||||
|
||||
const storage_keys = {
|
||||
collapse_newlines: "TavernAI_collapse_newlines",
|
||||
@ -43,8 +39,8 @@ function collapseNewlines(x) {
|
||||
}
|
||||
|
||||
function switchUiMode() {
|
||||
fast_ui_mode = localStorage.getItem(storage_keys.fast_ui_mode) == "true";
|
||||
if (fast_ui_mode) {
|
||||
power_user.fast_ui_mode = localStorage.getItem(storage_keys.fast_ui_mode) == "true";
|
||||
if (power_user.fast_ui_mode) {
|
||||
$("body").addClass("no-blur");
|
||||
}
|
||||
else {
|
||||
@ -53,8 +49,8 @@ function switchUiMode() {
|
||||
}
|
||||
|
||||
function applyAvatarStyle() {
|
||||
avatar_style = Number(localStorage.getItem(storage_keys.avatar_style) ?? 0);
|
||||
switch (avatar_style) {
|
||||
power_user.avatar_style = Number(localStorage.getItem(storage_keys.avatar_style) ?? 0);
|
||||
switch (power_user.avatar_style) {
|
||||
case 0:
|
||||
$("body").removeClass("big-avatars");
|
||||
break;
|
||||
@ -67,90 +63,101 @@ function applyAvatarStyle() {
|
||||
applyAvatarStyle();
|
||||
switchUiMode();
|
||||
|
||||
function loadPowerUserSettings() {
|
||||
collapse_newlines = localStorage.getItem(storage_keys.collapse_newlines) == "true";
|
||||
force_pygmalion_formatting = localStorage.getItem(storage_keys.force_pygmalion_formatting) == "true";
|
||||
pin_examples = localStorage.getItem(storage_keys.pin_examples) == "true";
|
||||
disable_description_formatting = localStorage.getItem(storage_keys.disable_description_formatting) == "true";
|
||||
disable_scenario_formatting = localStorage.getItem(storage_keys.disable_scenario_formatting) == "true";
|
||||
disable_personality_formatting = localStorage.getItem(storage_keys.disable_personality_formatting) == "true";
|
||||
always_force_name2 = localStorage.getItem(storage_keys.always_force_name2) == "true";
|
||||
custom_chat_separator = localStorage.getItem(storage_keys.custom_chat_separator);
|
||||
fast_ui_mode = localStorage.getItem(storage_keys.fast_ui_mode) == "true";
|
||||
multigen = localStorage.getItem(storage_keys.multigen) == "true";
|
||||
avatar_style = Number(localStorage.getItem(storage_keys.avatar_style) ?? 0);
|
||||
// TODO delete in next release
|
||||
function loadFromLocalStorage() {
|
||||
power_user.collapse_newlines = localStorage.getItem(storage_keys.collapse_newlines) == "true";
|
||||
power_user.force_pygmalion_formatting = localStorage.getItem(storage_keys.force_pygmalion_formatting) == "true";
|
||||
power_user.pin_examples = localStorage.getItem(storage_keys.pin_examples) == "true";
|
||||
power_user.disable_description_formatting = localStorage.getItem(storage_keys.disable_description_formatting) == "true";
|
||||
power_user.disable_scenario_formatting = localStorage.getItem(storage_keys.disable_scenario_formatting) == "true";
|
||||
power_user.disable_personality_formatting = localStorage.getItem(storage_keys.disable_personality_formatting) == "true";
|
||||
power_user.always_force_name2 = localStorage.getItem(storage_keys.always_force_name2) == "true";
|
||||
power_user.custom_chat_separator = localStorage.getItem(storage_keys.custom_chat_separator);
|
||||
power_user.multigen = localStorage.getItem(storage_keys.multigen) == "true";
|
||||
}
|
||||
|
||||
$("#force-pygmalion-formatting-checkbox").prop("checked", force_pygmalion_formatting);
|
||||
$("#collapse-newlines-checkbox").prop("checked", collapse_newlines);
|
||||
$("#pin-examples-checkbox").prop("checked", pin_examples);
|
||||
$("#disable-description-formatting-checkbox").prop("checked", disable_description_formatting);
|
||||
$("#disable-scenario-formatting-checkbox").prop("checked", disable_scenario_formatting);
|
||||
$("#disable-personality-formatting-checkbox").prop("checked", disable_personality_formatting);
|
||||
$("#always-force-name2-checkbox").prop("checked", always_force_name2);
|
||||
$("#custom_chat_separator").val(custom_chat_separator);
|
||||
$("#fast_ui_mode").prop("checked", fast_ui_mode);
|
||||
$("#multigen").prop("checked", multigen);
|
||||
$(`input[name="avatar_style"][value="${avatar_style}"]`).prop("checked", true);
|
||||
function loadPowerUserSettings(settings) {
|
||||
// Migrate legacy settings
|
||||
loadFromLocalStorage();
|
||||
|
||||
// Now do it properly from settings.json
|
||||
if (settings.power_user !== undefined) {
|
||||
Object.assign(power_user, settings.power_user);
|
||||
}
|
||||
|
||||
// These are still local storage
|
||||
power_user.fast_ui_mode = localStorage.getItem(storage_keys.fast_ui_mode) == "true";
|
||||
power_user.avatar_style = Number(localStorage.getItem(storage_keys.avatar_style) ?? 0);
|
||||
|
||||
$("#force-pygmalion-formatting-checkbox").prop("checked", power_user.force_pygmalion_formatting);
|
||||
$("#collapse-newlines-checkbox").prop("checked", power_user.collapse_newlines);
|
||||
$("#pin-examples-checkbox").prop("checked", power_user.pin_examples);
|
||||
$("#disable-description-formatting-checkbox").prop("checked", power_user.disable_description_formatting);
|
||||
$("#disable-scenario-formatting-checkbox").prop("checked", power_user.disable_scenario_formatting);
|
||||
$("#disable-personality-formatting-checkbox").prop("checked", power_user.disable_personality_formatting);
|
||||
$("#always-force-name2-checkbox").prop("checked", power_user.always_force_name2);
|
||||
$("#custom_chat_separator").val(power_user.custom_chat_separator);
|
||||
$("#fast_ui_mode").prop("checked", power_user.fast_ui_mode);
|
||||
$("#multigen").prop("checked", power_user.multigen);
|
||||
$(`input[name="avatar_style"][value="${power_user.avatar_style}"]`).prop("checked", true);
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
// Auto-load from local storage
|
||||
loadPowerUserSettings();
|
||||
|
||||
// Settings that go to settings.json
|
||||
$("#collapse-newlines-checkbox").change(function () {
|
||||
collapse_newlines = !!$(this).prop("checked");
|
||||
localStorage.setItem(storage_keys.collapse_newlines, collapse_newlines);
|
||||
power_user.collapse_newlines = !!$(this).prop("checked");
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$("#force-pygmalion-formatting-checkbox").change(function () {
|
||||
force_pygmalion_formatting = !!$(this).prop("checked");
|
||||
localStorage.setItem(storage_keys.force_pygmalion_formatting, force_pygmalion_formatting);
|
||||
power_user.force_pygmalion_formatting = !!$(this).prop("checked");
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$("#pin-examples-checkbox").change(function () {
|
||||
pin_examples = !!$(this).prop("checked");
|
||||
localStorage.setItem(storage_keys.pin_examples, pin_examples);
|
||||
power_user.pin_examples = !!$(this).prop("checked");
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$("#disable-description-formatting-checkbox").change(function () {
|
||||
disable_description_formatting = !!$(this).prop('checked');
|
||||
localStorage.setItem(storage_keys.disable_description_formatting, disable_description_formatting);
|
||||
power_user.disable_description_formatting = !!$(this).prop('checked');
|
||||
saveSettingsDebounced();
|
||||
})
|
||||
|
||||
$("#disable-scenario-formatting-checkbox").change(function () {
|
||||
disable_scenario_formatting = !!$(this).prop('checked');
|
||||
localStorage.setItem(storage_keys.disable_scenario_formatting, disable_scenario_formatting);
|
||||
power_user.disable_scenario_formatting = !!$(this).prop('checked');
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$("#disable-personality-formatting-checkbox").change(function () {
|
||||
disable_personality_formatting = !!$(this).prop('checked');
|
||||
localStorage.setItem(storage_keys.disable_personality_formatting, disable_personality_formatting);
|
||||
power_user.disable_personality_formatting = !!$(this).prop('checked');
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$("#always-force-name2-checkbox").change(function () {
|
||||
always_force_name2 = !!$(this).prop("checked");
|
||||
localStorage.setItem(storage_keys.always_force_name2, always_force_name2);
|
||||
power_user.always_force_name2 = !!$(this).prop("checked");
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$("#custom_chat_separator").on('input', function() {
|
||||
custom_chat_separator = $(this).val();
|
||||
localStorage.setItem(storage_keys.custom_chat_separator, custom_chat_separator);
|
||||
power_user.custom_chat_separator = $(this).val();
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
$("#multigen").change(function () {
|
||||
power_user.multigen = $(this).prop("checked");
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
// Settings that go to local storage
|
||||
$("#fast_ui_mode").change(function () {
|
||||
fast_ui_mode = $(this).prop("checked");
|
||||
localStorage.setItem(storage_keys.fast_ui_mode, fast_ui_mode);
|
||||
power_user.fast_ui_mode = $(this).prop("checked");
|
||||
localStorage.setItem(storage_keys.fast_ui_mode, power_user.fast_ui_mode);
|
||||
switchUiMode();
|
||||
});
|
||||
|
||||
$("#multigen").change(function () {
|
||||
multigen = $(this).prop("checked");
|
||||
localStorage.setItem(storage_keys.multigen, multigen);
|
||||
});
|
||||
|
||||
$(`input[name="avatar_style"]`).on('input', function (e) {
|
||||
avatar_style = Number(e.target.value);
|
||||
localStorage.setItem(storage_keys.avatar_style, avatar_style);
|
||||
power_user.avatar_style = Number(e.target.value);
|
||||
localStorage.setItem(storage_keys.avatar_style, power_user.avatar_style);
|
||||
applyAvatarStyle();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user