Presets: Add power user setting support
Settings such as adding character name, stopping strings, etc can be preset specific. This change is mainly inspired because people (like myself) often forget to change these settings after switching a preset, which can cause weird responses from the model. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
5c6343e85e
commit
6e4236d5ee
|
@ -41,6 +41,7 @@ export {
|
||||||
fixMarkdown,
|
fixMarkdown,
|
||||||
power_user,
|
power_user,
|
||||||
send_on_enter_options,
|
send_on_enter_options,
|
||||||
|
getContextSettings,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MAX_CONTEXT_DEFAULT = 4096;
|
export const MAX_CONTEXT_DEFAULT = 4096;
|
||||||
|
@ -249,6 +250,24 @@ const storage_keys = {
|
||||||
expand_message_actions: 'ExpandMessageActions',
|
expand_message_actions: 'ExpandMessageActions',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const contextControls = [
|
||||||
|
// Power user context scoped settings
|
||||||
|
{ id: "context_story_string", property: "story_string", isCheckbox: false, isGlobalSetting: false },
|
||||||
|
{ id: "context_example_separator", property: "example_separator", isCheckbox: false, isGlobalSetting: false },
|
||||||
|
{ id: "context_chat_start", property: "chat_start", isCheckbox: false, isGlobalSetting: false },
|
||||||
|
|
||||||
|
// Existing power user settings
|
||||||
|
{ id: "always-force-name2-checkbox", property: "always_force_name2", isCheckbox: true, isGlobalSetting: true },
|
||||||
|
{ id: "pin-examples-checkbox", property: "pin_examples", isCheckbox: true, isGlobalSetting: true },
|
||||||
|
{ id: "remove-examples-checkbox", property: "strip_examples", isCheckbox: true, isGlobalSetting: true },
|
||||||
|
{ id: "collapse-newlines-checkbox", property: "collapse_newlines", isCheckbox: true, isGlobalSetting: true },
|
||||||
|
{ id: "trim_spaces", property: "trim_spaces", isCheckbox: true, isGlobalSetting: true },
|
||||||
|
{ id: "trim_sentences_checkbox", property: "trim_sentences", isCheckbox: true, isGlobalSetting: true },
|
||||||
|
{ id: "include_newline_checkbox", property: "include_newline", isCheckbox: true, isGlobalSetting: true },
|
||||||
|
{ id: "custom_stopping_strings", property: "custom_stopping_strings", isCheckbox: false, isGlobalSetting: true },
|
||||||
|
{ id: "custom_stopping_strings_macro", property: "custom_stopping_strings_macro", isCheckbox: true, isGlobalSetting: true }
|
||||||
|
];
|
||||||
|
|
||||||
let browser_has_focus = true;
|
let browser_has_focus = true;
|
||||||
const debug_functions = [];
|
const debug_functions = [];
|
||||||
|
|
||||||
|
@ -1070,14 +1089,28 @@ function switchMaxContextSize() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadContextSettings() {
|
// Fetch a compiled object of all preset settings
|
||||||
const controls = [
|
function getContextSettings() {
|
||||||
{ id: "context_story_string", property: "story_string", isCheckbox: false },
|
let compiledSettings = {};
|
||||||
{ id: "context_example_separator", property: "example_separator", isCheckbox: false },
|
|
||||||
{ id: "context_chat_start", property: "chat_start", isCheckbox: false },
|
|
||||||
];
|
|
||||||
|
|
||||||
controls.forEach(control => {
|
contextControls.forEach((control) => {
|
||||||
|
let value = control.isGlobalSetting ? power_user[control.property] : power_user.context[control.property];
|
||||||
|
|
||||||
|
// Force to a boolean if the setting is a checkbox
|
||||||
|
if (control.isCheckbox) {
|
||||||
|
value = !!value;
|
||||||
|
}
|
||||||
|
|
||||||
|
compiledSettings[control.property] = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
return compiledSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Maybe add a refresh button to reset settings to preset
|
||||||
|
// TODO: Add "global state" if a preset doesn't set the power_user checkboxes
|
||||||
|
function loadContextSettings() {
|
||||||
|
contextControls.forEach(control => {
|
||||||
const $element = $(`#${control.id}`);
|
const $element = $(`#${control.id}`);
|
||||||
|
|
||||||
if (control.isCheckbox) {
|
if (control.isCheckbox) {
|
||||||
|
@ -1086,8 +1119,16 @@ function loadContextSettings() {
|
||||||
$element.val(power_user.context[control.property]);
|
$element.val(power_user.context[control.property]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the setting already exists, no need to duplicate it
|
||||||
|
// TODO: Maybe check the power_user object for the setting instead of a flag?
|
||||||
$element.on('input', function () {
|
$element.on('input', function () {
|
||||||
power_user.context[control.property] = control.isCheckbox ? !!$(this).prop('checked') : $(this).val();
|
const value = control.isCheckbox ? !!$(this).prop('checked') : $(this).val();
|
||||||
|
if (control.isGlobalSetting) {
|
||||||
|
power_user[control.property] = value;
|
||||||
|
} else {
|
||||||
|
power_user.context[control.property] = value;
|
||||||
|
}
|
||||||
|
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
if (!control.isCheckbox) {
|
if (!control.isCheckbox) {
|
||||||
resetScrollHeight($element);
|
resetScrollHeight($element);
|
||||||
|
@ -1113,9 +1154,14 @@ function loadContextSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
power_user.context.preset = name;
|
power_user.context.preset = name;
|
||||||
controls.forEach(control => {
|
contextControls.forEach(control => {
|
||||||
if (preset[control.property] !== undefined) {
|
if (preset[control.property] !== undefined) {
|
||||||
|
if (control.isGlobalSetting) {
|
||||||
|
power_user[control.property] = preset[control.property];
|
||||||
|
} else {
|
||||||
power_user.context[control.property] = preset[control.property];
|
power_user.context[control.property] = preset[control.property];
|
||||||
|
}
|
||||||
|
|
||||||
const $element = $(`#${control.id}`);
|
const $element = $(`#${control.id}`);
|
||||||
|
|
||||||
if (control.isCheckbox) {
|
if (control.isCheckbox) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import {
|
||||||
import { groups, selected_group } from "./group-chats.js";
|
import { groups, selected_group } from "./group-chats.js";
|
||||||
import { instruct_presets } from "./instruct-mode.js";
|
import { instruct_presets } from "./instruct-mode.js";
|
||||||
import { kai_settings } from "./kai-settings.js";
|
import { kai_settings } from "./kai-settings.js";
|
||||||
import { context_presets, power_user } from "./power-user.js";
|
import { context_presets, getContextSettings, power_user } from "./power-user.js";
|
||||||
import {
|
import {
|
||||||
textgenerationwebui_preset_names,
|
textgenerationwebui_preset_names,
|
||||||
textgenerationwebui_presets,
|
textgenerationwebui_presets,
|
||||||
|
@ -104,6 +104,7 @@ class PresetManager {
|
||||||
|
|
||||||
async updatePreset() {
|
async updatePreset() {
|
||||||
const selected = $(this.select).find("option:selected");
|
const selected = $(this.select).find("option:selected");
|
||||||
|
console.log(selected)
|
||||||
|
|
||||||
if (selected.val() == 'gui') {
|
if (selected.val() == 'gui') {
|
||||||
toastr.info('Cannot update GUI preset');
|
toastr.info('Cannot update GUI preset');
|
||||||
|
@ -236,7 +237,7 @@ class PresetManager {
|
||||||
case "textgenerationwebui":
|
case "textgenerationwebui":
|
||||||
return textgenerationwebui_settings;
|
return textgenerationwebui_settings;
|
||||||
case "context":
|
case "context":
|
||||||
const context_preset = structuredClone(power_user.context);
|
const context_preset = getContextSettings();
|
||||||
context_preset['name'] = name || power_user.context.preset;
|
context_preset['name'] = name || power_user.context.preset;
|
||||||
return context_preset;
|
return context_preset;
|
||||||
case "instruct":
|
case "instruct":
|
||||||
|
|
Loading…
Reference in New Issue