2023-07-20 19:32:15 +02:00
|
|
|
import {
|
2023-11-08 01:52:03 +01:00
|
|
|
abortStatusCheck,
|
2023-07-20 19:32:15 +02:00
|
|
|
getRequestHeaders,
|
2023-08-02 21:35:05 +02:00
|
|
|
getStoppingStrings,
|
2023-08-16 03:52:29 +02:00
|
|
|
novelai_setting_names,
|
2023-08-16 20:43:38 +02:00
|
|
|
saveSettingsDebounced,
|
2023-11-16 15:58:49 +01:00
|
|
|
setGenerationParamsFromPreset,
|
|
|
|
substituteParams,
|
2023-12-02 19:04:51 +01:00
|
|
|
} from '../script.js';
|
|
|
|
import { getCfgPrompt } from './cfg-scale.js';
|
2023-12-19 19:27:24 +01:00
|
|
|
import { MAX_CONTEXT_DEFAULT, MAX_RESPONSE_DEFAULT, power_user } from './power-user.js';
|
2023-12-02 19:04:51 +01:00
|
|
|
import { getTextTokens, tokenizers } from './tokenizers.js';
|
2023-12-07 04:55:17 +01:00
|
|
|
import EventSourceStream from './sse-stream.js';
|
2023-08-17 12:05:22 +02:00
|
|
|
import {
|
2023-08-18 12:41:46 +02:00
|
|
|
getSortableDelay,
|
2023-08-17 12:05:22 +02:00
|
|
|
getStringHash,
|
2023-09-15 16:54:13 +02:00
|
|
|
onlyUnique,
|
2023-12-02 19:04:51 +01:00
|
|
|
} from './utils.js';
|
2023-12-18 16:32:10 +01:00
|
|
|
import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js';
|
2023-07-20 19:32:15 +02:00
|
|
|
|
2023-12-02 19:04:51 +01:00
|
|
|
const default_preamble = '[ Style: chat, complex, sensory, visceral ]';
|
2023-08-16 19:34:47 +02:00
|
|
|
const default_order = [1, 5, 0, 2, 3, 4];
|
2023-08-15 03:40:43 +02:00
|
|
|
const maximum_output_length = 150;
|
2023-08-16 03:52:29 +02:00
|
|
|
const default_presets = {
|
2023-12-02 19:04:51 +01:00
|
|
|
'clio-v1': 'Talker-Chat-Clio',
|
2023-12-02 21:06:57 +01:00
|
|
|
'kayra-v1': 'Carefree-Kayra',
|
2023-12-02 20:11:06 +01:00
|
|
|
};
|
2023-08-03 03:22:06 +02:00
|
|
|
|
2023-09-04 17:00:15 +02:00
|
|
|
export const nai_settings = {
|
2023-08-16 03:52:29 +02:00
|
|
|
temperature: 1.5,
|
|
|
|
repetition_penalty: 2.25,
|
|
|
|
repetition_penalty_range: 2048,
|
|
|
|
repetition_penalty_slope: 0.09,
|
2023-07-23 01:09:03 +02:00
|
|
|
repetition_penalty_frequency: 0,
|
2023-08-16 03:52:29 +02:00
|
|
|
repetition_penalty_presence: 0.005,
|
|
|
|
tail_free_sampling: 0.975,
|
|
|
|
top_k: 10,
|
|
|
|
top_p: 0.75,
|
|
|
|
top_a: 0.08,
|
|
|
|
typical_p: 0.975,
|
|
|
|
min_length: 1,
|
2023-12-02 19:04:51 +01:00
|
|
|
model_novel: 'clio-v1',
|
|
|
|
preset_settings_novel: 'Talker-Chat-Clio',
|
2023-07-20 19:32:15 +02:00
|
|
|
streaming_novel: false,
|
2023-08-18 16:43:50 +02:00
|
|
|
preamble: default_preamble,
|
2023-08-12 20:26:51 +02:00
|
|
|
prefix: '',
|
2023-08-13 14:38:07 +02:00
|
|
|
cfg_uc: '',
|
2023-08-15 14:51:14 +02:00
|
|
|
banned_tokens: '',
|
2023-08-16 19:34:47 +02:00
|
|
|
order: default_order,
|
2023-08-17 12:05:22 +02:00
|
|
|
logit_bias: [],
|
2023-07-20 19:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const nai_tiers = {
|
|
|
|
0: 'Paper',
|
|
|
|
1: 'Tablet',
|
|
|
|
2: 'Scroll',
|
|
|
|
3: 'Opus',
|
|
|
|
};
|
|
|
|
|
2023-08-10 18:15:52 +02:00
|
|
|
let novel_data = null;
|
2023-08-15 14:51:14 +02:00
|
|
|
let badWordsCache = {};
|
2023-12-18 16:32:10 +01:00
|
|
|
const BIAS_KEY = '#novel_api-settings';
|
2023-08-10 18:15:52 +02:00
|
|
|
|
|
|
|
export function setNovelData(data) {
|
|
|
|
novel_data = data;
|
|
|
|
}
|
|
|
|
|
2023-08-12 13:21:05 +02:00
|
|
|
export function getKayraMaxContextTokens() {
|
|
|
|
switch (novel_data?.tier) {
|
|
|
|
case 1:
|
|
|
|
return 3072;
|
|
|
|
case 2:
|
|
|
|
return 6144;
|
|
|
|
case 3:
|
|
|
|
return 8192;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-08-10 18:15:52 +02:00
|
|
|
}
|
|
|
|
|
2023-09-04 17:00:15 +02:00
|
|
|
export function getNovelTier() {
|
|
|
|
return nai_tiers[novel_data?.tier] ?? 'no_connection';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNovelAnlas() {
|
|
|
|
return novel_data?.trainingStepsLeft?.fixedTrainingStepsLeft ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNovelUnlimitedImageGeneration() {
|
|
|
|
return novel_data?.perks?.unlimitedImageGeneration ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function loadNovelSubscriptionData() {
|
2023-09-15 16:54:13 +02:00
|
|
|
const result = await fetch('/api/novelai/status', {
|
2023-09-04 17:00:15 +02:00
|
|
|
method: 'POST',
|
|
|
|
headers: getRequestHeaders(),
|
2023-11-08 01:52:03 +01:00
|
|
|
signal: abortStatusCheck.signal,
|
2023-09-04 17:00:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (result.ok) {
|
|
|
|
const data = await result.json();
|
|
|
|
setNovelData(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.ok;
|
2023-07-20 19:32:15 +02:00
|
|
|
}
|
|
|
|
|
2023-09-04 17:00:15 +02:00
|
|
|
export function loadNovelPreset(preset) {
|
2023-08-16 20:43:38 +02:00
|
|
|
if (preset.genamt === undefined) {
|
2023-12-03 17:30:21 +01:00
|
|
|
const needsUnlock = preset.max_context > MAX_CONTEXT_DEFAULT || preset.max_length > MAX_RESPONSE_DEFAULT;
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#amount_gen').val(preset.max_length).trigger('input');
|
2023-08-16 20:43:38 +02:00
|
|
|
$('#max_context_unlocked').prop('checked', needsUnlock).trigger('change');
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#max_context').val(preset.max_context).trigger('input');
|
2023-08-16 20:43:38 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
setGenerationParamsFromPreset(preset);
|
2023-07-20 19:32:15 +02:00
|
|
|
}
|
|
|
|
|
2023-07-23 01:09:03 +02:00
|
|
|
nai_settings.temperature = preset.temperature;
|
|
|
|
nai_settings.repetition_penalty = preset.repetition_penalty;
|
|
|
|
nai_settings.repetition_penalty_range = preset.repetition_penalty_range;
|
|
|
|
nai_settings.repetition_penalty_slope = preset.repetition_penalty_slope;
|
|
|
|
nai_settings.repetition_penalty_frequency = preset.repetition_penalty_frequency;
|
|
|
|
nai_settings.repetition_penalty_presence = preset.repetition_penalty_presence;
|
|
|
|
nai_settings.tail_free_sampling = preset.tail_free_sampling;
|
|
|
|
nai_settings.top_k = preset.top_k;
|
|
|
|
nai_settings.top_p = preset.top_p;
|
|
|
|
nai_settings.top_a = preset.top_a;
|
|
|
|
nai_settings.typical_p = preset.typical_p;
|
|
|
|
nai_settings.min_length = preset.min_length;
|
2023-07-29 01:23:10 +02:00
|
|
|
nai_settings.cfg_scale = preset.cfg_scale;
|
|
|
|
nai_settings.phrase_rep_pen = preset.phrase_rep_pen;
|
2023-08-12 02:58:40 +02:00
|
|
|
nai_settings.mirostat_lr = preset.mirostat_lr;
|
|
|
|
nai_settings.mirostat_tau = preset.mirostat_tau;
|
2023-08-12 20:26:51 +02:00
|
|
|
nai_settings.prefix = preset.prefix;
|
2023-08-13 14:38:07 +02:00
|
|
|
nai_settings.cfg_uc = preset.cfg_uc || '';
|
2023-08-15 14:51:14 +02:00
|
|
|
nai_settings.banned_tokens = preset.banned_tokens || '';
|
2023-08-16 19:34:47 +02:00
|
|
|
nai_settings.order = preset.order || default_order;
|
2023-08-17 12:05:22 +02:00
|
|
|
nai_settings.logit_bias = preset.logit_bias || [];
|
2023-08-18 16:43:50 +02:00
|
|
|
nai_settings.preamble = preset.preamble || default_preamble;
|
2023-07-20 19:32:15 +02:00
|
|
|
loadNovelSettingsUi(nai_settings);
|
|
|
|
}
|
|
|
|
|
2023-09-04 17:00:15 +02:00
|
|
|
export function loadNovelSettings(settings) {
|
2023-07-20 19:32:15 +02:00
|
|
|
//load the rest of the Novel settings without any checks
|
|
|
|
nai_settings.model_novel = settings.model_novel;
|
2023-07-23 01:09:03 +02:00
|
|
|
$('#model_novel_select').val(nai_settings.model_novel);
|
2023-12-18 16:32:10 +01:00
|
|
|
$(`#model_novel_select option[value=${nai_settings.model_novel}]`).prop('selected', true);
|
2023-07-20 19:32:15 +02:00
|
|
|
|
2023-08-18 16:43:50 +02:00
|
|
|
if (settings.nai_preamble !== undefined) {
|
|
|
|
nai_settings.preamble = settings.nai_preamble;
|
|
|
|
delete settings.nai_preamble;
|
|
|
|
}
|
2023-07-23 01:09:03 +02:00
|
|
|
nai_settings.preset_settings_novel = settings.preset_settings_novel;
|
|
|
|
nai_settings.temperature = settings.temperature;
|
|
|
|
nai_settings.repetition_penalty = settings.repetition_penalty;
|
|
|
|
nai_settings.repetition_penalty_range = settings.repetition_penalty_range;
|
|
|
|
nai_settings.repetition_penalty_slope = settings.repetition_penalty_slope;
|
|
|
|
nai_settings.repetition_penalty_frequency = settings.repetition_penalty_frequency;
|
|
|
|
nai_settings.repetition_penalty_presence = settings.repetition_penalty_presence;
|
|
|
|
nai_settings.tail_free_sampling = settings.tail_free_sampling;
|
|
|
|
nai_settings.top_k = settings.top_k;
|
|
|
|
nai_settings.top_p = settings.top_p;
|
|
|
|
nai_settings.top_a = settings.top_a;
|
|
|
|
nai_settings.typical_p = settings.typical_p;
|
|
|
|
nai_settings.min_length = settings.min_length;
|
2023-07-29 01:23:10 +02:00
|
|
|
nai_settings.phrase_rep_pen = settings.phrase_rep_pen;
|
|
|
|
nai_settings.cfg_scale = settings.cfg_scale;
|
2023-08-12 02:58:40 +02:00
|
|
|
nai_settings.mirostat_lr = settings.mirostat_lr;
|
|
|
|
nai_settings.mirostat_tau = settings.mirostat_tau;
|
2023-07-20 19:32:15 +02:00
|
|
|
nai_settings.streaming_novel = !!settings.streaming_novel;
|
2023-08-15 03:40:43 +02:00
|
|
|
nai_settings.preamble = settings.preamble || default_preamble;
|
2023-08-12 20:26:51 +02:00
|
|
|
nai_settings.prefix = settings.prefix;
|
2023-08-13 14:38:07 +02:00
|
|
|
nai_settings.cfg_uc = settings.cfg_uc || '';
|
2023-08-15 14:51:14 +02:00
|
|
|
nai_settings.banned_tokens = settings.banned_tokens || '';
|
2023-08-16 19:34:47 +02:00
|
|
|
nai_settings.order = settings.order || default_order;
|
2023-08-17 12:05:22 +02:00
|
|
|
nai_settings.logit_bias = settings.logit_bias || [];
|
2023-07-20 19:32:15 +02:00
|
|
|
loadNovelSettingsUi(nai_settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadNovelSettingsUi(ui_settings) {
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#temp_novel').val(ui_settings.temperature);
|
|
|
|
$('#temp_counter_novel').val(Number(ui_settings.temperature).toFixed(2));
|
|
|
|
$('#rep_pen_novel').val(ui_settings.repetition_penalty);
|
|
|
|
$('#rep_pen_counter_novel').val(Number(ui_settings.repetition_penalty).toFixed(2));
|
|
|
|
$('#rep_pen_size_novel').val(ui_settings.repetition_penalty_range);
|
|
|
|
$('#rep_pen_size_counter_novel').val(Number(ui_settings.repetition_penalty_range).toFixed(0));
|
|
|
|
$('#rep_pen_slope_novel').val(ui_settings.repetition_penalty_slope);
|
|
|
|
$('#rep_pen_slope_counter_novel').val(Number(`${ui_settings.repetition_penalty_slope}`).toFixed(2));
|
|
|
|
$('#rep_pen_freq_novel').val(ui_settings.repetition_penalty_frequency);
|
|
|
|
$('#rep_pen_freq_counter_novel').val(Number(ui_settings.repetition_penalty_frequency).toFixed(3));
|
|
|
|
$('#rep_pen_presence_novel').val(ui_settings.repetition_penalty_presence);
|
|
|
|
$('#rep_pen_presence_counter_novel').val(Number(ui_settings.repetition_penalty_presence).toFixed(3));
|
|
|
|
$('#tail_free_sampling_novel').val(ui_settings.tail_free_sampling);
|
|
|
|
$('#tail_free_sampling_counter_novel').val(Number(ui_settings.tail_free_sampling).toFixed(3));
|
|
|
|
$('#top_k_novel').val(ui_settings.top_k);
|
|
|
|
$('#top_k_counter_novel').val(Number(ui_settings.top_k).toFixed(0));
|
|
|
|
$('#top_p_novel').val(ui_settings.top_p);
|
|
|
|
$('#top_p_counter_novel').val(Number(ui_settings.top_p).toFixed(3));
|
|
|
|
$('#top_a_novel').val(ui_settings.top_a);
|
|
|
|
$('#top_a_counter_novel').val(Number(ui_settings.top_a).toFixed(3));
|
|
|
|
$('#typical_p_novel').val(ui_settings.typical_p);
|
|
|
|
$('#typical_p_counter_novel').val(Number(ui_settings.typical_p).toFixed(3));
|
|
|
|
$('#cfg_scale_novel').val(ui_settings.cfg_scale);
|
|
|
|
$('#cfg_scale_counter_novel').val(Number(ui_settings.cfg_scale).toFixed(2));
|
|
|
|
$('#phrase_rep_pen_novel').val(ui_settings.phrase_rep_pen || 'off');
|
|
|
|
$('#mirostat_lr_novel').val(ui_settings.mirostat_lr);
|
|
|
|
$('#mirostat_lr_counter_novel').val(Number(ui_settings.mirostat_lr).toFixed(2));
|
|
|
|
$('#mirostat_tau_novel').val(ui_settings.mirostat_tau);
|
|
|
|
$('#mirostat_tau_counter_novel').val(Number(ui_settings.mirostat_tau).toFixed(2));
|
|
|
|
$('#min_length_novel').val(ui_settings.min_length);
|
|
|
|
$('#min_length_counter_novel').val(Number(ui_settings.min_length).toFixed(0));
|
2023-08-18 16:43:50 +02:00
|
|
|
$('#nai_preamble_textarea').val(ui_settings.preamble);
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#nai_prefix').val(ui_settings.prefix || 'vanilla');
|
|
|
|
$('#nai_cfg_uc').val(ui_settings.cfg_uc || '');
|
|
|
|
$('#nai_banned_tokens').val(ui_settings.banned_tokens || '');
|
2023-07-23 01:09:03 +02:00
|
|
|
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#streaming_novel').prop('checked', ui_settings.streaming_novel);
|
2023-08-16 19:34:47 +02:00
|
|
|
sortItemsByOrder(ui_settings.order);
|
2023-12-18 16:32:10 +01:00
|
|
|
displayLogitBias(ui_settings.logit_bias, BIAS_KEY);
|
2023-07-20 19:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const sliders = [
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#temp_novel',
|
|
|
|
counterId: '#temp_counter_novel',
|
2023-07-20 19:32:15 +02:00
|
|
|
format: (val) => Number(val).toFixed(2),
|
2023-07-23 01:09:03 +02:00
|
|
|
setValue: (val) => { nai_settings.temperature = Number(val).toFixed(2); },
|
2023-07-20 19:32:15 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#rep_pen_novel',
|
|
|
|
counterId: '#rep_pen_counter_novel',
|
2023-07-20 19:32:15 +02:00
|
|
|
format: (val) => Number(val).toFixed(2),
|
2023-07-23 01:09:03 +02:00
|
|
|
setValue: (val) => { nai_settings.repetition_penalty = Number(val).toFixed(2); },
|
2023-07-20 19:32:15 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#rep_pen_size_novel',
|
|
|
|
counterId: '#rep_pen_size_counter_novel',
|
2023-07-20 19:32:15 +02:00
|
|
|
format: (val) => `${val}`,
|
2023-07-23 01:09:03 +02:00
|
|
|
setValue: (val) => { nai_settings.repetition_penalty_range = Number(val).toFixed(0); },
|
2023-07-20 19:32:15 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#rep_pen_slope_novel',
|
|
|
|
counterId: '#rep_pen_slope_counter_novel',
|
2023-07-20 19:32:15 +02:00
|
|
|
format: (val) => `${val}`,
|
2023-07-23 01:09:03 +02:00
|
|
|
setValue: (val) => { nai_settings.repetition_penalty_slope = Number(val).toFixed(2); },
|
2023-07-20 19:32:15 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#rep_pen_freq_novel',
|
|
|
|
counterId: '#rep_pen_freq_counter_novel',
|
2023-10-26 13:46:09 +02:00
|
|
|
format: (val) => Number(val).toFixed(2),
|
2023-11-06 22:03:22 +01:00
|
|
|
setValue: (val) => { nai_settings.repetition_penalty_frequency = Number(val).toFixed(3); },
|
2023-07-20 19:32:15 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#rep_pen_presence_novel',
|
|
|
|
counterId: '#rep_pen_presence_counter_novel',
|
2023-07-20 19:32:15 +02:00
|
|
|
format: (val) => `${val}`,
|
2023-11-06 22:03:22 +01:00
|
|
|
setValue: (val) => { nai_settings.repetition_penalty_presence = Number(val).toFixed(3); },
|
2023-07-20 19:32:15 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#tail_free_sampling_novel',
|
|
|
|
counterId: '#tail_free_sampling_counter_novel',
|
2023-07-20 19:32:15 +02:00
|
|
|
format: (val) => `${val}`,
|
2023-10-26 14:09:34 +02:00
|
|
|
setValue: (val) => { nai_settings.tail_free_sampling = Number(val).toFixed(3); },
|
2023-07-23 01:09:03 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#top_k_novel',
|
|
|
|
counterId: '#top_k_counter_novel',
|
2023-07-23 01:09:03 +02:00
|
|
|
format: (val) => `${val}`,
|
|
|
|
setValue: (val) => { nai_settings.top_k = Number(val).toFixed(0); },
|
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#top_p_novel',
|
|
|
|
counterId: '#top_p_counter_novel',
|
2023-10-26 14:17:16 +02:00
|
|
|
format: (val) => Number(val).toFixed(3),
|
2023-10-26 14:11:38 +02:00
|
|
|
setValue: (val) => { nai_settings.top_p = Number(val).toFixed(3); },
|
2023-07-23 01:09:03 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#top_a_novel',
|
|
|
|
counterId: '#top_a_counter_novel',
|
2023-07-23 01:09:03 +02:00
|
|
|
format: (val) => Number(val).toFixed(2),
|
2023-11-06 21:58:04 +01:00
|
|
|
setValue: (val) => { nai_settings.top_a = Number(val).toFixed(3); },
|
2023-07-23 01:09:03 +02:00
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#typical_p_novel',
|
|
|
|
counterId: '#typical_p_counter_novel',
|
2023-11-06 22:43:30 +01:00
|
|
|
format: (val) => Number(val).toFixed(3),
|
|
|
|
setValue: (val) => { nai_settings.typical_p = Number(val).toFixed(3); },
|
2023-07-23 01:09:03 +02:00
|
|
|
},
|
2023-08-12 02:58:40 +02:00
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#mirostat_tau_novel',
|
|
|
|
counterId: '#mirostat_tau_counter_novel',
|
2023-08-12 02:58:40 +02:00
|
|
|
format: (val) => Number(val).toFixed(2),
|
|
|
|
setValue: (val) => { nai_settings.mirostat_tau = Number(val).toFixed(2); },
|
|
|
|
},
|
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#mirostat_lr_novel',
|
|
|
|
counterId: '#mirostat_lr_counter_novel',
|
2023-08-12 02:58:40 +02:00
|
|
|
format: (val) => Number(val).toFixed(2),
|
|
|
|
setValue: (val) => { nai_settings.mirostat_lr = Number(val).toFixed(2); },
|
|
|
|
},
|
2023-07-29 01:23:10 +02:00
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#cfg_scale_novel',
|
|
|
|
counterId: '#cfg_scale_counter_novel',
|
2023-07-29 01:23:10 +02:00
|
|
|
format: (val) => `${val}`,
|
|
|
|
setValue: (val) => { nai_settings.cfg_scale = Number(val).toFixed(2); },
|
|
|
|
},
|
2023-07-23 01:09:03 +02:00
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#min_length_novel',
|
|
|
|
counterId: '#min_length_counter_novel',
|
2023-07-23 01:09:03 +02:00
|
|
|
format: (val) => `${val}`,
|
|
|
|
setValue: (val) => { nai_settings.min_length = Number(val).toFixed(0); },
|
2023-07-20 19:32:15 +02:00
|
|
|
},
|
2023-08-13 14:38:07 +02:00
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#nai_cfg_uc',
|
|
|
|
counterId: '#nai_cfg_uc_counter',
|
2023-08-13 14:38:07 +02:00
|
|
|
format: (val) => val,
|
|
|
|
setValue: (val) => { nai_settings.cfg_uc = val; },
|
|
|
|
},
|
2023-08-15 14:51:14 +02:00
|
|
|
{
|
2023-12-02 19:04:51 +01:00
|
|
|
sliderId: '#nai_banned_tokens',
|
|
|
|
counterId: '#nai_banned_tokens_counter',
|
2023-08-15 14:51:14 +02:00
|
|
|
format: (val) => val,
|
|
|
|
setValue: (val) => { nai_settings.banned_tokens = val; },
|
2023-12-02 21:06:57 +01:00
|
|
|
},
|
2023-07-20 19:32:15 +02:00
|
|
|
];
|
|
|
|
|
2023-08-15 14:51:14 +02:00
|
|
|
function getBadWordIds(banned_tokens, tokenizerType) {
|
|
|
|
if (tokenizerType === tokenizers.NONE) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const cacheKey = `${getStringHash(banned_tokens)}-${tokenizerType}`;
|
|
|
|
|
|
|
|
if (cacheKey in badWordsCache && Array.isArray(badWordsCache[cacheKey])) {
|
|
|
|
console.debug(`Bad words ids cache hit for "${banned_tokens}"`, badWordsCache[cacheKey]);
|
|
|
|
return badWordsCache[cacheKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = [];
|
|
|
|
const sequence = banned_tokens.split('\n');
|
|
|
|
|
|
|
|
for (let token of sequence) {
|
|
|
|
const trimmed = token.trim();
|
|
|
|
|
|
|
|
// Skip empty lines
|
|
|
|
if (trimmed.length === 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verbatim text
|
|
|
|
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
|
|
const tokens = getTextTokens(tokenizerType, trimmed.slice(1, -1));
|
|
|
|
result.push(tokens);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Raw token ids, JSON serialized
|
|
|
|
else if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
|
|
try {
|
|
|
|
const tokens = JSON.parse(trimmed);
|
|
|
|
|
|
|
|
if (Array.isArray(tokens) && tokens.every(t => Number.isInteger(t))) {
|
|
|
|
result.push(tokens);
|
|
|
|
} else {
|
|
|
|
throw new Error('Not an array of integers');
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log(`Failed to parse bad word token list: ${trimmed}`, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply permutations
|
|
|
|
else {
|
|
|
|
const permutations = getBadWordPermutations(trimmed).map(t => getTextTokens(tokenizerType, t));
|
|
|
|
result.push(...permutations);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache the result
|
|
|
|
console.debug(`Bad words ids for "${banned_tokens}"`, result);
|
|
|
|
badWordsCache[cacheKey] = result;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBadWordPermutations(text) {
|
|
|
|
const result = [];
|
|
|
|
|
|
|
|
// Original text
|
|
|
|
result.push(text);
|
|
|
|
// Original text + leading space
|
|
|
|
result.push(` ${text}`);
|
|
|
|
// First letter capitalized
|
|
|
|
result.push(text[0].toUpperCase() + text.slice(1));
|
|
|
|
// Ditto + leading space
|
|
|
|
result.push(` ${text[0].toUpperCase() + text.slice(1)}`);
|
|
|
|
// First letter lower cased
|
|
|
|
result.push(text[0].toLowerCase() + text.slice(1));
|
|
|
|
// Ditto + leading space
|
|
|
|
result.push(` ${text[0].toLowerCase() + text.slice(1)}`);
|
|
|
|
// Original all upper cased
|
|
|
|
result.push(text.toUpperCase());
|
|
|
|
// Ditto + leading space
|
|
|
|
result.push(` ${text.toUpperCase()}`);
|
|
|
|
// Original all lower cased
|
|
|
|
result.push(text.toLowerCase());
|
|
|
|
// Ditto + leading space
|
|
|
|
result.push(` ${text.toLowerCase()}`);
|
|
|
|
|
2023-09-15 16:54:13 +02:00
|
|
|
return result.filter(onlyUnique);
|
2023-08-15 14:51:14 +02:00
|
|
|
}
|
|
|
|
|
2023-12-03 19:56:25 +01:00
|
|
|
export function getNovelGenerationData(finalPrompt, settings, maxLength, isImpersonate, isContinue, cfgValues, type) {
|
|
|
|
console.debug('NovelAI generation data for', type);
|
2023-08-23 17:26:56 +02:00
|
|
|
if (cfgValues && cfgValues.guidanceScale && cfgValues.guidanceScale?.value !== 1) {
|
2023-08-21 01:51:01 +02:00
|
|
|
cfgValues.negativePrompt = (getCfgPrompt(cfgValues.guidanceScale, true))?.value;
|
|
|
|
}
|
|
|
|
|
2024-01-23 06:00:31 +01:00
|
|
|
const tokenizerType = getTokenizerTypeForModel(nai_settings.model_novel);
|
2023-08-02 21:35:05 +02:00
|
|
|
const stopSequences = (tokenizerType !== tokenizers.NONE)
|
2023-11-22 15:16:48 +01:00
|
|
|
? getStoppingStrings(isImpersonate, isContinue)
|
2023-08-02 21:35:05 +02:00
|
|
|
.map(t => getTextTokens(tokenizerType, t))
|
|
|
|
: undefined;
|
|
|
|
|
2023-08-15 14:51:14 +02:00
|
|
|
const badWordIds = (tokenizerType !== tokenizers.NONE)
|
|
|
|
? getBadWordIds(nai_settings.banned_tokens, tokenizerType)
|
|
|
|
: undefined;
|
|
|
|
|
2023-08-15 03:40:43 +02:00
|
|
|
const prefix = selectPrefix(nai_settings.prefix, finalPrompt);
|
2023-08-03 08:07:17 +02:00
|
|
|
|
2023-08-17 07:14:04 +02:00
|
|
|
let logitBias = [];
|
2023-08-17 12:05:22 +02:00
|
|
|
if (tokenizerType !== tokenizers.NONE && Array.isArray(nai_settings.logit_bias) && nai_settings.logit_bias.length) {
|
2023-12-18 16:32:10 +01:00
|
|
|
logitBias = BIAS_CACHE.get(BIAS_KEY) || calculateLogitBias();
|
|
|
|
BIAS_CACHE.set(BIAS_KEY, logitBias);
|
2023-08-17 07:14:04 +02:00
|
|
|
}
|
|
|
|
|
2023-12-19 19:27:24 +01:00
|
|
|
if (power_user.console_log_prompts) {
|
|
|
|
console.log(finalPrompt);
|
|
|
|
}
|
|
|
|
|
2023-07-20 19:32:15 +02:00
|
|
|
return {
|
2023-12-02 19:04:51 +01:00
|
|
|
'input': finalPrompt,
|
|
|
|
'model': nai_settings.model_novel,
|
|
|
|
'use_string': true,
|
|
|
|
'temperature': Number(nai_settings.temperature),
|
|
|
|
'max_length': maxLength < maximum_output_length ? maxLength : maximum_output_length,
|
|
|
|
'min_length': Number(nai_settings.min_length),
|
|
|
|
'tail_free_sampling': Number(nai_settings.tail_free_sampling),
|
|
|
|
'repetition_penalty': Number(nai_settings.repetition_penalty),
|
|
|
|
'repetition_penalty_range': Number(nai_settings.repetition_penalty_range),
|
|
|
|
'repetition_penalty_slope': Number(nai_settings.repetition_penalty_slope),
|
|
|
|
'repetition_penalty_frequency': Number(nai_settings.repetition_penalty_frequency),
|
|
|
|
'repetition_penalty_presence': Number(nai_settings.repetition_penalty_presence),
|
|
|
|
'top_a': Number(nai_settings.top_a),
|
|
|
|
'top_p': Number(nai_settings.top_p),
|
|
|
|
'top_k': Number(nai_settings.top_k),
|
|
|
|
'typical_p': Number(nai_settings.typical_p),
|
|
|
|
'mirostat_lr': Number(nai_settings.mirostat_lr),
|
|
|
|
'mirostat_tau': Number(nai_settings.mirostat_tau),
|
|
|
|
'cfg_scale': cfgValues?.guidanceScale?.value ?? Number(nai_settings.cfg_scale),
|
|
|
|
'cfg_uc': cfgValues?.negativePrompt ?? substituteParams(nai_settings.cfg_uc) ?? '',
|
|
|
|
'phrase_rep_pen': nai_settings.phrase_rep_pen,
|
|
|
|
'stop_sequences': stopSequences,
|
|
|
|
'bad_words_ids': badWordIds,
|
|
|
|
'logit_bias_exp': logitBias,
|
|
|
|
'generate_until_sentence': true,
|
|
|
|
'use_cache': false,
|
|
|
|
'return_full_text': false,
|
|
|
|
'prefix': prefix,
|
|
|
|
'order': nai_settings.order || settings.order || default_order,
|
2024-01-23 06:00:31 +01:00
|
|
|
'num_logprobs': power_user.request_token_probabilities ? 10 : undefined,
|
2023-07-20 19:32:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-15 03:40:43 +02:00
|
|
|
// Check if the prefix needs to be overriden to use instruct mode
|
2023-08-27 18:24:28 +02:00
|
|
|
function selectPrefix(selected_prefix, finalPrompt) {
|
2023-08-12 20:26:51 +02:00
|
|
|
let useInstruct = false;
|
|
|
|
const clio = nai_settings.model_novel.includes('clio');
|
|
|
|
const kayra = nai_settings.model_novel.includes('kayra');
|
|
|
|
const isNewModel = clio || kayra;
|
|
|
|
|
|
|
|
if (isNewModel) {
|
|
|
|
// NovelAI claims they scan backwards 1000 characters (not tokens!) to look for instruct brackets. That's really short.
|
2023-08-27 18:24:28 +02:00
|
|
|
const tail = finalPrompt.slice(-1500);
|
2023-12-02 19:04:51 +01:00
|
|
|
useInstruct = tail.includes('}');
|
|
|
|
return useInstruct ? 'special_instruct' : selected_prefix;
|
2023-08-12 20:26:51 +02:00
|
|
|
}
|
|
|
|
|
2023-12-02 19:04:51 +01:00
|
|
|
return 'vanilla';
|
2023-08-12 20:26:51 +02:00
|
|
|
}
|
|
|
|
|
2024-01-23 06:00:31 +01:00
|
|
|
function getTokenizerTypeForModel(model) {
|
|
|
|
if (model.includes('clio')) {
|
|
|
|
return tokenizers.NERD;
|
|
|
|
}
|
|
|
|
if (model.includes('kayra')) {
|
|
|
|
return tokenizers.NERD2;
|
|
|
|
}
|
|
|
|
return tokenizers.NONE;
|
|
|
|
}
|
|
|
|
|
2023-08-16 19:34:47 +02:00
|
|
|
// Sort the samplers by the order array
|
|
|
|
function sortItemsByOrder(orderArray) {
|
|
|
|
console.debug('Preset samplers order: ' + orderArray);
|
2023-12-02 19:04:51 +01:00
|
|
|
const $draggableItems = $('#novel_order');
|
2023-08-16 19:34:47 +02:00
|
|
|
|
|
|
|
// Sort the items by the order array
|
|
|
|
for (let i = 0; i < orderArray.length; i++) {
|
|
|
|
const index = orderArray[i];
|
|
|
|
const $item = $draggableItems.find(`[data-id="${index}"]`).detach();
|
|
|
|
$draggableItems.append($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the disabled class for each sampler
|
|
|
|
$draggableItems.children().each(function () {
|
|
|
|
const isEnabled = orderArray.includes(parseInt($(this).data('id')));
|
|
|
|
$(this).toggleClass('disabled', !isEnabled);
|
|
|
|
|
|
|
|
// If the sampler is disabled, move it to the bottom of the list
|
|
|
|
if (!isEnabled) {
|
|
|
|
const item = $(this).detach();
|
|
|
|
$draggableItems.append(item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveSamplingOrder() {
|
|
|
|
const order = [];
|
|
|
|
$('#novel_order').children().each(function () {
|
|
|
|
const isEnabled = !$(this).hasClass('disabled');
|
|
|
|
if (isEnabled) {
|
|
|
|
order.push($(this).data('id'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
nai_settings.order = order;
|
|
|
|
console.log('Samplers reordered:', nai_settings.order);
|
|
|
|
saveSettingsDebounced();
|
|
|
|
}
|
|
|
|
|
2023-08-27 17:57:07 +02:00
|
|
|
/**
|
|
|
|
* Calculates logit bias for Novel AI
|
|
|
|
* @returns {object[]} Array of logit bias objects
|
|
|
|
*/
|
2023-08-17 12:05:22 +02:00
|
|
|
function calculateLogitBias() {
|
2023-12-18 16:32:10 +01:00
|
|
|
const biasPreset = nai_settings.logit_bias;
|
2023-08-17 07:14:04 +02:00
|
|
|
|
2023-12-18 16:32:10 +01:00
|
|
|
if (!Array.isArray(biasPreset) || biasPreset.length === 0) {
|
2023-08-17 12:05:22 +02:00
|
|
|
return [];
|
2023-08-17 07:14:04 +02:00
|
|
|
}
|
|
|
|
|
2024-01-23 06:00:31 +01:00
|
|
|
const tokenizerType = getTokenizerTypeForModel(nai_settings.model_novel);
|
2023-08-17 07:14:04 +02:00
|
|
|
|
2023-08-27 17:57:07 +02:00
|
|
|
/**
|
|
|
|
* Creates a bias object for Novel AI
|
|
|
|
* @param {number} bias Bias value
|
|
|
|
* @param {number[]} sequence Sequence of token ids
|
|
|
|
*/
|
|
|
|
function getBiasObject(bias, sequence) {
|
|
|
|
return {
|
|
|
|
bias: bias,
|
|
|
|
ensure_sequence_finish: false,
|
|
|
|
generate_once: false,
|
2023-12-02 21:06:57 +01:00
|
|
|
sequence: sequence,
|
2023-08-27 17:57:07 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-12-18 16:32:10 +01:00
|
|
|
const result = getLogitBiasListResult(biasPreset, tokenizerType, getBiasObject);
|
2023-08-27 17:57:07 +02:00
|
|
|
return result;
|
2023-08-17 07:14:04 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 16:40:38 +02:00
|
|
|
/**
|
2023-08-20 08:11:53 +02:00
|
|
|
* Transforms instruction into compatible format for Novel AI if Novel AI instruct format not already detected.
|
2023-08-17 16:40:38 +02:00
|
|
|
* 1. Instruction must begin and end with curly braces followed and preceded by a space.
|
|
|
|
* 2. Instruction must not contain square brackets as it serves different purpose in NAI.
|
|
|
|
* @param {string} prompt Original instruction prompt
|
|
|
|
* @returns Processed prompt
|
|
|
|
*/
|
|
|
|
export function adjustNovelInstructionPrompt(prompt) {
|
2023-12-02 16:17:31 +01:00
|
|
|
const stripedPrompt = prompt.replace(/[[\]]/g, '').trim();
|
2023-08-20 08:11:53 +02:00
|
|
|
if (!stripedPrompt.includes('{ ')) {
|
|
|
|
return `{ ${stripedPrompt} }`;
|
|
|
|
}
|
|
|
|
return stripedPrompt;
|
2023-08-17 16:40:38 +02:00
|
|
|
}
|
|
|
|
|
2023-12-07 17:02:39 +01:00
|
|
|
function tryParseStreamingError(response, decoded) {
|
|
|
|
try {
|
|
|
|
const data = JSON.parse(decoded);
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-08 01:01:08 +01:00
|
|
|
if (data.message || data.error) {
|
|
|
|
toastr.error(data.message || data.error?.message || response.statusText, 'NovelAI API');
|
2023-12-07 17:02:39 +01:00
|
|
|
throw new Error(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
// No JSON. Do nothing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-20 19:32:15 +02:00
|
|
|
export async function generateNovelWithStreaming(generate_data, signal) {
|
2023-08-18 11:56:20 +02:00
|
|
|
generate_data.streaming = nai_settings.streaming_novel;
|
|
|
|
|
2023-09-15 16:54:13 +02:00
|
|
|
const response = await fetch('/api/novelai/generate', {
|
2023-07-20 19:32:15 +02:00
|
|
|
headers: getRequestHeaders(),
|
|
|
|
body: JSON.stringify(generate_data),
|
|
|
|
method: 'POST',
|
|
|
|
signal: signal,
|
|
|
|
});
|
2023-12-07 17:02:39 +01:00
|
|
|
if (!response.ok) {
|
2023-12-08 01:01:08 +01:00
|
|
|
tryParseStreamingError(response, await response.text());
|
2023-12-07 17:02:39 +01:00
|
|
|
throw new Error(`Got response status ${response.status}`);
|
|
|
|
}
|
2023-12-07 04:55:17 +01:00
|
|
|
const eventStream = new EventSourceStream();
|
|
|
|
response.body.pipeThrough(eventStream);
|
|
|
|
const reader = eventStream.readable.getReader();
|
2023-07-20 19:32:15 +02:00
|
|
|
|
|
|
|
return async function* streamData() {
|
2023-12-07 04:55:17 +01:00
|
|
|
let text = '';
|
2023-07-20 19:32:15 +02:00
|
|
|
while (true) {
|
|
|
|
const { done, value } = await reader.read();
|
2023-12-07 04:55:17 +01:00
|
|
|
if (done) return;
|
|
|
|
|
|
|
|
const data = JSON.parse(value.data);
|
2023-07-20 19:32:15 +02:00
|
|
|
|
2023-12-07 04:55:17 +01:00
|
|
|
if (data.token) {
|
|
|
|
text += data.token;
|
2023-07-20 19:32:15 +02:00
|
|
|
}
|
2023-12-07 04:55:17 +01:00
|
|
|
|
2024-01-23 06:00:31 +01:00
|
|
|
yield { text, swipes: [], logprobs: parseNovelAILogprobs(data.logprobs) };
|
2023-07-20 19:32:15 +02:00
|
|
|
}
|
2023-12-02 20:11:06 +01:00
|
|
|
};
|
2023-07-20 19:32:15 +02:00
|
|
|
}
|
|
|
|
|
2024-01-23 06:00:31 +01:00
|
|
|
/**
|
|
|
|
* A single token's ID.
|
|
|
|
* @typedef {[number]} TokenIdEntry
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* A single token's log probabilities. The first element is before repetition
|
|
|
|
* penalties and samplers are applied, the second is after.
|
|
|
|
* @typedef {[number, number]} LogprobsEntry
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Combination of token ID and its corresponding log probabilities.
|
|
|
|
* @typedef {[TokenIdEntry, LogprobsEntry]} TokenLogprobTuple
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Represents all logprob data for a single token, including its
|
|
|
|
* before, after, and the ultimately selected token.
|
|
|
|
* @typedef {Object} NAITokenLogprobs
|
|
|
|
* @property {TokenLogprobTuple[]} chosen - always length 1
|
|
|
|
* @property {TokenLogprobTuple[]} before - always `top_logprobs` length
|
|
|
|
* @property {TokenLogprobTuple[]} after - maybe less than `top_logprobs` length
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* parseNovelAILogprobs converts a logprobs object returned from the NovelAI API
|
|
|
|
* for a single token into a TokenLogprobs object used by the Token Probabilities
|
|
|
|
* feature.
|
|
|
|
* @param {NAITokenLogprobs} data - NAI logprobs object for one token
|
|
|
|
* @returns {import('logprobs.js').TokenLogprobs | null} converted logprobs
|
|
|
|
*/
|
|
|
|
export function parseNovelAILogprobs(data) {
|
|
|
|
if (!data) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const befores = data.before.map(([[tokenId], [before, _]]) => [tokenId, before]);
|
|
|
|
const afters = data.after.map(([[tokenId], [_, after]]) => [tokenId, after]);
|
|
|
|
|
|
|
|
// Find any tokens in `befores` that are missing from `afters`. Then add
|
|
|
|
// them with a logprob of -Infinity (0% probability)
|
|
|
|
const notInAfter = befores
|
|
|
|
.filter(([id]) => !afters.some(([aid]) => aid === id))
|
|
|
|
.map(([id]) => [id, -Infinity])
|
|
|
|
const merged = afters.concat(notInAfter);
|
|
|
|
|
|
|
|
// Add the chosen token to `merged` if it's not already there. This can
|
|
|
|
// happen if the chosen token was not among the top 10 most likely ones.
|
|
|
|
const [[chosenId], [_, chosenAfter]] = data.chosen[0];
|
|
|
|
if (!merged.some(([id]) => id === chosenId)) {
|
|
|
|
merged.push([chosenId, chosenAfter]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nb: returned logprobs are provided alongside token IDs, not decoded text.
|
|
|
|
// We don't want to send an API call for every streaming tick to decode the
|
|
|
|
// text so we will use the IDs instead and bulk decode them in
|
|
|
|
// StreamingProcessor. JSDoc typechecking may complain about this, but it's
|
|
|
|
// intentional.
|
|
|
|
return { token: chosenId, topLogprobs: merged };
|
|
|
|
}
|
|
|
|
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#nai_preamble_textarea').on('input', function () {
|
2023-08-23 17:26:56 +02:00
|
|
|
nai_settings.preamble = String($('#nai_preamble_textarea').val());
|
2023-08-03 03:22:06 +02:00
|
|
|
saveSettingsDebounced();
|
|
|
|
});
|
|
|
|
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#nai_preamble_restore').on('click', function () {
|
2023-08-04 03:22:46 +02:00
|
|
|
nai_settings.preamble = default_preamble;
|
|
|
|
$('#nai_preamble_textarea').val(nai_settings.preamble);
|
2023-08-03 03:22:06 +02:00
|
|
|
saveSettingsDebounced();
|
|
|
|
});
|
|
|
|
|
2023-08-18 12:41:46 +02:00
|
|
|
jQuery(function () {
|
2023-07-20 19:32:15 +02:00
|
|
|
sliders.forEach(slider => {
|
2023-12-02 19:04:51 +01:00
|
|
|
$(document).on('input', slider.sliderId, function () {
|
2023-07-20 19:32:15 +02:00
|
|
|
const value = $(this).val();
|
|
|
|
const formattedValue = slider.format(value);
|
|
|
|
slider.setValue(value);
|
2023-10-26 06:20:47 +02:00
|
|
|
$(slider.counterId).val(formattedValue);
|
2023-07-20 19:32:15 +02:00
|
|
|
saveSettingsDebounced();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#streaming_novel').on('input', function () {
|
|
|
|
const value = !!$(this).prop('checked');
|
|
|
|
nai_settings.streaming_novel = value;
|
|
|
|
saveSettingsDebounced();
|
|
|
|
});
|
|
|
|
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#model_novel_select').change(function () {
|
|
|
|
nai_settings.model_novel = String($('#model_novel_select').find(':selected').val());
|
2023-07-20 19:32:15 +02:00
|
|
|
saveSettingsDebounced();
|
2023-08-16 03:52:29 +02:00
|
|
|
|
|
|
|
// Update the selected preset to something appropriate
|
|
|
|
const default_preset = default_presets[nai_settings.model_novel];
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#settings_preset_novel').val(novelai_setting_names[default_preset]);
|
2023-12-02 20:11:06 +01:00
|
|
|
$(`#settings_preset_novel option[value=${novelai_setting_names[default_preset]}]`).attr('selected', 'true');
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#settings_preset_novel').trigger('change');
|
2023-07-20 19:32:15 +02:00
|
|
|
});
|
2023-08-12 20:26:51 +02:00
|
|
|
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#nai_prefix').on('change', function () {
|
|
|
|
nai_settings.prefix = String($('#nai_prefix').find(':selected').val());
|
2023-08-12 20:26:51 +02:00
|
|
|
saveSettingsDebounced();
|
|
|
|
});
|
2023-08-14 18:00:36 +02:00
|
|
|
|
2023-12-02 19:04:51 +01:00
|
|
|
$('#phrase_rep_pen_novel').on('change', function () {
|
|
|
|
nai_settings.phrase_rep_pen = String($('#phrase_rep_pen_novel').find(':selected').val());
|
2023-08-14 18:00:36 +02:00
|
|
|
saveSettingsDebounced();
|
|
|
|
});
|
2023-08-16 19:34:47 +02:00
|
|
|
|
|
|
|
$('#novel_order').sortable({
|
2023-08-18 12:41:46 +02:00
|
|
|
delay: getSortableDelay(),
|
2023-08-16 19:34:47 +02:00
|
|
|
stop: saveSamplingOrder,
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#novel_order .toggle_button').on('click', function () {
|
|
|
|
const $item = $(this).closest('[data-id]');
|
|
|
|
const isEnabled = !$item.hasClass('disabled');
|
|
|
|
$item.toggleClass('disabled', isEnabled);
|
|
|
|
console.log('Sampler toggled:', $item.data('id'), !isEnabled);
|
|
|
|
saveSamplingOrder();
|
|
|
|
});
|
2023-08-17 07:14:04 +02:00
|
|
|
|
2023-12-18 16:32:10 +01:00
|
|
|
$('#novelai_logit_bias_new_entry').on('click', () => createNewLogitBiasEntry(nai_settings.logit_bias, BIAS_KEY));
|
2023-07-20 19:32:15 +02:00
|
|
|
});
|