Move Kobold Classic settings into related module (#4234) * Move Kobold Classic settings into related module * Update public/scripts/kai-settings.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed| @@ -17,10 +17,11 @@ import { | ||
| 17 | 17 | generateKoboldWithStreaming, |
| 18 | 18 | kai_settings, |
| 19 | 19 | loadKoboldSettings, |
| 20 | - formatKoboldUrl, | |
| 21 | 20 | getKoboldGenerationData, |
| 22 | 21 | kai_flags, |
| 23 | 22 | setKoboldFlagskoboldai_settings, |
| 23 | + koboldai_setting_names, | |
| 24 | + initKoboldSettings, | |
| 24 | 25 | } from './scripts/kai-settings.js'; |
| 25 | 26 | |
| 26 | 27 | import { |
| @@ -303,9 +304,6 @@ globalThis.SillyTavern = { | ||
| 303 | 304 | getContext, |
| 304 | 305 | }; |
| 305 | 306 | |
| 306 | -/** | |
| 307 | - * Exports that were once part of this module. For backwards compatibility. | |
| 308 | - */ | |
| 309 | 307 | export { |
| 310 | 308 | user_avatar, |
| 311 | 309 | setUserAvatar, |
| @@ -324,6 +322,8 @@ export { | ||
| 324 | 322 | replaceItemizedPromptText, |
| 325 | 323 | deleteItemizedPrompts, |
| 326 | 324 | findItemizedPromptSet, |
| 325 | + koboldai_settings, | |
| 326 | + koboldai_setting_names, | |
| 327 | 327 | }; |
| 328 | 328 | |
| 329 | 329 | /** |
| @@ -900,8 +900,6 @@ let popup_type = ''; | ||
| 900 | 900 | let chat_file_for_del = ''; |
| 901 | 901 | export let online_status = 'no_connection'; |
| 902 | 902 | |
| 903 | -export let api_server = ''; | |
| 904 | - | |
| 905 | 903 | export let is_send_press = false; //Send generation |
| 906 | 904 | |
| 907 | 905 | let this_del_mes = -1; |
| @@ -912,9 +910,6 @@ var this_edit_mes_id; | ||
| 912 | 910 | |
| 913 | 911 | //settings |
| 914 | 912 | export let settings; |
| 915 | -export let koboldai_settings; | |
| 916 | -export let koboldai_setting_names; | |
| 917 | -var preset_settings = 'gui'; | |
| 918 | 913 | export let amount_gen = 80; //default max length of AI generated responses |
| 919 | 914 | export let max_context = 2048; |
| 920 | 915 | |
| @@ -1009,6 +1004,7 @@ async function firstLoadInit() { | ||
| 1009 | 1004 | initDefaultSlashCommands(); |
| 1010 | 1005 | initTextGenModels(); |
| 1011 | 1006 | initOpenAI(); |
| 1007 | + initKoboldSettings(); | |
| 1012 | 1008 | initSystemPrompts(); |
| 1013 | 1009 | initExtensions(); |
| 1014 | 1010 | initExtensionSlashCommands(); |
| @@ -1120,52 +1116,6 @@ async function getStatusHorde() { | ||
| 1120 | 1116 | return resultCheckStatus(); |
| 1121 | 1117 | } |
| 1122 | 1118 | |
| 1123 | -async function getStatusKobold() { | |
| 1124 | - let endpoint = api_server; | |
| 1125 | - | |
| 1126 | - if (!endpoint) { | |
| 1127 | - console.warn('No endpoint for status check'); | |
| 1128 | - setOnlineStatus('no_connection'); | |
| 1129 | - return resultCheckStatus(); | |
| 1130 | - } | |
| 1131 | - | |
| 1132 | - try { | |
| 1133 | - const response = await fetch('/api/backends/kobold/status', { | |
| 1134 | - method: 'POST', | |
| 1135 | - headers: getRequestHeaders(), | |
| 1136 | - body: JSON.stringify({ | |
| 1137 | - main_api, | |
| 1138 | - api_server: endpoint, | |
| 1139 | - }), | |
| 1140 | - signal: abortStatusCheck.signal, | |
| 1141 | - }); | |
| 1142 | - | |
| 1143 | - const data = await response.json(); | |
| 1144 | - | |
| 1145 | - setOnlineStatus(data?.model ?? 'no_connection'); | |
| 1146 | - | |
| 1147 | - if (!data.koboldUnitedVersion) { | |
| 1148 | - throw new Error('Missing mandatory Kobold version in data:', data); | |
| 1149 | - } | |
| 1150 | - | |
| 1151 | - // Determine instruct mode preset | |
| 1152 | - autoSelectInstructPreset(online_status); | |
| 1153 | - | |
| 1154 | - // determine if we can use stop sequence and streaming | |
| 1155 | - setKoboldFlags(data.koboldUnitedVersion, data.koboldCppVersion); | |
| 1156 | - | |
| 1157 | - // We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress. | |
| 1158 | - if (online_status === 'no_connection' && data.response) { | |
| 1159 | - toastr.error(data.response, t`API Error`, { timeOut: 5000, preventDuplicates: true }); | |
| 1160 | - } | |
| 1161 | - } catch (err) { | |
| 1162 | - console.error('Error getting status', err); | |
| 1163 | - setOnlineStatus('no_connection'); | |
| 1164 | - } | |
| 1165 | - | |
| 1166 | - return resultCheckStatus(); | |
| 1167 | -} | |
| 1168 | - | |
| 1169 | 1119 | async function getStatusTextgen() { |
| 1170 | 1120 | const url = '/api/backends/text-completions/status'; |
| 1171 | 1121 | |
| @@ -3716,11 +3666,11 @@ export async function generateRaw(prompt, api, instructOverride, quietToLoud, sy | ||
| 3716 | 3666 | switch (api) { |
| 3717 | 3667 | case 'kobold': |
| 3718 | 3668 | case 'koboldhorde': |
| 3719 | 3669 | if (kai_settings.preset_settings === 'gui') { |
| 3720 | 3670 | generateData = { prompt: prompt, gui_settings: true, max_length: amount_gen, max_context_length: max_context, api_server: kai_settings.api_server }; |
| 3721 | 3671 | } else { |
| 3722 | 3672 | const isHorde = api === 'koboldhorde'; |
| 3723 | 3673 | const koboldSettings = koboldai_settings[koboldai_setting_names[kai_settings.preset_settings]]; |
| 3724 | 3674 | generateData = getKoboldGenerationData(prompt, koboldSettings, amount_gen, max_context, isHorde, 'quiet'); |
| 3725 | 3675 | } |
| 3726 | 3676 | TempResponseLength.restore(api); |
| @@ -4871,12 +4821,12 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4871 | 4821 | gui_settings: true, |
| 4872 | 4822 | max_length: maxLength, |
| 4873 | 4823 | max_context_length: max_context, |
| 4874 | 4824 | api_server: kai_settings.api_server, |
| 4875 | 4825 | }; |
| 4876 | 4826 | |
| 4877 | 4827 | if (kai_settings.preset_settings != 'gui') { |
| 4878 | 4828 | const isHorde = main_api == 'koboldhorde'; |
| 4879 | 4829 | const presetSettings = koboldai_settings[koboldai_setting_names[kai_settings.preset_settings]]; |
| 4880 | 4830 | const maxContext = (adjustedParams && horde_settings.auto_adjust_context_length) ? adjustedParams.maxContextLength : max_context; |
| 4881 | 4831 | generate_data = getKoboldGenerationData(finalPrompt, presetSettings, maxLength, maxContext, isHorde, type); |
| 4882 | 4832 | } |
| @@ -7329,47 +7279,12 @@ export async function getSettings() { | ||
| 7329 | 7279 | // Allow subscribers to mutate settings |
| 7330 | 7280 | await eventSource.emit(event_types.SETTINGS_LOADED_BEFORE, settings); |
| 7331 | 7281 | |
| 7332 | - //Load KoboldAI settings | |
| 7333 | - koboldai_setting_names = data.koboldai_setting_names; | |
| 7334 | - koboldai_settings = data.koboldai_settings; | |
| 7335 | - koboldai_settings.forEach(function (item, i, arr) { | |
| 7336 | - koboldai_settings[i] = JSON.parse(item); | |
| 7337 | - }); | |
| 7338 | - | |
| 7339 | - let arr_holder = {}; | |
| 7340 | - | |
| 7341 | - $('#settings_preset').empty(); | |
| 7342 | - $('#settings_preset').append( | |
| 7343 | - '<option value="gui">GUI KoboldAI Settings</option>', | |
| 7344 | - ); //adding in the GUI settings, since it is not loaded dynamically | |
| 7345 | - | |
| 7346 | - koboldai_setting_names.forEach(function (item, i, arr) { | |
| 7347 | - arr_holder[item] = i; | |
| 7348 | - $('#settings_preset').append(`<option value=${i}>${item}</option>`); | |
| 7349 | - //console.log('loading preset #'+i+' -- '+item); | |
| 7350 | - }); | |
| 7351 | - koboldai_setting_names = {}; | |
| 7352 | - koboldai_setting_names = arr_holder; | |
| 7353 | - preset_settings = settings.preset_settings; | |
| 7354 | - | |
| 7355 | - if (preset_settings == 'gui') { | |
| 7356 | - selectKoboldGuiPreset(); | |
| 7357 | - } else { | |
| 7358 | - if (typeof koboldai_setting_names[preset_settings] !== 'undefined') { | |
| 7359 | - $(`#settings_preset option[value=${koboldai_setting_names[preset_settings]}]`) | |
| 7360 | - .attr('selected', 'true'); | |
| 7361 | - } else { | |
| 7362 | - preset_settings = 'gui'; | |
| 7363 | - selectKoboldGuiPreset(); | |
| 7364 | - } | |
| 7365 | - } | |
| 7366 | - | |
| 7367 | 7282 | novelai_setting_names = data.novelai_setting_names; |
| 7368 | 7283 | novelai_settings = data.novelai_settings; |
| 7369 | 7284 | novelai_settings.forEach(function (item, i, arr) { |
| 7370 | 7285 | novelai_settings[i] = JSON.parse(item); |
| 7371 | 7286 | }); |
| 7372 | 7287 | const arr_holder = {}; |
| 7373 | 7288 | |
| 7374 | 7289 | $('#settings_preset_novel').empty(); |
| 7375 | 7290 | |
| @@ -7381,7 +7296,6 @@ export async function getSettings() { | ||
| 7381 | 7296 | novelai_setting_names = arr_holder; |
| 7382 | 7297 | |
| 7383 | 7298 | //Load AI model config settings |
| 7384 | - | |
| 7385 | 7299 | amount_gen = settings.amount_gen; |
| 7386 | 7300 | if (settings.max_context !== undefined) |
| 7387 | 7301 | max_context = parseInt(settings.max_context); |
| @@ -7392,7 +7306,7 @@ export async function getSettings() { | ||
| 7392 | 7306 | showSwipeButtons(); |
| 7393 | 7307 | |
| 7394 | 7308 | // Kobold |
| 7395 | 7309 | loadKoboldSettings(data, settings.kai_settings ?? settings, settings); |
| 7396 | 7310 | |
| 7397 | 7311 | // Novel |
| 7398 | 7312 | loadNovelSettings(settings.nai_settings ?? settings); |
| @@ -7401,7 +7315,6 @@ export async function getSettings() { | ||
| 7401 | 7315 | // TextGen |
| 7402 | 7316 | loadTextGenSettings(data, settings); |
| 7403 | 7317 | |
| 7404 | - | |
| 7405 | 7318 | // OpenAI |
| 7406 | 7319 | loadOpenAISettings(data, settings.oai_settings ?? settings); |
| 7407 | 7320 | |
| @@ -7444,13 +7357,9 @@ export async function getSettings() { | ||
| 7444 | 7357 | |
| 7445 | 7358 | main_api = settings.main_api; |
| 7446 | 7359 | $('#main_api').val(main_api); |
| 7447 | 7360 | $('`#main_api option[value=' + ${main_api + '}]'`).attr('selected', 'true'); |
| 7448 | - 'selected', | |
| 7449 | - 'true', | |
| 7450 | - ); | |
| 7451 | 7361 | changeMainAPI(); |
| 7452 | 7362 | |
| 7453 | - | |
| 7454 | 7363 | //Load User's Name and Avatar |
| 7455 | 7364 | initUserAvatar(settings.user_avatar); |
| 7456 | 7365 | setPersonaDescription(); |
| @@ -7459,10 +7368,6 @@ export async function getSettings() { | ||
| 7459 | 7368 | active_character = settings.active_character; |
| 7460 | 7369 | active_group = settings.active_group; |
| 7461 | 7370 | |
| 7462 | - //Load the API server URL from settings | |
| 7463 | - api_server = settings.api_server; | |
| 7464 | - $('#api_url_text').val(api_server); | |
| 7465 | - | |
| 7466 | 7371 | setWorldInfoSettings(settings.world_info_settings ?? settings, data); |
| 7467 | 7372 | |
| 7468 | 7373 | selected_button = settings.selected_button; |
| @@ -7487,12 +7392,6 @@ export async function getSettings() { | ||
| 7487 | 7392 | await eventSource.emit(event_types.SETTINGS_LOADED); |
| 7488 | 7393 | } |
| 7489 | 7394 | |
| 7490 | -function selectKoboldGuiPreset() { | |
| 7491 | - $('#settings_preset option[value=gui]') | |
| 7492 | - .attr('selected', 'true') | |
| 7493 | - .trigger('change'); | |
| 7494 | -} | |
| 7495 | - | |
| 7496 | 7395 | //MARK: saveSettings() |
| 7497 | 7396 | export async function saveSettings(loopCounter = 0) { |
| 7498 | 7397 | if (!settingsReady) { |
| @@ -7523,8 +7422,6 @@ export async function saveSettings(loopCounter = 0) { | ||
| 7523 | 7422 | username: name1, |
| 7524 | 7423 | active_character: active_character, |
| 7525 | 7424 | active_group: active_group, |
| 7526 | - api_server: api_server, | |
| 7527 | - preset_settings: preset_settings, | |
| 7528 | 7425 | user_avatar: user_avatar, |
| 7529 | 7426 | amount_gen: amount_gen, |
| 7530 | 7427 | max_context: max_context, |
| @@ -8609,7 +8506,7 @@ export function setGenerationProgress(progress) { | ||
| 8609 | 8506 | } |
| 8610 | 8507 | |
| 8611 | 8508 | function isHordeGenerationNotAllowed() { |
| 8612 | 8509 | if (main_api == 'koboldhorde' && kai_settings.preset_settings == 'gui') { |
| 8613 | 8510 | toastr.error(t`GUI Settings preset is not supported for Horde. Please select another preset.`); |
| 8614 | 8511 | return true; |
| 8615 | 8512 | } |
| @@ -10893,27 +10790,6 @@ jQuery(async function () { | ||
| 10893 | 10790 | } |
| 10894 | 10791 | }); |
| 10895 | 10792 | |
| 10896 | - /////////////////////////////////////////////////////////////////////////////////// | |
| 10897 | - | |
| 10898 | - $('#api_button').on('click', function (e) { | |
| 10899 | - if ($('#api_url_text').val() != '') { | |
| 10900 | - let value = formatKoboldUrl(String($('#api_url_text').val()).trim()); | |
| 10901 | - | |
| 10902 | - if (!value) { | |
| 10903 | - toastr.error('Please enter a valid URL.'); | |
| 10904 | - return; | |
| 10905 | - } | |
| 10906 | - | |
| 10907 | - $('#api_url_text').val(value); | |
| 10908 | - api_server = value; | |
| 10909 | - startStatusLoading(); | |
| 10910 | - | |
| 10911 | - main_api = 'kobold'; | |
| 10912 | - saveSettingsDebounced(); | |
| 10913 | - getStatusKobold(); | |
| 10914 | - } | |
| 10915 | - }); | |
| 10916 | - | |
| 10917 | 10793 | $('#api_button_textgenerationwebui').on('click', async function (e) { |
| 10918 | 10794 | const keys = [ |
| 10919 | 10795 | { id: 'api_key_mancer', secret: SECRET_KEYS.MANCER }, |
| @@ -11184,31 +11060,6 @@ jQuery(async function () { | ||
| 11184 | 11060 | is_delete_mode = false; |
| 11185 | 11061 | }); |
| 11186 | 11062 | |
| 11187 | - $('#settings_preset').on('change', function () { | |
| 11188 | - if ($('#settings_preset').find(':selected').val() != 'gui') { | |
| 11189 | - preset_settings = $('#settings_preset').find(':selected').text(); | |
| 11190 | - const preset = koboldai_settings[koboldai_setting_names[preset_settings]]; | |
| 11191 | - loadKoboldSettings(preset); | |
| 11192 | - setGenerationParamsFromPreset(preset); | |
| 11193 | - $('#kobold_api-settings').find('input').prop('disabled', false); | |
| 11194 | - $('#kobold_api-settings').css('opacity', 1.0); | |
| 11195 | - $('#kobold_order') | |
| 11196 | - .css('opacity', 1) | |
| 11197 | - .sortable('enable'); | |
| 11198 | - } else { | |
| 11199 | - //$('.button').disableSelection(); | |
| 11200 | - preset_settings = 'gui'; | |
| 11201 | - | |
| 11202 | - $('#kobold_api-settings').find('input').prop('disabled', true); | |
| 11203 | - $('#kobold_api-settings').css('opacity', 0.5); | |
| 11204 | - | |
| 11205 | - $('#kobold_order') | |
| 11206 | - .css('opacity', 0.5) | |
| 11207 | - .sortable('disable'); | |
| 11208 | - } | |
| 11209 | - saveSettingsDebounced(); | |
| 11210 | - }); | |
| 11211 | - | |
| 11212 | 11063 | $('#settings_preset_novel').on('change', function () { |
| 11213 | 11064 | nai_settings.preset_settings_novel = $('#settings_preset_novel') |
| 11214 | 11065 | .find(':selected') |
| @@ -4,7 +4,6 @@ import { | ||
| 4 | 4 | characters, |
| 5 | 5 | online_status, |
| 6 | 6 | main_api, |
| 7 | - api_server, | |
| 8 | 7 | is_send_press, |
| 9 | 8 | max_context, |
| 10 | 9 | saveSettingsDebounced, |
| @@ -42,6 +41,7 @@ import { debounce_timeout } from './constants.js'; | ||
| 42 | 41 | import { Popup } from './popup.js'; |
| 43 | 42 | import { accountStorage } from './util/AccountStorage.js'; |
| 44 | 43 | import { getCurrentUserHandle } from './user.js'; |
| 44 | +import { kai_settings } from './kai-settings.js'; | |
| 45 | 45 | |
| 46 | 46 | var RPanelPin = document.getElementById('rm_button_panel_pin'); |
| 47 | 47 | var LPanelPin = document.getElementById('lm_button_panel_pin'); |
| @@ -371,7 +371,7 @@ function RA_autoconnect(PrevApi) { | ||
| 371 | 371 | if (online_status === 'no_connection' && power_user.auto_connect) { |
| 372 | 372 | switch (main_api) { |
| 373 | 373 | case 'kobold': |
| 374 | 374 | if (kai_settings.api_server && isValidUrl(kai_settings.api_server)) { |
| 375 | 375 | $('#api_button').trigger('click'); |
| 376 | 376 | } |
| 377 | 377 | break; |
| @@ -3,8 +3,16 @@ import { | ||
| 3 | 3 | saveSettingsDebounced, |
| 4 | 4 | getStoppingStrings, |
| 5 | 5 | substituteParams, |
| 6 | 6 | api_serversetOnlineStatus, |
| 7 | + resultCheckStatus, | |
| 8 | + main_api, | |
| 9 | + online_status, | |
| 10 | + abortStatusCheck, | |
| 11 | + startStatusLoading, | |
| 12 | + setGenerationParamsFromPreset, | |
| 7 | 13 | } from '../script.js'; |
| 14 | +import { t } from './i18n.js'; | |
| 15 | +import { autoSelectInstructPreset } from './instruct-mode.js'; | |
| 8 | 16 | |
| 9 | 17 | import { |
| 10 | 18 | power_user, |
| @@ -12,6 +20,9 @@ import { | ||
| 12 | 20 | import { getEventSourceStream } from './sse-stream.js'; |
| 13 | 21 | import { getSortableDelay } from './utils.js'; |
| 14 | 22 | |
| 23 | +export let koboldai_settings; | |
| 24 | +export let koboldai_setting_names; | |
| 25 | + | |
| 15 | 26 | export const kai_settings = { |
| 16 | 27 | temp: 1, |
| 17 | 28 | rep_pen: 1, |
| @@ -31,6 +42,8 @@ export const kai_settings = { | ||
| 31 | 42 | use_default_badwordsids: false, |
| 32 | 43 | grammar: '', |
| 33 | 44 | seed: -1, |
| 45 | + api_server: '', | |
| 46 | + preset_settings: 'gui', | |
| 34 | 47 | }; |
| 35 | 48 | |
| 36 | 49 | /** |
| @@ -72,7 +85,50 @@ export function formatKoboldUrl(value) { | ||
| 72 | 85 | return null; |
| 73 | 86 | } |
| 74 | 87 | |
| 75 | 88 | export function loadKoboldSettingsselectKoboldGuiPreset(preset) { |
| 89 | + $('#settings_preset option[value=gui]') | |
| 90 | + .attr('selected', 'true') | |
| 91 | + .trigger('change'); | |
| 92 | +} | |
| 93 | + | |
| 94 | +export function loadKoboldSettings(data, preset, settings) { | |
| 95 | + koboldai_setting_names = data.koboldai_setting_names; | |
| 96 | + koboldai_settings = data.koboldai_settings; | |
| 97 | + koboldai_settings.forEach(function (item, i, arr) { | |
| 98 | + koboldai_settings[i] = JSON.parse(item); | |
| 99 | + }); | |
| 100 | + | |
| 101 | + $('#settings_preset').empty(); | |
| 102 | + $('#settings_preset').append('<option value="gui">GUI KoboldAI Settings</option>'); | |
| 103 | + const names = {}; | |
| 104 | + koboldai_setting_names.forEach(function (item, i, arr) { | |
| 105 | + names[item] = i; | |
| 106 | + $('#settings_preset').append(`<option value=${i}>${item}</option>`); | |
| 107 | + }); | |
| 108 | + koboldai_setting_names = names; | |
| 109 | + | |
| 110 | + kai_settings.preset_settings = preset.preset_settings ?? settings.preset_settings; | |
| 111 | + kai_settings.api_server = preset.api_server ?? settings.api_server; | |
| 112 | + | |
| 113 | + if (kai_settings.preset_settings == 'gui') { | |
| 114 | + selectKoboldGuiPreset(); | |
| 115 | + } else { | |
| 116 | + if (typeof koboldai_setting_names[kai_settings.preset_settings] !== 'undefined') { | |
| 117 | + $(`#settings_preset option[value=${koboldai_setting_names[kai_settings.preset_settings]}]`) | |
| 118 | + .attr('selected', 'true'); | |
| 119 | + } else { | |
| 120 | + kai_settings.preset_settings = 'gui'; | |
| 121 | + selectKoboldGuiPreset(); | |
| 122 | + } | |
| 123 | + } | |
| 124 | + | |
| 125 | + loadKoboldSettingsFromPreset(preset); | |
| 126 | + | |
| 127 | + //Load the API server URL from settings | |
| 128 | + $('#api_url_text').val(kai_settings.api_server); | |
| 129 | +} | |
| 130 | + | |
| 131 | +function loadKoboldSettingsFromPreset(preset) { | |
| 76 | 132 | for (const name of Object.keys(kai_settings)) { |
| 77 | 133 | const value = preset[name] ?? defaultValues[name]; |
| 78 | 134 | const slider = sliders.find(x => x.name === name); |
| @@ -139,8 +195,7 @@ export function getKoboldGenerationData(finalPrompt, settings, maxLength, maxCon | ||
| 139 | 195 | use_default_badwordsids: (kai_flags.can_use_default_badwordsids || isHorde) ? kai_settings.use_default_badwordsids : undefined, |
| 140 | 196 | grammar: (kai_flags.can_use_grammar || isHorde) ? substituteParams(kai_settings.grammar) : undefined, |
| 141 | 197 | sampler_seed: kai_settings.seed >= 0 ? kai_settings.seed : undefined, |
| 142 | - | |
| 198 | + api_server: kai_settings.api_server, | |
| 143 | - api_server, | |
| 144 | 199 | }; |
| 145 | 200 | return generate_data; |
| 146 | 201 | } |
| @@ -350,7 +405,53 @@ function sortItemsByOrder(orderArray) { | ||
| 350 | 405 | } |
| 351 | 406 | } |
| 352 | 407 | |
| 353 | 408 | jQuery(export async function getStatusKobold() { |
| 409 | + let endpoint = kai_settings.api_server; | |
| 410 | + | |
| 411 | + if (!endpoint) { | |
| 412 | + console.warn('No endpoint for status check'); | |
| 413 | + setOnlineStatus('no_connection'); | |
| 414 | + return resultCheckStatus(); | |
| 415 | + } | |
| 416 | + | |
| 417 | + try { | |
| 418 | + const response = await fetch('/api/backends/kobold/status', { | |
| 419 | + method: 'POST', | |
| 420 | + headers: getRequestHeaders(), | |
| 421 | + body: JSON.stringify({ | |
| 422 | + main_api, | |
| 423 | + api_server: endpoint, | |
| 424 | + }), | |
| 425 | + signal: abortStatusCheck.signal, | |
| 426 | + }); | |
| 427 | + | |
| 428 | + const data = await response.json(); | |
| 429 | + | |
| 430 | + setOnlineStatus(data?.model ?? 'no_connection'); | |
| 431 | + | |
| 432 | + if (!data.koboldUnitedVersion) { | |
| 433 | + throw new Error(`Missing mandatory Kobold version in data: ${JSON.stringify(data)}`); | |
| 434 | + } | |
| 435 | + | |
| 436 | + // Determine instruct mode preset | |
| 437 | + autoSelectInstructPreset(online_status); | |
| 438 | + | |
| 439 | + // determine if we can use stop sequence and streaming | |
| 440 | + setKoboldFlags(data.koboldUnitedVersion, data.koboldCppVersion); | |
| 441 | + | |
| 442 | + // We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress. | |
| 443 | + if (online_status === 'no_connection' && data.response) { | |
| 444 | + toastr.error(data.response, t`API Error`, { timeOut: 5000, preventDuplicates: true }); | |
| 445 | + } | |
| 446 | + } catch (err) { | |
| 447 | + console.error('Error getting status', err); | |
| 448 | + setOnlineStatus('no_connection'); | |
| 449 | + } | |
| 450 | + | |
| 451 | + return resultCheckStatus(); | |
| 452 | +} | |
| 453 | + | |
| 454 | +export function initKoboldSettings() { | |
| 354 | 455 | sliders.forEach(slider => { |
| 355 | 456 | $(document).on('input', slider.sliderId, function () { |
| 356 | 457 | const value = $(this).val(); |
| @@ -361,6 +462,23 @@ jQuery(function () { | ||
| 361 | 462 | }); |
| 362 | 463 | }); |
| 363 | 464 | |
| 465 | + $('#api_button').on('click', function (e) { | |
| 466 | + if ($('#api_url_text').val() != '') { | |
| 467 | + const value = formatKoboldUrl(String($('#api_url_text').val()).trim()); | |
| 468 | + | |
| 469 | + if (!value) { | |
| 470 | + toastr.error('Please enter a valid URL.'); | |
| 471 | + return; | |
| 472 | + } | |
| 473 | + | |
| 474 | + $('#api_url_text').val(value); | |
| 475 | + kai_settings.api_server = value; | |
| 476 | + startStatusLoading(); | |
| 477 | + saveSettingsDebounced(); | |
| 478 | + getStatusKobold(); | |
| 479 | + } | |
| 480 | + }); | |
| 481 | + | |
| 364 | 482 | $('#streaming_kobold').on('input', function () { |
| 365 | 483 | const value = !!$(this).prop('checked'); |
| 366 | 484 | kai_settings.streaming_kobold = value; |
| @@ -391,4 +509,28 @@ jQuery(function () { | ||
| 391 | 509 | sortItemsByOrder(kai_settings.sampler_order); |
| 392 | 510 | saveSettingsDebounced(); |
| 393 | 511 | }); |
| 394 | -}); | |
| 512 | + | |
| 513 | + $('#settings_preset').on('change', function () { | |
| 514 | + if ($('#settings_preset').find(':selected').val() != 'gui') { | |
| 515 | + kai_settings.preset_settings = $('#settings_preset').find(':selected').text(); | |
| 516 | + const preset = koboldai_settings[koboldai_setting_names[kai_settings.preset_settings]]; | |
| 517 | + loadKoboldSettingsFromPreset(preset); | |
| 518 | + setGenerationParamsFromPreset(preset); | |
| 519 | + $('#kobold_api-settings').find('input').prop('disabled', false); | |
| 520 | + $('#kobold_api-settings').css('opacity', 1.0); | |
| 521 | + $('#kobold_order') | |
| 522 | + .css('opacity', 1) | |
| 523 | + .sortable('enable'); | |
| 524 | + } else { | |
| 525 | + kai_settings.preset_settings = 'gui'; | |
| 526 | + | |
| 527 | + $('#kobold_api-settings').find('input').prop('disabled', true); | |
| 528 | + $('#kobold_api-settings').css('opacity', 0.5); | |
| 529 | + | |
| 530 | + $('#kobold_order') | |
| 531 | + .css('opacity', 0.5) | |
| 532 | + .sortable('disable'); | |
| 533 | + } | |
| 534 | + saveSettingsDebounced(); | |
| 535 | + }); | |
| 536 | +} | |
| @@ -598,6 +598,7 @@ class PresetManager { | ||
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | const filteredKeys = [ |
| 601 | + 'api_server', | |
| 601 | 602 | 'preset', |
| 602 | 603 | 'streaming', |
| 603 | 604 | 'truncation_length', |
| @@ -607,6 +608,7 @@ class PresetManager { | ||
| 607 | 608 | 'can_use_tokenization', |
| 608 | 609 | 'can_use_streaming', |
| 609 | 610 | 'preset_settings_novel', |
| 611 | + 'preset_settings', | |
| 610 | 612 | 'streaming_novel', |
| 611 | 613 | 'nai_preamble', |
| 612 | 614 | 'model_novel', |
| @@ -6,7 +6,6 @@ import { | ||
| 6 | 6 | UNIQUE_APIS, |
| 7 | 7 | activateSendButtons, |
| 8 | 8 | addOneMessage, |
| 9 | - api_server, | |
| 10 | 9 | characters, |
| 11 | 10 | chat, |
| 12 | 11 | chat_metadata, |
| @@ -80,6 +79,7 @@ import { accountStorage } from './util/AccountStorage.js'; | ||
| 80 | 79 | import { SlashCommandDebugController } from './slash-commands/SlashCommandDebugController.js'; |
| 81 | 80 | import { SlashCommandScope } from './slash-commands/SlashCommandScope.js'; |
| 82 | 81 | import { t } from './i18n.js'; |
| 82 | +import { kai_settings } from './kai-settings.js'; | |
| 83 | 83 | export { |
| 84 | 84 | executeSlashCommands, executeSlashCommandsWithOptions, getSlashCommandsHelp, registerSlashCommand, |
| 85 | 85 | }; |
| @@ -4555,7 +4555,7 @@ async function setApiUrlCallback({ api = null, connect = 'true', quiet = 'false' | ||
| 4555 | 4555 | const isCurrentlyKoboldClassic = main_api === 'kobold'; |
| 4556 | 4556 | if (api === 'kobold' || (!api && isCurrentlyKoboldClassic)) { |
| 4557 | 4557 | if (!url) { |
| 4558 | 4558 | return kai_settings.api_server ?? ''; |
| 4559 | 4559 | } |
| 4560 | 4560 | |
| 4561 | 4561 | if (!isCurrentlyKoboldClassic && autoConnect) { |
| @@ -4571,7 +4571,7 @@ async function setApiUrlCallback({ api = null, connect = 'true', quiet = 'false' | ||
| 4571 | 4571 | $('#api_button').trigger('click'); |
| 4572 | 4572 | } |
| 4573 | 4573 | |
| 4574 | 4574 | return kai_settings.api_server ?? ''; |
| 4575 | 4575 | } |
| 4576 | 4576 | |
| 4577 | 4577 | // Do some checks and get the api type we are targeting with this command |
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | import { localforage } from '../lib.js'; |
| 2 | 2 | import { characters, main_api, api_server, nai_settings, online_status, this_chid } from '../script.js'; |
| 3 | 3 | import { power_user, registerDebugFunction } from './power-user.js'; |
| 4 | 4 | import { chat_completion_sources, model_list, oai_settings } from './openai.js'; |
| 5 | 5 | import { groups, selected_group } from './group-chats.js'; |
| 6 | 6 | import { getStringHash } from './utils.js'; |
| 7 | 7 | import { kai_flags, kai_settings } from './kai-settings.js'; |
| 8 | 8 | import { textgen_types, textgenerationwebui_settings as textgen_settings, getTextGenServer, getTextGenModel } from './textgen-settings.js'; |
| 9 | 9 | import { getCurrentDreamGenModelTokenizer, getCurrentOpenRouterModelTokenizer, openRouterModels } from './textgen-models.js'; |
| 10 | 10 | |
| @@ -911,7 +911,7 @@ function countTokensFromKoboldAPI(str, resolve) { | ||
| 911 | 911 | url: TOKENIZER_URLS[tokenizers.API_KOBOLD].count, |
| 912 | 912 | data: JSON.stringify({ |
| 913 | 913 | text: str, |
| 914 | 914 | url: kai_settings.api_server, |
| 915 | 915 | }), |
| 916 | 916 | dataType: 'json', |
| 917 | 917 | contentType: 'application/json', |
| @@ -1062,7 +1062,7 @@ function getTextTokensFromKoboldAPI(str, resolve) { | ||
| 1062 | 1062 | url: TOKENIZER_URLS[tokenizers.API_KOBOLD].encode, |
| 1063 | 1063 | data: JSON.stringify({ |
| 1064 | 1064 | text: str, |
| 1065 | 1065 | url: kai_settings.api_server, |
| 1066 | 1066 | }), |
| 1067 | 1067 | dataType: 'json', |
| 1068 | 1068 | contentType: 'application/json', |