Move NovelAI settings to respective module (#4238) * Move NovelAI settings to respective module * Update public/scripts/nai-settings.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed| @@ -119,13 +119,13 @@ import { | ||
| 119 | 119 | generateNovelWithStreaming, |
| 120 | 120 | getNovelGenerationData, |
| 121 | 121 | getKayraMaxContextTokens, |
| 122 | - getNovelTier, | |
| 123 | - loadNovelPreset, | |
| 124 | 122 | loadNovelSettings, |
| 125 | 123 | nai_settings, |
| 126 | 124 | adjustNovelInstructionPrompt, |
| 127 | - loadNovelSubscriptionData, | |
| 128 | 125 | parseNovelAILogprobs, |
| 126 | + novelai_settings, | |
| 127 | + novelai_setting_names, | |
| 128 | + initNovelAISettings, | |
| 129 | 129 | } from './scripts/nai-settings.js'; |
| 130 | 130 | |
| 131 | 131 | import { |
| @@ -210,7 +210,6 @@ import { | ||
| 210 | 210 | SECRET_KEYS, |
| 211 | 211 | initSecrets, |
| 212 | 212 | readSecretState, |
| 213 | - secret_state, | |
| 214 | 213 | writeSecret, |
| 215 | 214 | } from './scripts/secrets.js'; |
| 216 | 215 | import { EventEmitter } from './lib/eventemitter.js'; |
| @@ -325,6 +324,8 @@ export { | ||
| 325 | 324 | findItemizedPromptSet, |
| 326 | 325 | koboldai_settings, |
| 327 | 326 | koboldai_setting_names, |
| 327 | + novelai_settings, | |
| 328 | + novelai_setting_names, | |
| 328 | 329 | }; |
| 329 | 330 | |
| 330 | 331 | /** |
| @@ -918,9 +919,6 @@ var swipes = true; | ||
| 918 | 919 | export let extension_prompts = {}; |
| 919 | 920 | |
| 920 | 921 | export let main_api;// = "kobold"; |
| 921 | -//novel settings | |
| 922 | -export let novelai_settings; | |
| 923 | -export let novelai_setting_names; | |
| 924 | 922 | /** @type {AbortController} */ |
| 925 | 923 | let abortController; |
| 926 | 924 | |
| @@ -1006,6 +1004,7 @@ async function firstLoadInit() { | ||
| 1006 | 1004 | initTextGenModels(); |
| 1007 | 1005 | initOpenAI(); |
| 1008 | 1006 | initKoboldSettings(); |
| 1007 | + initNovelAISettings(); | |
| 1009 | 1008 | initSystemPrompts(); |
| 1010 | 1009 | initExtensions(); |
| 1011 | 1010 | initExtensionSlashCommands(); |
| @@ -1256,22 +1255,6 @@ async function getStatusTextgen() { | ||
| 1256 | 1255 | return resultCheckStatus(); |
| 1257 | 1256 | } |
| 1258 | 1257 | |
| 1259 | -async function getStatusNovel() { | |
| 1260 | - try { | |
| 1261 | - const result = await loadNovelSubscriptionData(); | |
| 1262 | - | |
| 1263 | - if (!result) { | |
| 1264 | - throw new Error('Could not load subscription data'); | |
| 1265 | - } | |
| 1266 | - | |
| 1267 | - setOnlineStatus(getNovelTier()); | |
| 1268 | - } catch { | |
| 1269 | - setOnlineStatus('no_connection'); | |
| 1270 | - } | |
| 1271 | - | |
| 1272 | - resultCheckStatus(); | |
| 1273 | -} | |
| 1274 | - | |
| 1275 | 1258 | export function startStatusLoading() { |
| 1276 | 1259 | $('.api_loading').show(); |
| 1277 | 1260 | $('.api_button').addClass('disabled'); |
| @@ -7282,22 +7265,6 @@ export async function getSettings() { | ||
| 7282 | 7265 | // Allow subscribers to mutate settings |
| 7283 | 7266 | await eventSource.emit(event_types.SETTINGS_LOADED_BEFORE, settings); |
| 7284 | 7267 | |
| 7285 | - novelai_setting_names = data.novelai_setting_names; | |
| 7286 | - novelai_settings = data.novelai_settings; | |
| 7287 | - novelai_settings.forEach(function (item, i, arr) { | |
| 7288 | - novelai_settings[i] = JSON.parse(item); | |
| 7289 | - }); | |
| 7290 | - const arr_holder = {}; | |
| 7291 | - | |
| 7292 | - $('#settings_preset_novel').empty(); | |
| 7293 | - | |
| 7294 | - novelai_setting_names.forEach(function (item, i, arr) { | |
| 7295 | - arr_holder[item] = i; | |
| 7296 | - $('#settings_preset_novel').append(`<option value=${i}>${item}</option>`); | |
| 7297 | - }); | |
| 7298 | - novelai_setting_names = {}; | |
| 7299 | - novelai_setting_names = arr_holder; | |
| 7300 | - | |
| 7301 | 7268 | //Load AI model config settings |
| 7302 | 7269 | amount_gen = settings.amount_gen; |
| 7303 | 7270 | if (settings.max_context !== undefined) |
| @@ -7312,8 +7279,7 @@ export async function getSettings() { | ||
| 7312 | 7279 | loadKoboldSettings(data, settings.kai_settings ?? settings, settings); |
| 7313 | 7280 | |
| 7314 | 7281 | // Novel |
| 7315 | 7282 | loadNovelSettings(data, settings.nai_settings ?? settings); |
| 7316 | - $(`#settings_preset_novel option[value=${novelai_setting_names[nai_settings.preset_settings_novel]}]`).attr('selected', 'true'); | |
| 7317 | 7283 | |
| 7318 | 7284 | // TextGen |
| 7319 | 7285 | loadTextGenSettings(data, settings); |
| @@ -10825,23 +10791,6 @@ jQuery(async function () { | ||
| 10825 | 10791 | getStatusTextgen(); |
| 10826 | 10792 | }); |
| 10827 | 10793 | |
| 10828 | - $('#api_button_novel').on('click', async function (e) { | |
| 10829 | - e.stopPropagation(); | |
| 10830 | - const api_key_novel = String($('#api_key_novel').val()).trim(); | |
| 10831 | - | |
| 10832 | - if (api_key_novel.length) { | |
| 10833 | - await writeSecret(SECRET_KEYS.NOVEL, api_key_novel); | |
| 10834 | - } | |
| 10835 | - | |
| 10836 | - if (!secret_state[SECRET_KEYS.NOVEL]) { | |
| 10837 | - console.log('No secret key saved for NovelAI'); | |
| 10838 | - return; | |
| 10839 | - } | |
| 10840 | - | |
| 10841 | - startStatusLoading(); | |
| 10842 | - // Check near immediately rather than waiting for up to 90s | |
| 10843 | - await getStatusNovel(); | |
| 10844 | - }); | |
| 10845 | 10794 | |
| 10846 | 10795 | const button = $('#options_button'); |
| 10847 | 10796 | const menu = $('#options'); |
| @@ -11063,19 +11012,6 @@ jQuery(async function () { | ||
| 11063 | 11012 | is_delete_mode = false; |
| 11064 | 11013 | }); |
| 11065 | 11014 | |
| 11066 | - $('#settings_preset_novel').on('change', function () { | |
| 11067 | - nai_settings.preset_settings_novel = $('#settings_preset_novel') | |
| 11068 | - .find(':selected') | |
| 11069 | - .text(); | |
| 11070 | - | |
| 11071 | - const preset = novelai_settings[novelai_setting_names[nai_settings.preset_settings_novel]]; | |
| 11072 | - loadNovelPreset(preset); | |
| 11073 | - amount_gen = Number($('#amount_gen').val()); | |
| 11074 | - max_context = Number($('#max_context').val()); | |
| 11075 | - | |
| 11076 | - saveSettingsDebounced(); | |
| 11077 | - }); | |
| 11078 | - | |
| 11079 | 11015 | $('#main_api').on('change', function () { |
| 11080 | 11016 | cancelStatusCheck('Canceled because main api changed'); |
| 11081 | 11017 | changeMainAPI(); |
| @@ -2,9 +2,11 @@ import { | ||
| 2 | 2 | abortStatusCheck, |
| 3 | 3 | getRequestHeaders, |
| 4 | 4 | getStoppingStrings, |
| 5 | 5 | novelai_setting_namesresultCheckStatus, |
| 6 | 6 | saveSettingsDebounced, |
| 7 | 7 | setGenerationParamsFromPreset, |
| 8 | + setOnlineStatus, | |
| 9 | + startStatusLoading, | |
| 8 | 10 | } from '../script.js'; |
| 9 | 11 | import { MAX_CONTEXT_DEFAULT, MAX_RESPONSE_DEFAULT, power_user } from './power-user.js'; |
| 10 | 12 | import { getTextTokens, tokenizers } from './tokenizers.js'; |
| @@ -15,6 +17,7 @@ import { | ||
| 15 | 17 | onlyUnique, |
| 16 | 18 | } from './utils.js'; |
| 17 | 19 | import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js'; |
| 20 | +import { SECRET_KEYS, secret_state, writeSecret } from './secrets.js'; | |
| 18 | 21 | |
| 19 | 22 | const default_preamble = '[ Style: chat, complex, sensory, visceral ]'; |
| 20 | 23 | const default_order = [1, 5, 0, 2, 3, 4]; |
| @@ -25,6 +28,9 @@ const default_presets = { | ||
| 25 | 28 | 'llama-3-erato-v1': 'Erato-Dragonfruit', |
| 26 | 29 | }; |
| 27 | 30 | |
| 31 | +export let novelai_settings; | |
| 32 | +export let novelai_setting_names; | |
| 33 | + | |
| 28 | 34 | export const nai_settings = { |
| 29 | 35 | temperature: 1.5, |
| 30 | 36 | repetition_penalty: 2.25, |
| @@ -202,7 +208,21 @@ export function loadNovelPreset(preset) { | ||
| 202 | 208 | loadNovelSettingsUi(nai_settings); |
| 203 | 209 | } |
| 204 | 210 | |
| 205 | 211 | export function loadNovelSettings(data, settings) { |
| 212 | + novelai_setting_names = data.novelai_setting_names; | |
| 213 | + novelai_settings = data.novelai_settings; | |
| 214 | + novelai_settings.forEach(function (item, i, arr) { | |
| 215 | + novelai_settings[i] = JSON.parse(item); | |
| 216 | + }); | |
| 217 | + | |
| 218 | + $('#settings_preset_novel').empty(); | |
| 219 | + const presetNames = {}; | |
| 220 | + novelai_setting_names.forEach(function (item, i, arr) { | |
| 221 | + presetNames[item] = i; | |
| 222 | + $('#settings_preset_novel').append(`<option value=${i}>${item}</option>`); | |
| 223 | + }); | |
| 224 | + novelai_setting_names = presetNames; | |
| 225 | + | |
| 206 | 226 | //load the rest of the Novel settings without any checks |
| 207 | 227 | nai_settings.model_novel = settings.model_novel; |
| 208 | 228 | $('#model_novel_select').val(nai_settings.model_novel); |
| @@ -282,6 +302,7 @@ function loadNovelSettingsUi(ui_settings) { | ||
| 282 | 302 | $('#math1_quad_counter_novel').val(Number(ui_settings.math1_quad).toFixed(2)); |
| 283 | 303 | $('#math1_quad_entropy_scale_novel').val(ui_settings.math1_quad_entropy_scale); |
| 284 | 304 | $('#math1_quad_entropy_scale_counter_novel').val(Number(ui_settings.math1_quad_entropy_scale).toFixed(2)); |
| 305 | + $(`#settings_preset_novel option[value=${novelai_setting_names[nai_settings.preset_settings_novel]}]`).prop('selected', true); | |
| 285 | 306 | |
| 286 | 307 | $('#streaming_novel').prop('checked', ui_settings.streaming_novel); |
| 287 | 308 | sortItemsByOrder(ui_settings.order); |
| @@ -293,85 +314,85 @@ const sliders = [ | ||
| 293 | 314 | sliderId: '#temp_novel', |
| 294 | 315 | counterId: '#temp_counter_novel', |
| 295 | 316 | format: (val) => Number(val).toFixed(2), |
| 296 | 317 | setValue: (val) => { nai_settings.temperature = Number(val).toFixed(2); }, |
| 297 | 318 | }, |
| 298 | 319 | { |
| 299 | 320 | sliderId: '#rep_pen_novel', |
| 300 | 321 | counterId: '#rep_pen_counter_novel', |
| 301 | 322 | format: (val) => Number(val).toFixed(3), |
| 302 | 323 | setValue: (val) => { nai_settings.repetition_penalty = Number(val).toFixed(3); }, |
| 303 | 324 | }, |
| 304 | 325 | { |
| 305 | 326 | sliderId: '#rep_pen_size_novel', |
| 306 | 327 | counterId: '#rep_pen_size_counter_novel', |
| 307 | 328 | format: (val) => `${val}`, |
| 308 | 329 | setValue: (val) => { nai_settings.repetition_penalty_range = Number(val).toFixed(0); }, |
| 309 | 330 | }, |
| 310 | 331 | { |
| 311 | 332 | sliderId: '#rep_pen_slope_novel', |
| 312 | 333 | counterId: '#rep_pen_slope_counter_novel', |
| 313 | 334 | format: (val) => `${val}`, |
| 314 | 335 | setValue: (val) => { nai_settings.repetition_penalty_slope = Number(val).toFixed(2); }, |
| 315 | 336 | }, |
| 316 | 337 | { |
| 317 | 338 | sliderId: '#rep_pen_freq_novel', |
| 318 | 339 | counterId: '#rep_pen_freq_counter_novel', |
| 319 | 340 | format: (val) => Number(val).toFixed(2), |
| 320 | 341 | setValue: (val) => { nai_settings.repetition_penalty_frequency = Number(val).toFixed(3); }, |
| 321 | 342 | }, |
| 322 | 343 | { |
| 323 | 344 | sliderId: '#rep_pen_presence_novel', |
| 324 | 345 | counterId: '#rep_pen_presence_counter_novel', |
| 325 | 346 | format: (val) => `${val}`, |
| 326 | 347 | setValue: (val) => { nai_settings.repetition_penalty_presence = Number(val).toFixed(3); }, |
| 327 | 348 | }, |
| 328 | 349 | { |
| 329 | 350 | sliderId: '#tail_free_sampling_novel', |
| 330 | 351 | counterId: '#tail_free_sampling_counter_novel', |
| 331 | 352 | format: (val) => `${val}`, |
| 332 | 353 | setValue: (val) => { nai_settings.tail_free_sampling = Number(val).toFixed(3); }, |
| 333 | 354 | }, |
| 334 | 355 | { |
| 335 | 356 | sliderId: '#top_k_novel', |
| 336 | 357 | counterId: '#top_k_counter_novel', |
| 337 | 358 | format: (val) => `${val}`, |
| 338 | 359 | setValue: (val) => { nai_settings.top_k = Number(val).toFixed(0); }, |
| 339 | 360 | }, |
| 340 | 361 | { |
| 341 | 362 | sliderId: '#top_p_novel', |
| 342 | 363 | counterId: '#top_p_counter_novel', |
| 343 | 364 | format: (val) => Number(val).toFixed(3), |
| 344 | 365 | setValue: (val) => { nai_settings.top_p = Number(val).toFixed(3); }, |
| 345 | 366 | }, |
| 346 | 367 | { |
| 347 | 368 | sliderId: '#top_a_novel', |
| 348 | 369 | counterId: '#top_a_counter_novel', |
| 349 | 370 | format: (val) => Number(val).toFixed(2), |
| 350 | 371 | setValue: (val) => { nai_settings.top_a = Number(val).toFixed(3); }, |
| 351 | 372 | }, |
| 352 | 373 | { |
| 353 | 374 | sliderId: '#typical_p_novel', |
| 354 | 375 | counterId: '#typical_p_counter_novel', |
| 355 | 376 | format: (val) => Number(val).toFixed(3), |
| 356 | 377 | setValue: (val) => { nai_settings.typical_p = Number(val).toFixed(3); }, |
| 357 | 378 | }, |
| 358 | 379 | { |
| 359 | 380 | sliderId: '#mirostat_tau_novel', |
| 360 | 381 | counterId: '#mirostat_tau_counter_novel', |
| 361 | 382 | format: (val) => Number(val).toFixed(2), |
| 362 | 383 | setValue: (val) => { nai_settings.mirostat_tau = Number(val).toFixed(2); }, |
| 363 | 384 | }, |
| 364 | 385 | { |
| 365 | 386 | sliderId: '#mirostat_lr_novel', |
| 366 | 387 | counterId: '#mirostat_lr_counter_novel', |
| 367 | 388 | format: (val) => Number(val).toFixed(2), |
| 368 | 389 | setValue: (val) => { nai_settings.mirostat_lr = Number(val).toFixed(2); }, |
| 369 | 390 | }, |
| 370 | 391 | { |
| 371 | 392 | sliderId: '#min_length_novel', |
| 372 | 393 | counterId: '#min_length_counter_novel', |
| 373 | 394 | format: (val) => `${val}`, |
| 374 | 395 | setValue: (val) => { nai_settings.min_length = Number(val).toFixed(0); }, |
| 375 | 396 | }, |
| 376 | 397 | { |
| 377 | 398 | sliderId: '#nai_banned_tokens', |
| @@ -777,7 +798,7 @@ export async function generateNovelWithStreaming(generate_data, signal) { | ||
| 777 | 798 | * for a single token into a TokenLogprobs object used by the Token Probabilities |
| 778 | 799 | * feature. |
| 779 | 800 | * @param {NAITokenLogprobs} data - NAI logprobs object for one token |
| 780 | 801 | * @returns {import('./logprobs.js').TokenLogprobs | null} converted logprobs |
| 781 | 802 | */ |
| 782 | 803 | export function parseNovelAILogprobs(data) { |
| 783 | 804 | if (!data) { |
| @@ -806,6 +827,7 @@ export function parseNovelAILogprobs(data) { | ||
| 806 | 827 | // text so we will use the IDs instead and bulk decode them in |
| 807 | 828 | // StreamingProcessor. JSDoc typechecking may complain about this, but it's |
| 808 | 829 | // intentional. |
| 830 | + // @ts-ignore | |
| 809 | 831 | return { token: chosenId, topLogprobs: merged }; |
| 810 | 832 | } |
| 811 | 833 | |
| @@ -820,7 +842,23 @@ $('#nai_preamble_restore').on('click', function () { | ||
| 820 | 842 | saveSettingsDebounced(); |
| 821 | 843 | }); |
| 822 | 844 | |
| 823 | 845 | jQuery(export async function getStatusNovel() { |
| 846 | + try { | |
| 847 | + const result = await loadNovelSubscriptionData(); | |
| 848 | + | |
| 849 | + if (!result) { | |
| 850 | + throw new Error('Could not load subscription data'); | |
| 851 | + } | |
| 852 | + | |
| 853 | + setOnlineStatus(getNovelTier()); | |
| 854 | + } catch { | |
| 855 | + setOnlineStatus('no_connection'); | |
| 856 | + } | |
| 857 | + | |
| 858 | + return resultCheckStatus(); | |
| 859 | +} | |
| 860 | + | |
| 861 | +export function initNovelAISettings() { | |
| 824 | 862 | sliders.forEach(slider => { |
| 825 | 863 | $(document).on('input', slider.sliderId, function () { |
| 826 | 864 | const value = $(this).val(); |
| @@ -831,6 +869,30 @@ jQuery(function () { | ||
| 831 | 869 | }); |
| 832 | 870 | }); |
| 833 | 871 | |
| 872 | + $('#api_button_novel').on('click', async function (e) { | |
| 873 | + e.stopPropagation(); | |
| 874 | + const api_key_novel = String($('#api_key_novel').val()).trim(); | |
| 875 | + | |
| 876 | + if (api_key_novel.length) { | |
| 877 | + await writeSecret(SECRET_KEYS.NOVEL, api_key_novel); | |
| 878 | + } | |
| 879 | + | |
| 880 | + if (!secret_state[SECRET_KEYS.NOVEL]) { | |
| 881 | + console.log('No secret key saved for NovelAI'); | |
| 882 | + return; | |
| 883 | + } | |
| 884 | + | |
| 885 | + startStatusLoading(); | |
| 886 | + await getStatusNovel(); | |
| 887 | + }); | |
| 888 | + | |
| 889 | + $('#settings_preset_novel').on('change', function () { | |
| 890 | + nai_settings.preset_settings_novel = $('#settings_preset_novel').find(':selected').text(); | |
| 891 | + const preset = novelai_settings[novelai_setting_names[nai_settings.preset_settings_novel]]; | |
| 892 | + loadNovelPreset(preset); | |
| 893 | + saveSettingsDebounced(); | |
| 894 | + }); | |
| 895 | + | |
| 834 | 896 | $('#streaming_novel').on('input', function () { |
| 835 | 897 | const value = !!$(this).prop('checked'); |
| 836 | 898 | nai_settings.streaming_novel = value; |
| @@ -872,4 +934,4 @@ jQuery(function () { | ||
| 872 | 934 | }); |
| 873 | 935 | |
| 874 | 936 | $('#novelai_logit_bias_new_entry').on('click', () => createNewLogitBiasEntry(nai_settings.logit_bias, BIAS_KEY)); |
| 875 | 937 | }); |