mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
More typechecks and comments
This commit is contained in:
76
package-lock.json
generated
76
package-lock.json
generated
@ -52,13 +52,8 @@
|
||||
"sillytavern": "server.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@types/moment": "^2.13.0",
|
||||
"dompurify": "^3.0.5",
|
||||
"pkg": "^5.8.1",
|
||||
"pkg-fetch": "^3.5.2",
|
||||
"showdown": "^2.1.0",
|
||||
"toastr": "^2.1.4"
|
||||
"pkg-fetch": "^3.5.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@agnai/sentencepiece-js": {
|
||||
@ -649,31 +644,11 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/@popperjs/core": {
|
||||
"version": "2.11.8",
|
||||
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
|
||||
"integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==",
|
||||
"dev": true,
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/popperjs"
|
||||
}
|
||||
},
|
||||
"node_modules/@tokenizer/token": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz",
|
||||
"integrity": "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A=="
|
||||
},
|
||||
"node_modules/@types/moment": {
|
||||
"version": "2.13.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/moment/-/moment-2.13.0.tgz",
|
||||
"integrity": "sha512-DyuyYGpV6r+4Z1bUznLi/Y7HpGn4iQ4IVcGn8zrr1P4KotKLdH0sbK1TFR6RGyX6B+G8u83wCzL+bpawKU/hdQ==",
|
||||
"deprecated": "This is a stub types definition for Moment (https://github.com/moment/moment). Moment provides its own type definitions, so you don't need @types/moment installed!",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"moment": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "16.9.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.9.1.tgz",
|
||||
@ -1052,15 +1027,6 @@
|
||||
"resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz",
|
||||
"integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w=="
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "9.5.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
|
||||
"integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.20.0 || >=14"
|
||||
}
|
||||
},
|
||||
"node_modules/compressible": {
|
||||
"version": "2.0.18",
|
||||
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
||||
@ -1298,12 +1264,6 @@
|
||||
"resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.2.tgz",
|
||||
"integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w=="
|
||||
},
|
||||
"node_modules/dompurify": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.0.5.tgz",
|
||||
"integrity": "sha512-F9e6wPGtY+8KNMRAVfxeCOHU0/NPWMSENNq4pQctuXRqqdEPW7q3CrLbR5Nse044WwacyjHGOMlvNsBe1y6z9A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
@ -2196,15 +2156,6 @@
|
||||
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/moment": {
|
||||
"version": "2.29.4",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
@ -3117,22 +3068,6 @@
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
|
||||
},
|
||||
"node_modules/showdown": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/showdown/-/showdown-2.1.0.tgz",
|
||||
"integrity": "sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"commander": "^9.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"showdown": "bin/showdown.js"
|
||||
},
|
||||
"funding": {
|
||||
"type": "individual",
|
||||
"url": "https://www.paypal.me/tiviesantos"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
||||
@ -3430,15 +3365,6 @@
|
||||
"node": ">=8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/toastr": {
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/toastr/-/toastr-2.1.4.tgz",
|
||||
"integrity": "sha512-LIy77F5n+sz4tefMmFOntcJ6HL0Fv3k1TDnNmFZ0bU/GcvIIfy6eG2v7zQmMiYgaalAiUv75ttFrPn5s0gyqlA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"jquery": ">=1.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/toidentifier": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
||||
|
@ -80,12 +80,7 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@types/moment": "^2.13.0",
|
||||
"dompurify": "^3.0.5",
|
||||
"pkg": "^5.8.1",
|
||||
"pkg-fetch": "^3.5.2",
|
||||
"showdown": "^2.1.0",
|
||||
"toastr": "^2.1.4"
|
||||
"pkg-fetch": "^3.5.2"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"checkJs": true,
|
||||
"target": "esnext",
|
||||
"target": "ESNext",
|
||||
"module": "commonjs",
|
||||
"allowUmdGlobalAccess": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
@ -16,7 +16,11 @@
|
||||
"toastr",
|
||||
"showdown",
|
||||
"dompurify",
|
||||
"@types/moment"
|
||||
"moment",
|
||||
"seedrandom",
|
||||
"showdown-katex",
|
||||
"droll",
|
||||
"handlebars",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -2318,7 +2318,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
||||
const magName = isImpersonate ? (is_pygmalion ? 'You' : name1) : name2;
|
||||
|
||||
if (isInstruct) {
|
||||
message_already_generated = formatInstructModePrompt(magName, isImpersonate, false, name1, name2);
|
||||
message_already_generated = formatInstructModePrompt(magName, isImpersonate, '', name1, name2);
|
||||
} else {
|
||||
message_already_generated = `${magName}: `;
|
||||
}
|
||||
@ -4743,7 +4743,7 @@ function onPersonaDescriptionPositionInput() {
|
||||
}
|
||||
|
||||
function onPersonaDescriptionInput() {
|
||||
power_user.persona_description = $("#persona_description").val();
|
||||
power_user.persona_description = String($("#persona_description").val());
|
||||
|
||||
if (power_user.personas[user_avatar]) {
|
||||
let object = power_user.persona_descriptions[user_avatar];
|
||||
@ -7397,7 +7397,7 @@ $(document).ready(function () {
|
||||
$(document).on('click', '.swipe_left', swipe_left);
|
||||
|
||||
$("#character_search_bar").on("input", function () {
|
||||
const searchValue = $(this).val().toLowerCase();
|
||||
const searchValue = String($(this).val()).toLowerCase();
|
||||
entitiesFilter.setFilterData(FILTER_TYPES.SEARCH, searchValue);
|
||||
});
|
||||
|
||||
@ -7465,7 +7465,7 @@ $(document).ready(function () {
|
||||
$(this).parent().css("background", css_mes_bg);
|
||||
});
|
||||
$(this).css("background", "#600"); //sets the bg of the mes selected for deletion
|
||||
var i = $(this).attr("mesid"); //checks the message ID in the chat
|
||||
var i = Number($(this).attr("mesid")); //checks the message ID in the chat
|
||||
this_del_mes = i;
|
||||
while (i < chat.length) {
|
||||
//as long as the current message ID is less than the total chat length
|
||||
@ -7899,7 +7899,7 @@ $(document).ready(function () {
|
||||
$("#api_button").click(function (e) {
|
||||
e.stopPropagation();
|
||||
if ($("#api_url_text").val() != "") {
|
||||
let value = formatKoboldUrl($.trim($("#api_url_text").val()));
|
||||
let value = formatKoboldUrl(String($("#api_url_text").val()).trim());
|
||||
|
||||
if (!value) {
|
||||
toastr.error('Please enter a valid URL.');
|
||||
@ -7933,13 +7933,13 @@ $(document).ready(function () {
|
||||
e.stopPropagation();
|
||||
const url_source = api_use_mancer_webui ? "#mancer_api_url_text" : "#textgenerationwebui_api_url_text";
|
||||
if ($(url_source).val() != "") {
|
||||
let value = formatTextGenURL($(url_source).val().trim(), api_use_mancer_webui);
|
||||
let value = formatTextGenURL(String($(url_source).val()).trim(), api_use_mancer_webui);
|
||||
if (!value) {
|
||||
callPopup("Please enter a valid URL.<br/>WebUI URLs should end with <tt>/api</tt><br/>Enable 'Relaxed API URLs' to allow other paths.", 'text');
|
||||
return;
|
||||
}
|
||||
|
||||
const mancer_key = $("#api_key_mancer").val().trim();
|
||||
const mancer_key = String($("#api_key_mancer").val()).trim();
|
||||
if (mancer_key.length) {
|
||||
await writeSecret(SECRET_KEYS.MANCER, mancer_key);
|
||||
}
|
||||
@ -8194,8 +8194,8 @@ $(document).ready(function () {
|
||||
|
||||
const preset = novelai_settings[novelai_setting_names[nai_settings.preset_settings_novel]];
|
||||
loadNovelPreset(preset);
|
||||
amount_gen = parseInt($("#amount_gen").val());
|
||||
max_context = parseInt($("#max_context").val());
|
||||
amount_gen = Number($("#amount_gen").val());
|
||||
max_context = Number($("#max_context").val());
|
||||
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
@ -8572,7 +8572,7 @@ $(document).ready(function () {
|
||||
|
||||
$("#api_button_novel").on('click', async function (e) {
|
||||
e.stopPropagation();
|
||||
const api_key_novel = $("#api_key_novel").val().trim();
|
||||
const api_key_novel = String($("#api_key_novel").val()).trim();
|
||||
|
||||
if (api_key_novel.length) {
|
||||
await writeSecret(SECRET_KEYS.NOVEL, api_key_novel);
|
||||
@ -8922,7 +8922,7 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
$("#bg-filter").on("input", function () {
|
||||
const filterValue = $(this).val().toLowerCase();
|
||||
const filterValue = String($(this).val()).toLowerCase();
|
||||
$("#bg_menu_content > div").each(function () {
|
||||
const $bgContent = $(this);
|
||||
if ($bgContent.attr("title").toLowerCase().includes(filterValue)) {
|
||||
|
@ -1,6 +1,10 @@
|
||||
import { fuzzySearchCharacters, fuzzySearchGroups, fuzzySearchWorldInfo, power_user } from "./power-user.js";
|
||||
import { tag_map } from "./tags.js";
|
||||
|
||||
/**
|
||||
* The filter types.
|
||||
* @type {Object.<string, string>}
|
||||
*/
|
||||
export const FILTER_TYPES = {
|
||||
SEARCH: 'search',
|
||||
TAG: 'tag',
|
||||
@ -9,11 +13,26 @@ export const FILTER_TYPES = {
|
||||
WORLD_INFO_SEARCH: 'world_info_search',
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class for filtering data.
|
||||
* @example
|
||||
* const filterHelper = new FilterHelper(() => console.log('data changed'));
|
||||
* filterHelper.setFilterData(FILTER_TYPES.SEARCH, 'test');
|
||||
* data = filterHelper.applyFilters(data);
|
||||
*/
|
||||
export class FilterHelper {
|
||||
/**
|
||||
* Creates a new FilterHelper
|
||||
* @param {Function} onDataChanged Callback to trigger when the filter data changes
|
||||
*/
|
||||
constructor(onDataChanged) {
|
||||
this.onDataChanged = onDataChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* The filter functions.
|
||||
* @type {Object.<string, Function>}
|
||||
*/
|
||||
filterFunctions = {
|
||||
[FILTER_TYPES.SEARCH]: this.searchFilter.bind(this),
|
||||
[FILTER_TYPES.GROUP]: this.groupFilter.bind(this),
|
||||
@ -22,6 +41,10 @@ export class FilterHelper {
|
||||
[FILTER_TYPES.WORLD_INFO_SEARCH]: this.wiSearchFilter.bind(this),
|
||||
}
|
||||
|
||||
/**
|
||||
* The filter data.
|
||||
* @type {Object.<string, any>}
|
||||
*/
|
||||
filterData = {
|
||||
[FILTER_TYPES.SEARCH]: '',
|
||||
[FILTER_TYPES.GROUP]: false,
|
||||
@ -30,6 +53,11 @@ export class FilterHelper {
|
||||
[FILTER_TYPES.WORLD_INFO_SEARCH]: '',
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a fuzzy search filter to the World Info data.
|
||||
* @param {any[]} data The data to filter. Must have a uid property.
|
||||
* @returns {any[]} The filtered data.
|
||||
*/
|
||||
wiSearchFilter(data) {
|
||||
const term = this.filterData[FILTER_TYPES.WORLD_INFO_SEARCH];
|
||||
|
||||
@ -41,6 +69,11 @@ export class FilterHelper {
|
||||
return data.filter(entity => fuzzySearchResults.includes(entity.uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a tag filter to the data.
|
||||
* @param {any[]} data The data to filter.
|
||||
* @returns {any[]} The filtered data.
|
||||
*/
|
||||
tagFilter(data) {
|
||||
const TAG_LOGIC_AND = true; // switch to false to use OR logic for combining tags
|
||||
const { selected, excluded } = this.filterData[FILTER_TYPES.TAG];
|
||||
@ -76,6 +109,11 @@ export class FilterHelper {
|
||||
return data.filter(entity => getIsTagged(entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a favorite filter to the data.
|
||||
* @param {any[]} data The data to filter.
|
||||
* @returns {any[]} The filtered data.
|
||||
*/
|
||||
favFilter(data) {
|
||||
if (!this.filterData[FILTER_TYPES.FAV]) {
|
||||
return data;
|
||||
@ -84,6 +122,11 @@ export class FilterHelper {
|
||||
return data.filter(entity => entity.item.fav || entity.item.fav == "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a group type filter to the data.
|
||||
* @param {any[]} data The data to filter.
|
||||
* @returns {any[]} The filtered data.
|
||||
*/
|
||||
groupFilter(data) {
|
||||
if (!this.filterData[FILTER_TYPES.GROUP]) {
|
||||
return data;
|
||||
@ -92,6 +135,11 @@ export class FilterHelper {
|
||||
return data.filter(entity => entity.type === 'group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a search filter to the data. Uses fuzzy search if enabled.
|
||||
* @param {any[]} data The data to filter.
|
||||
* @returns {any[]} The filtered data.
|
||||
*/
|
||||
searchFilter(data) {
|
||||
if (!this.filterData[FILTER_TYPES.SEARCH]) {
|
||||
return data;
|
||||
@ -122,6 +170,12 @@ export class FilterHelper {
|
||||
return data.filter(entity => getIsValidSearch(entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filter data for the given filter type.
|
||||
* @param {string} filterType The filter type to set data for.
|
||||
* @param {any} data The data to set.
|
||||
* @param {boolean} suppressDataChanged Whether to suppress the data changed callback.
|
||||
*/
|
||||
setFilterData(filterType, data, suppressDataChanged = false) {
|
||||
const oldData = this.filterData[filterType];
|
||||
this.filterData[filterType] = data;
|
||||
@ -132,10 +186,19 @@ export class FilterHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filter data for the given filter type.
|
||||
* @param {string} filterType The filter type to get data for.
|
||||
*/
|
||||
getFilterData(filterType) {
|
||||
return this.filterData[filterType];
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies all filters to the given data.
|
||||
* @param {any[]} data The data to filter.
|
||||
* @returns {any[]} The filtered data.
|
||||
*/
|
||||
applyFilters(data) {
|
||||
return Object.values(this.filterFunctions)
|
||||
.reduce((data, fn) => fn(data), data);
|
||||
|
@ -463,7 +463,7 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
||||
is_group_generating = true;
|
||||
setCharacterName('');
|
||||
setCharacterId(undefined);
|
||||
const userInput = $("#send_textarea").val();
|
||||
const userInput = String($("#send_textarea").val());
|
||||
|
||||
if (typingIndicator.length === 0 && !isStreamingEnabled()) {
|
||||
typingIndicator = $(
|
||||
@ -983,11 +983,9 @@ function printGroupCandidates() {
|
||||
const storageKey = 'GroupCandidates_PerPage';
|
||||
$("#rm_group_add_members_pagination").pagination({
|
||||
dataSource: getGroupCharacters({ doFilter: true, onlyMembers: false }),
|
||||
pageSize: 5,
|
||||
pageRange: 1,
|
||||
position: 'top',
|
||||
showPageNumbers: false,
|
||||
showSizeChanger: false,
|
||||
prevText: '<',
|
||||
nextText: '>',
|
||||
formatNavigator: PAGINATION_TEMPLATE,
|
||||
@ -1011,11 +1009,9 @@ function printGroupMembers() {
|
||||
const storageKey = 'GroupMembers_PerPage';
|
||||
$("#rm_group_members_pagination").pagination({
|
||||
dataSource: getGroupCharacters({ doFilter: false, onlyMembers: true }),
|
||||
pageSize: 5,
|
||||
pageRange: 1,
|
||||
position: 'top',
|
||||
showPageNumbers: false,
|
||||
showSizeChanger: false,
|
||||
prevText: '<',
|
||||
nextText: '>',
|
||||
formatNavigator: PAGINATION_TEMPLATE,
|
||||
@ -1320,7 +1316,7 @@ function openCharacterDefinition(characterSelect) {
|
||||
}
|
||||
|
||||
function filterGroupMembers() {
|
||||
const searchValue = $(this).val().toLowerCase();
|
||||
const searchValue = String($(this).val()).toLowerCase();
|
||||
groupCandidatesFilter.setFilterData(FILTER_TYPES.SEARCH, searchValue);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ jQuery(async () => {
|
||||
addLanguagesToDropdown();
|
||||
|
||||
$('#ui_language_select').on('change', async function () {
|
||||
const language = $(this).val();
|
||||
const language = String($(this).val());
|
||||
|
||||
if (language) {
|
||||
localStorage.setItem(storageKey, language);
|
||||
|
@ -4,6 +4,9 @@ import { saveSettingsDebounced, substituteParams } from "../script.js";
|
||||
import { selected_group } from "./group-chats.js";
|
||||
import { power_user } from "./power-user.js";
|
||||
|
||||
/**
|
||||
* @type {any[]} Instruct mode presets.
|
||||
*/
|
||||
export let instruct_presets = [];
|
||||
|
||||
const controls = [
|
||||
@ -116,6 +119,11 @@ export function autoSelectInstructPreset(modelId) {
|
||||
* @returns {string[]} Array of instruct mode stopping strings.
|
||||
*/
|
||||
export function getInstructStoppingSequences() {
|
||||
/**
|
||||
* Adds instruct mode sequence to the result array.
|
||||
* @param {string} sequence Sequence string.
|
||||
* @returns {void}
|
||||
*/
|
||||
function addInstructSequence(sequence) {
|
||||
// Cohee: oobabooga's textgen always appends newline before the sequence as a stopping string
|
||||
// But it's a problem for Metharme which doesn't use newlines to separate them.
|
||||
@ -215,6 +223,7 @@ export function formatInstructModeExamples(mesExamples, name1, name2) {
|
||||
* @param {string} promptBias Prompt bias string.
|
||||
* @param {string} name1 User name.
|
||||
* @param {string} name2 Character name.
|
||||
* @returns {string} Formatted instruct mode last prompt line.
|
||||
*/
|
||||
export function formatInstructModePrompt(name, isImpersonate, promptBias, name1, name2) {
|
||||
const includeNames = power_user.instruct.names || (!!selected_group && power_user.instruct.names_force_groups);
|
||||
@ -258,7 +267,7 @@ jQuery(() => {
|
||||
return;
|
||||
}
|
||||
|
||||
power_user.instruct.preset = name;
|
||||
power_user.instruct.preset = String(name);
|
||||
controls.forEach(control => {
|
||||
if (preset[control.property] !== undefined) {
|
||||
power_user.instruct[control.property] = preset[control.property];
|
||||
|
@ -75,18 +75,18 @@ function loadKoboldSettings(preset) {
|
||||
}
|
||||
}
|
||||
|
||||
function getKoboldGenerationData(finalPromt, this_settings, this_amount_gen, this_max_context, isImpersonate, type) {
|
||||
function getKoboldGenerationData(finalPrompt, this_settings, this_amount_gen, this_max_context, isImpersonate, type) {
|
||||
const sampler_order = kai_settings.sampler_order || this_settings.sampler_order;
|
||||
let generate_data = {
|
||||
prompt: finalPromt,
|
||||
prompt: finalPrompt,
|
||||
gui_settings: false,
|
||||
sampler_order: sampler_order,
|
||||
max_context_length: parseInt(this_max_context),
|
||||
max_context_length: Number(this_max_context),
|
||||
max_length: this_amount_gen,
|
||||
rep_pen: parseFloat(kai_settings.rep_pen),
|
||||
rep_pen_range: parseInt(kai_settings.rep_pen_range),
|
||||
rep_pen: Number(kai_settings.rep_pen),
|
||||
rep_pen_range: Number(kai_settings.rep_pen_range),
|
||||
rep_pen_slope: kai_settings.rep_pen_slope,
|
||||
temperature: parseFloat(kai_settings.temp),
|
||||
temperature: Number(kai_settings.temp),
|
||||
tfs: kai_settings.tfs,
|
||||
top_a: kai_settings.top_a,
|
||||
top_k: kai_settings.top_k,
|
||||
@ -223,16 +223,30 @@ const sliders = [
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Determines if the Kobold stop sequence can be used with the given version.
|
||||
* @param {string} version KoboldAI version to check.
|
||||
* @returns {boolean} True if the Kobold stop sequence can be used, false otherwise.
|
||||
*/
|
||||
function canUseKoboldStopSequence(version) {
|
||||
return (version || '0.0.0').localeCompare(MIN_STOP_SEQUENCE_VERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the Kobold streaming API can be used with the given version.
|
||||
* @param {{ result: string; version: string; }} koboldVersion KoboldAI version object.
|
||||
* @returns {boolean} True if the Kobold streaming API can be used, false otherwise.
|
||||
*/
|
||||
function canUseKoboldStreaming(koboldVersion) {
|
||||
if (koboldVersion && koboldVersion.result == 'KoboldCpp') {
|
||||
return (koboldVersion.version || '0.0').localeCompare(MIN_STREAMING_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the sampler items by the given order.
|
||||
* @param {any[]} orderArray Sampler order array.
|
||||
*/
|
||||
function sortItemsByOrder(orderArray) {
|
||||
console.debug('Preset samplers order: ' + orderArray);
|
||||
const $draggableItems = $("#kobold_order");
|
||||
|
@ -911,7 +911,7 @@ function loadContextSettings() {
|
||||
});
|
||||
|
||||
$('#context_presets').on('change', function () {
|
||||
const name = $(this).find(':selected').val();
|
||||
const name = String($(this).find(':selected').val());
|
||||
const preset = context_presets.find(x => x.name === name);
|
||||
|
||||
if (!preset) {
|
||||
@ -1032,6 +1032,10 @@ const compareFunc = (first, second) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sorts an array of entities based on the current sort settings
|
||||
* @param {any[]} entities An array of objects with an `item` property
|
||||
*/
|
||||
function sortEntitiesList(entities) {
|
||||
if (power_user.sort_field == undefined || entities.length === 0) {
|
||||
return;
|
||||
@ -1039,6 +1043,7 @@ function sortEntitiesList(entities) {
|
||||
|
||||
entities.sort((a, b) => sortFunc(a.item, b.item));
|
||||
}
|
||||
|
||||
async function saveTheme() {
|
||||
const name = await callPopup('Enter a theme preset name:', 'input');
|
||||
|
||||
@ -1262,8 +1267,8 @@ async function doDelMode(_, text) {
|
||||
if (text) {
|
||||
await delay(300) //same as above, need event signal for 'entered del mode'
|
||||
console.debug('parsing msgs to del')
|
||||
let numMesToDel = Number(text).toFixed(0)
|
||||
let lastMesID = $('.last_mes').attr('mesid')
|
||||
let numMesToDel = Number(text);
|
||||
let lastMesID = Number($('.last_mes').attr('mesid'));
|
||||
let oldestMesIDToDel = lastMesID - numMesToDel + 1;
|
||||
|
||||
//disallow targeting first message
|
||||
@ -1340,10 +1345,6 @@ function setAvgBG() {
|
||||
$("#user-mes-blur-tint-color-picker").attr('color', 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')');
|
||||
} */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function getAverageRGB(imgEl) {
|
||||
|
||||
var blockSize = 5, // only visit every 5 pixels
|
||||
@ -1388,6 +1389,13 @@ function setAvgBG() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an HSL color value to RGB.
|
||||
* @param {number} h Hue value
|
||||
* @param {number} s Saturation value
|
||||
* @param {number} l Luminance value
|
||||
* @return {Array} The RGB representation
|
||||
*/
|
||||
function hslToRgb(h, s, l) {
|
||||
const hueToRgb = (p, q, t) => {
|
||||
if (t < 0) t += 1;
|
||||
@ -1429,7 +1437,7 @@ function setAvgBG() {
|
||||
|
||||
console.log(`rLum ${rLuminance}, gLum ${gLuminance}, bLum ${bLuminance}`)
|
||||
|
||||
return 0.2126 * rLuminance + 0.7152 * gLuminance + 0.0722 * bLuminance;
|
||||
return 0.2126 * Number(rLuminance) + 0.7152 * Number(gLuminance) + 0.0722 * Number(bLuminance);
|
||||
}
|
||||
|
||||
//this version keeps BG and main text in same hue
|
||||
@ -1612,13 +1620,13 @@ $(document).ready(() => {
|
||||
});
|
||||
|
||||
$("#markdown_escape_strings").on('input', function () {
|
||||
power_user.markdown_escape_strings = $(this).val();
|
||||
power_user.markdown_escape_strings = String($(this).val());
|
||||
saveSettingsDebounced();
|
||||
reloadMarkdownProcessor(power_user.render_formulas);
|
||||
});
|
||||
|
||||
$("#start_reply_with").on('input', function () {
|
||||
power_user.user_prompt_bias = $(this).val();
|
||||
power_user.user_prompt_bias = String($(this).val());
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
@ -1745,7 +1753,7 @@ $(document).ready(() => {
|
||||
});
|
||||
|
||||
$("#themes").on('change', function () {
|
||||
const themeSelected = $(this).find(':selected').val();
|
||||
const themeSelected = String($(this).find(':selected').val());
|
||||
power_user.theme = themeSelected;
|
||||
applyTheme(themeSelected);
|
||||
saveSettingsDebounced();
|
||||
@ -1753,7 +1761,7 @@ $(document).ready(() => {
|
||||
|
||||
$("#movingUIPresets").on('change', async function () {
|
||||
console.log('saw MUI preset change')
|
||||
const movingUIPresetSelected = $(this).find(':selected').val();
|
||||
const movingUIPresetSelected = String($(this).find(':selected').val());
|
||||
power_user.movingUIPreset = movingUIPresetSelected;
|
||||
applyMovingUIPreset(movingUIPresetSelected);
|
||||
saveSettingsDebounced();
|
||||
@ -1813,7 +1821,7 @@ $(document).ready(() => {
|
||||
});
|
||||
|
||||
$('#auto_swipe_blacklist').on('input', function () {
|
||||
power_user.auto_swipe_blacklist = $(this).val()
|
||||
power_user.auto_swipe_blacklist = String($(this).val())
|
||||
.split(",")
|
||||
.map(str => str.trim())
|
||||
.filter(str => str);
|
||||
@ -1822,7 +1830,7 @@ $(document).ready(() => {
|
||||
});
|
||||
|
||||
$('#auto_swipe_minimum_length').on('input', function () {
|
||||
const number = parseInt($(this).val());
|
||||
const number = Number($(this).val());
|
||||
if (!isNaN(number)) {
|
||||
power_user.auto_swipe_minimum_length = number;
|
||||
saveSettingsDebounced();
|
||||
@ -1830,7 +1838,7 @@ $(document).ready(() => {
|
||||
});
|
||||
|
||||
$('#auto_swipe_blacklist_threshold').on('input', function () {
|
||||
const number = parseInt($(this).val());
|
||||
const number = Number($(this).val());
|
||||
if (!isNaN(number)) {
|
||||
power_user.auto_swipe_blacklist_threshold = number;
|
||||
saveSettingsDebounced();
|
||||
@ -1913,35 +1921,35 @@ $(document).ready(() => {
|
||||
$("#messageTimerEnabled").on("input", function () {
|
||||
const value = !!$(this).prop('checked');
|
||||
power_user.timer_enabled = value;
|
||||
localStorage.setItem(storage_keys.timer_enabled, power_user.timer_enabled);
|
||||
localStorage.setItem(storage_keys.timer_enabled, String(power_user.timer_enabled));
|
||||
switchTimer();
|
||||
});
|
||||
|
||||
$("#messageTimestampsEnabled").on("input", function () {
|
||||
const value = !!$(this).prop('checked');
|
||||
power_user.timestamps_enabled = value;
|
||||
localStorage.setItem(storage_keys.timestamps_enabled, power_user.timestamps_enabled);
|
||||
localStorage.setItem(storage_keys.timestamps_enabled, String(power_user.timestamps_enabled));
|
||||
switchTimestamps();
|
||||
});
|
||||
|
||||
$("#messageModelIconEnabled").on("input", function () {
|
||||
const value = !!$(this).prop('checked');
|
||||
power_user.timestamp_model_icon = value;
|
||||
localStorage.setItem(storage_keys.timestamp_model_icon, power_user.timestamp_model_icon);
|
||||
localStorage.setItem(storage_keys.timestamp_model_icon, String(power_user.timestamp_model_icon));
|
||||
switchIcons();
|
||||
});
|
||||
|
||||
$("#mesIDDisplayEnabled").on("input", function () {
|
||||
const value = !!$(this).prop('checked');
|
||||
power_user.mesIDDisplay_enabled = value;
|
||||
localStorage.setItem(storage_keys.mesIDDisplay_enabled, power_user.mesIDDisplay_enabled);
|
||||
localStorage.setItem(storage_keys.mesIDDisplay_enabled, String(power_user.mesIDDisplay_enabled));
|
||||
switchMesIDDisplay();
|
||||
});
|
||||
|
||||
$("#hotswapEnabled").on("input", function () {
|
||||
const value = !!$(this).prop('checked');
|
||||
power_user.hotswap_enabled = value;
|
||||
localStorage.setItem(storage_keys.hotswap_enabled, power_user.hotswap_enabled);
|
||||
localStorage.setItem(storage_keys.hotswap_enabled, String(power_user.hotswap_enabled));
|
||||
switchHotswap();
|
||||
});
|
||||
|
||||
@ -1987,7 +1995,7 @@ $(document).ready(() => {
|
||||
});
|
||||
|
||||
$('#custom_stopping_strings').on('input', function () {
|
||||
power_user.custom_stopping_strings = $(this).val();
|
||||
power_user.custom_stopping_strings = String($(this).val());
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user