Require single quotes

This commit is contained in:
valadaptive
2023-12-02 13:04:51 -05:00
parent a06f1e8ad6
commit a37f874e38
76 changed files with 4135 additions and 4134 deletions

View File

@ -14,17 +14,17 @@ import {
novelai_settings,
saveSettingsDebounced,
this_chid,
} from "../script.js";
import { groups, selected_group } from "./group-chats.js";
import { instruct_presets } from "./instruct-mode.js";
import { kai_settings } from "./kai-settings.js";
import { context_presets, getContextSettings, power_user } from "./power-user.js";
} from '../script.js';
import { groups, selected_group } from './group-chats.js';
import { instruct_presets } from './instruct-mode.js';
import { kai_settings } from './kai-settings.js';
import { context_presets, getContextSettings, power_user } from './power-user.js';
import {
textgenerationwebui_preset_names,
textgenerationwebui_presets,
textgenerationwebui_settings,
} from "./textgen-settings.js";
import { download, parseJsonFile, waitUntilCondition } from "./utils.js";
} from './textgen-settings.js';
import { download, parseJsonFile, waitUntilCondition } from './utils.js';
const presetManagers = {};
@ -71,8 +71,8 @@ function getPresetManager(apiId) {
function registerPresetManagers() {
$('select[data-preset-manager-for]').each((_, e) => {
const forData = $(e).data("preset-manager-for");
for (const apiId of forData.split(",")) {
const forData = $(e).data('preset-manager-for');
for (const apiId of forData.split(',')) {
console.debug(`Registering preset manager for API: ${apiId}`);
presetManagers[apiId] = new PresetManager($(e), apiId);
}
@ -90,20 +90,20 @@ class PresetManager {
}
getSelectedPreset() {
return $(this.select).find("option:selected").val();
return $(this.select).find('option:selected').val();
}
getSelectedPresetName() {
return $(this.select).find("option:selected").text();
return $(this.select).find('option:selected').text();
}
selectPreset(preset) {
$(this.select).find(`option[value=${preset}]`).prop('selected', true);
$(this.select).val(preset).trigger("change");
$(this.select).val(preset).trigger('change');
}
async updatePreset() {
const selected = $(this.select).find("option:selected");
const selected = $(this.select).find('option:selected');
console.log(selected)
if (selected.val() == 'gui') {
@ -120,7 +120,7 @@ class PresetManager {
const popupText = `
<h3>Preset name:</h3>
${!this.isNonGenericApi() ? '<h4>Hint: Use a character/group name to bind preset to a specific chat.</h4>' : ''}`;
const name = await callPopup(popupText, "input");
const name = await callPopup(popupText, 'input');
if (!name) {
console.log('Preset name not provided');
@ -134,8 +134,8 @@ class PresetManager {
async savePreset(name, settings) {
const preset = settings ?? this.getPresetSettings(name);
const res = await fetch(`/api/presets/save`, {
method: "POST",
const res = await fetch('/api/presets/save', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({ preset, name, apiId: this.apiId })
});
@ -155,24 +155,24 @@ class PresetManager {
let preset_names = {};
switch (this.apiId) {
case "koboldhorde":
case "kobold":
case 'koboldhorde':
case 'kobold':
presets = koboldai_settings;
preset_names = koboldai_setting_names;
break;
case "novel":
case 'novel':
presets = novelai_settings;
preset_names = novelai_setting_names;
break;
case "textgenerationwebui":
case 'textgenerationwebui':
presets = textgenerationwebui_presets;
preset_names = textgenerationwebui_preset_names;
break;
case "context":
case 'context':
presets = context_presets;
preset_names = context_presets.map(x => x.name);
break;
case "instruct":
case 'instruct':
presets = instruct_presets;
preset_names = instruct_presets.map(x => x.name);
break;
@ -184,11 +184,11 @@ class PresetManager {
}
isKeyedApi() {
return this.apiId == "textgenerationwebui" || this.apiId == "context" || this.apiId == "instruct";
return this.apiId == 'textgenerationwebui' || this.apiId == 'context' || this.apiId == 'instruct';
}
isNonGenericApi() {
return this.apiId == "context" || this.apiId == "instruct";
return this.apiId == 'context' || this.apiId == 'instruct';
}
updateList(name, preset) {
@ -199,13 +199,13 @@ class PresetManager {
if (this.isKeyedApi()) {
presets[preset_names.indexOf(name)] = preset;
$(this.select).find(`option[value="${name}"]`).prop('selected', true);
$(this.select).val(name).trigger("change");
$(this.select).val(name).trigger('change');
}
else {
const value = preset_names[name];
presets[value] = preset;
$(this.select).find(`option[value="${value}"]`).prop('selected', true);
$(this.select).val(value).trigger("change");
$(this.select).val(value).trigger('change');
}
}
else {
@ -216,12 +216,12 @@ class PresetManager {
preset_names[value] = name;
const option = $('<option></option>', { value: name, text: name, selected: true });
$(this.select).append(option);
$(this.select).val(name).trigger("change");
$(this.select).val(name).trigger('change');
} else {
preset_names[name] = value;
const option = $('<option></option>', { value: value, text: name, selected: true });
$(this.select).append(option);
$(this.select).val(value).trigger("change");
$(this.select).val(value).trigger('change');
}
}
}
@ -229,19 +229,19 @@ class PresetManager {
getPresetSettings(name) {
function getSettingsByApiId(apiId) {
switch (apiId) {
case "koboldhorde":
case "kobold":
case 'koboldhorde':
case 'kobold':
return kai_settings;
case "novel":
case 'novel':
return nai_settings;
case "textgenerationwebui":
case 'textgenerationwebui':
return textgenerationwebui_settings;
case "context": {
case 'context': {
const context_preset = getContextSettings();
context_preset['name'] = name || power_user.context.preset;
return context_preset;
}
case "instruct": {
case 'instruct': {
const instruct_preset = structuredClone(power_user.instruct);
instruct_preset['name'] = name || power_user.instruct.preset;
return instruct_preset;
@ -263,7 +263,7 @@ class PresetManager {
'nai_preamble',
'model_novel',
'streaming_kobold',
"enabled",
'enabled',
'seed',
'mancer_model',
];
@ -327,8 +327,8 @@ jQuery(async () => {
eventSource.on(event_types.CHAT_CHANGED, autoSelectPreset);
registerPresetManagers();
$(document).on("click", "[data-preset-manager-update]", async function () {
const apiId = $(this).data("preset-manager-update");
$(document).on('click', '[data-preset-manager-update]', async function () {
const apiId = $(this).data('preset-manager-update');
const presetManager = getPresetManager(apiId);
if (!presetManager) {
@ -339,8 +339,8 @@ jQuery(async () => {
await presetManager.updatePreset();
});
$(document).on("click", "[data-preset-manager-new]", async function () {
const apiId = $(this).data("preset-manager-new");
$(document).on('click', '[data-preset-manager-new]', async function () {
const apiId = $(this).data('preset-manager-new');
const presetManager = getPresetManager(apiId);
if (!presetManager) {
@ -351,8 +351,8 @@ jQuery(async () => {
await presetManager.savePresetAs();
});
$(document).on("click", "[data-preset-manager-export]", async function () {
const apiId = $(this).data("preset-manager-export");
$(document).on('click', '[data-preset-manager-export]', async function () {
const apiId = $(this).data('preset-manager-export');
const presetManager = getPresetManager(apiId);
if (!presetManager) {
@ -360,20 +360,20 @@ jQuery(async () => {
return;
}
const selected = $(presetManager.select).find("option:selected");
const selected = $(presetManager.select).find('option:selected');
const name = selected.text();
const preset = presetManager.getPresetSettings(name);
const data = JSON.stringify(preset, null, 4);
download(data, `${name}.json`, "application/json");
download(data, `${name}.json`, 'application/json');
});
$(document).on("click", "[data-preset-manager-import]", async function () {
const apiId = $(this).data("preset-manager-import");
$(document).on('click', '[data-preset-manager-import]', async function () {
const apiId = $(this).data('preset-manager-import');
$(`[data-preset-manager-file="${apiId}"]`).trigger('click');
});
$(document).on("change", "[data-preset-manager-file]", async function (e) {
const apiId = $(this).data("preset-manager-file");
$(document).on('change', '[data-preset-manager-file]', async function (e) {
const apiId = $(this).data('preset-manager-file');
const presetManager = getPresetManager(apiId);
if (!presetManager) {
@ -397,8 +397,8 @@ jQuery(async () => {
e.target.value = null;
});
$(document).on("click", "[data-preset-manager-delete]", async function () {
const apiId = $(this).data("preset-manager-delete");
$(document).on('click', '[data-preset-manager-delete]', async function () {
const apiId = $(this).data('preset-manager-delete');
const presetManager = getPresetManager(apiId);
if (!presetManager) {
@ -407,7 +407,7 @@ jQuery(async () => {
}
// default context preset cannot be deleted
if (apiId == "context" && power_user.default_context === power_user.context.preset) {
if (apiId == 'context' && power_user.default_context === power_user.context.preset) {
return;
}