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 | generateNovelWithStreaming, | 119 | generateNovelWithStreaming, |
| 120 | getNovelGenerationData, | 120 | getNovelGenerationData, |
| 121 | getKayraMaxContextTokens, | 121 | getKayraMaxContextTokens, |
| 122 | getNovelTier, | ||
| 123 | loadNovelPreset, | ||
| 124 | loadNovelSettings, | 122 | loadNovelSettings, |
| 125 | nai_settings, | 123 | nai_settings, |
| 126 | adjustNovelInstructionPrompt, | 124 | adjustNovelInstructionPrompt, |
| 127 | loadNovelSubscriptionData, | ||
| 128 | parseNovelAILogprobs, | 125 | parseNovelAILogprobs, |
| 126 | novelai_settings, | ||
| 127 | novelai_setting_names, | ||
| 128 | initNovelAISettings, | ||
| 129 | } from './scripts/nai-settings.js'; | 129 | } from './scripts/nai-settings.js'; |
| 130 | 130 | ||
| 131 | import { | 131 | import { |
| @@ -210,7 +210,6 @@ import { | |||
| 210 | SECRET_KEYS, | 210 | SECRET_KEYS, |
| 211 | initSecrets, | 211 | initSecrets, |
| 212 | readSecretState, | 212 | readSecretState, |
| 213 | secret_state, | ||
| 214 | writeSecret, | 213 | writeSecret, |
| 215 | } from './scripts/secrets.js'; | 214 | } from './scripts/secrets.js'; |
| 216 | import { EventEmitter } from './lib/eventemitter.js'; | 215 | import { EventEmitter } from './lib/eventemitter.js'; |
| @@ -325,6 +324,8 @@ export { | |||
| 325 | findItemizedPromptSet, | 324 | findItemizedPromptSet, |
| 326 | koboldai_settings, | 325 | koboldai_settings, |
| 327 | koboldai_setting_names, | 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 | export let extension_prompts = {}; | 919 | export let extension_prompts = {}; |
| 919 | 920 | ||
| 920 | export let main_api;// = "kobold"; | 921 | export let main_api;// = "kobold"; |
| 921 | //novel settings | ||
| 922 | export let novelai_settings; | ||
| 923 | export let novelai_setting_names; | ||
| 924 | /** @type {AbortController} */ | 922 | /** @type {AbortController} */ |
| 925 | let abortController; | 923 | let abortController; |
| 926 | 924 | ||
| @@ -1006,6 +1004,7 @@ async function firstLoadInit() { | |||
| 1006 | initTextGenModels(); | 1004 | initTextGenModels(); |
| 1007 | initOpenAI(); | 1005 | initOpenAI(); |
| 1008 | initKoboldSettings(); | 1006 | initKoboldSettings(); |
| 1007 | initNovelAISettings(); | ||
| 1009 | initSystemPrompts(); | 1008 | initSystemPrompts(); |
| 1010 | initExtensions(); | 1009 | initExtensions(); |
| 1011 | initExtensionSlashCommands(); | 1010 | initExtensionSlashCommands(); |
| @@ -1256,22 +1255,6 @@ async function getStatusTextgen() { | |||
| 1256 | return resultCheckStatus(); | 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 | export function startStatusLoading() { | 1258 | export function startStatusLoading() { |
| 1276 | $('.api_loading').show(); | 1259 | $('.api_loading').show(); |
| 1277 | $('.api_button').addClass('disabled'); | 1260 | $('.api_button').addClass('disabled'); |
| @@ -7282,22 +7265,6 @@ export async function getSettings() { | |||
| 7282 | // Allow subscribers to mutate settings | 7265 | // Allow subscribers to mutate settings |
| 7283 | await eventSource.emit(event_types.SETTINGS_LOADED_BEFORE, settings); | 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 | //Load AI model config settings | 7268 | //Load AI model config settings |
| 7302 | amount_gen = settings.amount_gen; | 7269 | amount_gen = settings.amount_gen; |
| 7303 | if (settings.max_context !== undefined) | 7270 | if (settings.max_context !== undefined) |
| @@ -7312,8 +7279,7 @@ export async function getSettings() { | |||
| 7312 | loadKoboldSettings(data, settings.kai_settings ?? settings, settings); | 7279 | loadKoboldSettings(data, settings.kai_settings ?? settings, settings); |
| 7313 | 7280 | ||
| 7314 | // Novel | 7281 | // Novel |
| 7315 | loadNovelSettings(settings.nai_settings ?? settings); | 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 | // TextGen | 7284 | // TextGen |
| 7319 | loadTextGenSettings(data, settings); | 7285 | loadTextGenSettings(data, settings); |
| @@ -10825,23 +10791,6 @@ jQuery(async function () { | |||
| 10825 | getStatusTextgen(); | 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 | const button = $('#options_button'); | 10795 | const button = $('#options_button'); |
| 10847 | const menu = $('#options'); | 10796 | const menu = $('#options'); |
| @@ -11063,19 +11012,6 @@ jQuery(async function () { | |||
| 11063 | is_delete_mode = false; | 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 | $('#main_api').on('change', function () { | 11015 | $('#main_api').on('change', function () { |
| 11080 | cancelStatusCheck('Canceled because main api changed'); | 11016 | cancelStatusCheck('Canceled because main api changed'); |
| 11081 | changeMainAPI(); | 11017 | changeMainAPI(); |
| @@ -2,9 +2,11 @@ import { | |||
| 2 | abortStatusCheck, | 2 | abortStatusCheck, |
| 3 | getRequestHeaders, | 3 | getRequestHeaders, |
| 4 | getStoppingStrings, | 4 | getStoppingStrings, |
| 5 | novelai_setting_names, | 5 | resultCheckStatus, |
| 6 | saveSettingsDebounced, | 6 | saveSettingsDebounced, |
| 7 | setGenerationParamsFromPreset, | 7 | setGenerationParamsFromPreset, |
| 8 | setOnlineStatus, | ||
| 9 | startStatusLoading, | ||
| 8 | } from '../script.js'; | 10 | } from '../script.js'; |
| 9 | import { MAX_CONTEXT_DEFAULT, MAX_RESPONSE_DEFAULT, power_user } from './power-user.js'; | 11 | import { MAX_CONTEXT_DEFAULT, MAX_RESPONSE_DEFAULT, power_user } from './power-user.js'; |
| 10 | import { getTextTokens, tokenizers } from './tokenizers.js'; | 12 | import { getTextTokens, tokenizers } from './tokenizers.js'; |
| @@ -15,6 +17,7 @@ import { | |||
| 15 | onlyUnique, | 17 | onlyUnique, |
| 16 | } from './utils.js'; | 18 | } from './utils.js'; |
| 17 | import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js'; | 19 | import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js'; |
| 20 | import { SECRET_KEYS, secret_state, writeSecret } from './secrets.js'; | ||
| 18 | 21 | ||
| 19 | const default_preamble = '[ Style: chat, complex, sensory, visceral ]'; | 22 | const default_preamble = '[ Style: chat, complex, sensory, visceral ]'; |
| 20 | const default_order = [1, 5, 0, 2, 3, 4]; | 23 | const default_order = [1, 5, 0, 2, 3, 4]; |
| @@ -25,6 +28,9 @@ const default_presets = { | |||
| 25 | 'llama-3-erato-v1': 'Erato-Dragonfruit', | 28 | 'llama-3-erato-v1': 'Erato-Dragonfruit', |
| 26 | }; | 29 | }; |
| 27 | 30 | ||
| 31 | export let novelai_settings; | ||
| 32 | export let novelai_setting_names; | ||
| 33 | |||
| 28 | export const nai_settings = { | 34 | export const nai_settings = { |
| 29 | temperature: 1.5, | 35 | temperature: 1.5, |
| 30 | repetition_penalty: 2.25, | 36 | repetition_penalty: 2.25, |
| @@ -202,7 +208,21 @@ export function loadNovelPreset(preset) { | |||
| 202 | loadNovelSettingsUi(nai_settings); | 208 | loadNovelSettingsUi(nai_settings); |
| 203 | } | 209 | } |
| 204 | 210 | ||
| 205 | export function loadNovelSettings(settings) { | 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 | //load the rest of the Novel settings without any checks | 226 | //load the rest of the Novel settings without any checks |
| 207 | nai_settings.model_novel = settings.model_novel; | 227 | nai_settings.model_novel = settings.model_novel; |
| 208 | $('#model_novel_select').val(nai_settings.model_novel); | 228 | $('#model_novel_select').val(nai_settings.model_novel); |
| @@ -282,6 +302,7 @@ function loadNovelSettingsUi(ui_settings) { | |||
| 282 | $('#math1_quad_counter_novel').val(Number(ui_settings.math1_quad).toFixed(2)); | 302 | $('#math1_quad_counter_novel').val(Number(ui_settings.math1_quad).toFixed(2)); |
| 283 | $('#math1_quad_entropy_scale_novel').val(ui_settings.math1_quad_entropy_scale); | 303 | $('#math1_quad_entropy_scale_novel').val(ui_settings.math1_quad_entropy_scale); |
| 284 | $('#math1_quad_entropy_scale_counter_novel').val(Number(ui_settings.math1_quad_entropy_scale).toFixed(2)); | 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 | $('#streaming_novel').prop('checked', ui_settings.streaming_novel); | 307 | $('#streaming_novel').prop('checked', ui_settings.streaming_novel); |
| 287 | sortItemsByOrder(ui_settings.order); | 308 | sortItemsByOrder(ui_settings.order); |
| @@ -293,85 +314,85 @@ const sliders = [ | |||
| 293 | sliderId: '#temp_novel', | 314 | sliderId: '#temp_novel', |
| 294 | counterId: '#temp_counter_novel', | 315 | counterId: '#temp_counter_novel', |
| 295 | format: (val) => Number(val).toFixed(2), | 316 | format: (val) => Number(val).toFixed(2), |
| 296 | setValue: (val) => { nai_settings.temperature = Number(val).toFixed(2); }, | 317 | setValue: (val) => { nai_settings.temperature = Number(val); }, |
| 297 | }, | 318 | }, |
| 298 | { | 319 | { |
| 299 | sliderId: '#rep_pen_novel', | 320 | sliderId: '#rep_pen_novel', |
| 300 | counterId: '#rep_pen_counter_novel', | 321 | counterId: '#rep_pen_counter_novel', |
| 301 | format: (val) => Number(val).toFixed(3), | 322 | format: (val) => Number(val).toFixed(3), |
| 302 | setValue: (val) => { nai_settings.repetition_penalty = Number(val).toFixed(3); }, | 323 | setValue: (val) => { nai_settings.repetition_penalty = Number(val); }, |
| 303 | }, | 324 | }, |
| 304 | { | 325 | { |
| 305 | sliderId: '#rep_pen_size_novel', | 326 | sliderId: '#rep_pen_size_novel', |
| 306 | counterId: '#rep_pen_size_counter_novel', | 327 | counterId: '#rep_pen_size_counter_novel', |
| 307 | format: (val) => `${val}`, | 328 | format: (val) => `${val}`, |
| 308 | setValue: (val) => { nai_settings.repetition_penalty_range = Number(val).toFixed(0); }, | 329 | setValue: (val) => { nai_settings.repetition_penalty_range = Number(val); }, |
| 309 | }, | 330 | }, |
| 310 | { | 331 | { |
| 311 | sliderId: '#rep_pen_slope_novel', | 332 | sliderId: '#rep_pen_slope_novel', |
| 312 | counterId: '#rep_pen_slope_counter_novel', | 333 | counterId: '#rep_pen_slope_counter_novel', |
| 313 | format: (val) => `${val}`, | 334 | format: (val) => `${val}`, |
| 314 | setValue: (val) => { nai_settings.repetition_penalty_slope = Number(val).toFixed(2); }, | 335 | setValue: (val) => { nai_settings.repetition_penalty_slope = Number(val); }, |
| 315 | }, | 336 | }, |
| 316 | { | 337 | { |
| 317 | sliderId: '#rep_pen_freq_novel', | 338 | sliderId: '#rep_pen_freq_novel', |
| 318 | counterId: '#rep_pen_freq_counter_novel', | 339 | counterId: '#rep_pen_freq_counter_novel', |
| 319 | format: (val) => Number(val).toFixed(2), | 340 | format: (val) => Number(val).toFixed(2), |
| 320 | setValue: (val) => { nai_settings.repetition_penalty_frequency = Number(val).toFixed(3); }, | 341 | setValue: (val) => { nai_settings.repetition_penalty_frequency = Number(val); }, |
| 321 | }, | 342 | }, |
| 322 | { | 343 | { |
| 323 | sliderId: '#rep_pen_presence_novel', | 344 | sliderId: '#rep_pen_presence_novel', |
| 324 | counterId: '#rep_pen_presence_counter_novel', | 345 | counterId: '#rep_pen_presence_counter_novel', |
| 325 | format: (val) => `${val}`, | 346 | format: (val) => `${val}`, |
| 326 | setValue: (val) => { nai_settings.repetition_penalty_presence = Number(val).toFixed(3); }, | 347 | setValue: (val) => { nai_settings.repetition_penalty_presence = Number(val); }, |
| 327 | }, | 348 | }, |
| 328 | { | 349 | { |
| 329 | sliderId: '#tail_free_sampling_novel', | 350 | sliderId: '#tail_free_sampling_novel', |
| 330 | counterId: '#tail_free_sampling_counter_novel', | 351 | counterId: '#tail_free_sampling_counter_novel', |
| 331 | format: (val) => `${val}`, | 352 | format: (val) => `${val}`, |
| 332 | setValue: (val) => { nai_settings.tail_free_sampling = Number(val).toFixed(3); }, | 353 | setValue: (val) => { nai_settings.tail_free_sampling = Number(val); }, |
| 333 | }, | 354 | }, |
| 334 | { | 355 | { |
| 335 | sliderId: '#top_k_novel', | 356 | sliderId: '#top_k_novel', |
| 336 | counterId: '#top_k_counter_novel', | 357 | counterId: '#top_k_counter_novel', |
| 337 | format: (val) => `${val}`, | 358 | format: (val) => `${val}`, |
| 338 | setValue: (val) => { nai_settings.top_k = Number(val).toFixed(0); }, | 359 | setValue: (val) => { nai_settings.top_k = Number(val); }, |
| 339 | }, | 360 | }, |
| 340 | { | 361 | { |
| 341 | sliderId: '#top_p_novel', | 362 | sliderId: '#top_p_novel', |
| 342 | counterId: '#top_p_counter_novel', | 363 | counterId: '#top_p_counter_novel', |
| 343 | format: (val) => Number(val).toFixed(3), | 364 | format: (val) => Number(val).toFixed(3), |
| 344 | setValue: (val) => { nai_settings.top_p = Number(val).toFixed(3); }, | 365 | setValue: (val) => { nai_settings.top_p = Number(val); }, |
| 345 | }, | 366 | }, |
| 346 | { | 367 | { |
| 347 | sliderId: '#top_a_novel', | 368 | sliderId: '#top_a_novel', |
| 348 | counterId: '#top_a_counter_novel', | 369 | counterId: '#top_a_counter_novel', |
| 349 | format: (val) => Number(val).toFixed(2), | 370 | format: (val) => Number(val).toFixed(2), |
| 350 | setValue: (val) => { nai_settings.top_a = Number(val).toFixed(3); }, | 371 | setValue: (val) => { nai_settings.top_a = Number(val); }, |
| 351 | }, | 372 | }, |
| 352 | { | 373 | { |
| 353 | sliderId: '#typical_p_novel', | 374 | sliderId: '#typical_p_novel', |
| 354 | counterId: '#typical_p_counter_novel', | 375 | counterId: '#typical_p_counter_novel', |
| 355 | format: (val) => Number(val).toFixed(3), | 376 | format: (val) => Number(val).toFixed(3), |
| 356 | setValue: (val) => { nai_settings.typical_p = Number(val).toFixed(3); }, | 377 | setValue: (val) => { nai_settings.typical_p = Number(val); }, |
| 357 | }, | 378 | }, |
| 358 | { | 379 | { |
| 359 | sliderId: '#mirostat_tau_novel', | 380 | sliderId: '#mirostat_tau_novel', |
| 360 | counterId: '#mirostat_tau_counter_novel', | 381 | counterId: '#mirostat_tau_counter_novel', |
| 361 | format: (val) => Number(val).toFixed(2), | 382 | format: (val) => Number(val).toFixed(2), |
| 362 | setValue: (val) => { nai_settings.mirostat_tau = Number(val).toFixed(2); }, | 383 | setValue: (val) => { nai_settings.mirostat_tau = Number(val); }, |
| 363 | }, | 384 | }, |
| 364 | { | 385 | { |
| 365 | sliderId: '#mirostat_lr_novel', | 386 | sliderId: '#mirostat_lr_novel', |
| 366 | counterId: '#mirostat_lr_counter_novel', | 387 | counterId: '#mirostat_lr_counter_novel', |
| 367 | format: (val) => Number(val).toFixed(2), | 388 | format: (val) => Number(val).toFixed(2), |
| 368 | setValue: (val) => { nai_settings.mirostat_lr = Number(val).toFixed(2); }, | 389 | setValue: (val) => { nai_settings.mirostat_lr = Number(val); }, |
| 369 | }, | 390 | }, |
| 370 | { | 391 | { |
| 371 | sliderId: '#min_length_novel', | 392 | sliderId: '#min_length_novel', |
| 372 | counterId: '#min_length_counter_novel', | 393 | counterId: '#min_length_counter_novel', |
| 373 | format: (val) => `${val}`, | 394 | format: (val) => `${val}`, |
| 374 | setValue: (val) => { nai_settings.min_length = Number(val).toFixed(0); }, | 395 | setValue: (val) => { nai_settings.min_length = Number(val); }, |
| 375 | }, | 396 | }, |
| 376 | { | 397 | { |
| 377 | sliderId: '#nai_banned_tokens', | 398 | sliderId: '#nai_banned_tokens', |
| @@ -777,7 +798,7 @@ export async function generateNovelWithStreaming(generate_data, signal) { | |||
| 777 | * for a single token into a TokenLogprobs object used by the Token Probabilities | 798 | * for a single token into a TokenLogprobs object used by the Token Probabilities |
| 778 | * feature. | 799 | * feature. |
| 779 | * @param {NAITokenLogprobs} data - NAI logprobs object for one token | 800 | * @param {NAITokenLogprobs} data - NAI logprobs object for one token |
| 780 | * @returns {import('logprobs.js').TokenLogprobs | null} converted logprobs | 801 | * @returns {import('./logprobs.js').TokenLogprobs | null} converted logprobs |
| 781 | */ | 802 | */ |
| 782 | export function parseNovelAILogprobs(data) { | 803 | export function parseNovelAILogprobs(data) { |
| 783 | if (!data) { | 804 | if (!data) { |
| @@ -806,6 +827,7 @@ export function parseNovelAILogprobs(data) { | |||
| 806 | // text so we will use the IDs instead and bulk decode them in | 827 | // text so we will use the IDs instead and bulk decode them in |
| 807 | // StreamingProcessor. JSDoc typechecking may complain about this, but it's | 828 | // StreamingProcessor. JSDoc typechecking may complain about this, but it's |
| 808 | // intentional. | 829 | // intentional. |
| 830 | // @ts-ignore | ||
| 809 | return { token: chosenId, topLogprobs: merged }; | 831 | return { token: chosenId, topLogprobs: merged }; |
| 810 | } | 832 | } |
| 811 | 833 | ||
| @@ -820,7 +842,23 @@ $('#nai_preamble_restore').on('click', function () { | |||
| 820 | saveSettingsDebounced(); | 842 | saveSettingsDebounced(); |
| 821 | }); | 843 | }); |
| 822 | 844 | ||
| 823 | jQuery(function () { | 845 | 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 | sliders.forEach(slider => { | 862 | sliders.forEach(slider => { |
| 825 | $(document).on('input', slider.sliderId, function () { | 863 | $(document).on('input', slider.sliderId, function () { |
| 826 | const value = $(this).val(); | 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 | $('#streaming_novel').on('input', function () { | 896 | $('#streaming_novel').on('input', function () { |
| 835 | const value = !!$(this).prop('checked'); | 897 | const value = !!$(this).prop('checked'); |
| 836 | nai_settings.streaming_novel = value; | 898 | nai_settings.streaming_novel = value; |
| @@ -872,4 +934,4 @@ jQuery(function () { | |||
| 872 | }); | 934 | }); |
| 873 | 935 | ||
| 874 | $('#novelai_logit_bias_new_entry').on('click', () => createNewLogitBiasEntry(nai_settings.logit_bias, BIAS_KEY)); | 936 | $('#novelai_logit_bias_new_entry').on('click', () => createNewLogitBiasEntry(nai_settings.logit_bias, BIAS_KEY)); |
| 875 | }); | 937 | } |