From ba54e3dea020c9c3e2ff8742bd7cc451c2565e19 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sun, 3 Dec 2023 02:45:53 -0500 Subject: [PATCH 1/6] Replaces is_[api] params with api_type param These were 5 mutually-exclusive booleans, which can be replaced with one param that takes on 5 values, one for each API type. --- public/script.js | 8 +-- public/scripts/textgen-settings.js | 6 +- public/scripts/tokenizers.js | 5 +- server.js | 107 ++++++++++++++++------------- 4 files changed, 64 insertions(+), 62 deletions(-) diff --git a/public/script.js b/public/script.js index c4aff5a9a..9be6275a6 100644 --- a/public/script.js +++ b/public/script.js @@ -885,13 +885,9 @@ async function getStatus() { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ - main_api: main_api, + main_api, api_server: endpoint, - use_mancer: main_api == 'textgenerationwebui' ? isMancer() : false, - use_aphrodite: main_api == 'textgenerationwebui' ? isAphrodite() : false, - use_ooba: main_api == 'textgenerationwebui' ? isOoba() : false, - use_tabby: main_api == 'textgenerationwebui' ? isTabby() : false, - use_koboldcpp: main_api == 'textgenerationwebui' ? isKoboldCpp() : false, + api_type: textgenerationwebui_settings.type, legacy_api: main_api == 'textgenerationwebui' ? textgenerationwebui_settings.legacy_api && !isMancer() : false, }), signal: abortStatusCheck.signal, diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 96217e0db..42a339c33 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -620,11 +620,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, 'mirostat_tau': textgenerationwebui_settings.mirostat_tau, 'mirostat_eta': textgenerationwebui_settings.mirostat_eta, 'custom_token_bans': isAphrodite() ? toIntArray(getCustomTokenBans()) : getCustomTokenBans(), - 'use_mancer': isMancer(), - 'use_aphrodite': isAphrodite(), - 'use_tabby': isTabby(), - 'use_koboldcpp': isKoboldCpp(), - 'use_ooba': isOoba(), + 'api_type': textgenerationwebui_settings.type, 'api_server': isMancer() ? MANCER_SERVER : api_server_textgenerationwebui, 'legacy_api': textgenerationwebui_settings.legacy_api && !isMancer(), 'sampler_order': isKoboldCpp() ? textgenerationwebui_settings.sampler_order : undefined, diff --git a/public/scripts/tokenizers.js b/public/scripts/tokenizers.js index 86fc262fb..9b106e23f 100644 --- a/public/scripts/tokenizers.js +++ b/public/scripts/tokenizers.js @@ -392,11 +392,10 @@ function getTokenCacheObject() { function getRemoteTokenizationParams(str) { return { text: str, - api: main_api, + main_api, + api_type: textgenerationwebui_settings.type, url: getAPIServerUrl(), legacy_api: main_api === 'textgenerationwebui' && textgenerationwebui_settings.legacy_api && !isMancer(), - use_tabby: main_api === 'textgenerationwebui' && isTabby(), - use_koboldcpp: main_api === 'textgenerationwebui' && isKoboldCpp(), }; } diff --git a/server.js b/server.js index fdd06876f..ad8c75a44 100644 --- a/server.js +++ b/server.js @@ -177,19 +177,24 @@ function getOverrideHeaders(urlHost) { * @param {string|null} server API server for new request */ function setAdditionalHeaders(request, args, server) { - let headers = {}; + let headers; - if (request.body.use_mancer) { - headers = getMancerHeaders(); - } else if (request.body.use_aphrodite) { - headers = getAphroditeHeaders(); - } else if (request.body.use_tabby) { - headers = getTabbyHeaders(); - } else { - headers = server ? getOverrideHeaders((new URL(server))?.host) : {}; + switch (request.body.api_type) { + case 'mancer': + headers = getMancerHeaders(); + break; + case 'aphrodite': + headers = getAphroditeHeaders(); + break; + case 'tabby': + headers = getTabbyHeaders(); + break; + default: + headers = server ? getOverrideHeaders((new URL(server))?.host) : {}; + break; } - args.headers = Object.assign(args.headers, headers); + Object.assign(args.headers, headers); } function humanizedISO8601DateTime(date) { @@ -562,21 +567,20 @@ app.post('/api/textgenerationwebui/status', jsonParser, async function (request, if (request.body.legacy_api) { url += '/v1/model'; - } - else if (request.body.use_ooba) { - url += '/v1/models'; - } - else if (request.body.use_aphrodite) { - url += '/v1/models'; - } - else if (request.body.use_mancer) { - url += '/oai/v1/models'; - } - else if (request.body.use_tabby) { - url += '/v1/model/list'; - } - else if (request.body.use_koboldcpp) { - url += '/v1/models'; + } else { + switch (request.body.api_type) { + case 'ooba': + case 'aphrodite': + case 'koboldcpp': + url += '/v1/models'; + break; + case 'mancer': + url += '/oai/v1/models'; + break; + case 'tabby': + url += '/v1/model/list'; + break; + } } const modelsReply = await fetch(url, args); @@ -604,7 +608,7 @@ app.post('/api/textgenerationwebui/status', jsonParser, async function (request, // Set result to the first model ID result = modelIds[0] || 'Valid'; - if (request.body.use_ooba) { + if (request.body.api_type === 'ooba') { try { const modelInfoUrl = baseUrl + '/v1/internal/model/info'; const modelInfoReply = await fetch(modelInfoUrl, args); @@ -619,9 +623,7 @@ app.post('/api/textgenerationwebui/status', jsonParser, async function (request, } catch (error) { console.error(`Failed to get Ooba model info: ${error}`); } - } - - if (request.body.use_tabby) { + } else if (request.body.api_type === 'tabby') { try { const modelInfoUrl = baseUrl + '/v1/model'; const modelInfoReply = await fetch(modelInfoUrl, args); @@ -671,12 +673,18 @@ app.post('/api/textgenerationwebui/generate', jsonParser, async function (reques if (request.body.legacy_api) { url += '/v1/generate'; - } - else if (request.body.use_aphrodite || request.body.use_ooba || request.body.use_tabby || request.body.use_koboldcpp) { - url += '/v1/completions'; - } - else if (request.body.use_mancer) { - url += '/oai/v1/completions'; + } else { + switch (request.body.api_type) { + case 'aphrodite': + case 'ooba': + case 'tabby': + case 'koboldcpp': + url += '/v1/completions'; + break; + case 'mancer': + url += '/oai/v1/completions'; + break; + } } const args = { @@ -3471,7 +3479,7 @@ app.post('/tokenize_via_api', jsonParser, async function (request, response) { return response.sendStatus(400); } const text = String(request.body.text) || ''; - const api = String(request.body.api); + const api = String(request.body.main_api); const baseUrl = String(request.body.url); const legacyApi = Boolean(request.body.legacy_api); @@ -3490,18 +3498,21 @@ app.post('/tokenize_via_api', jsonParser, async function (request, response) { if (legacyApi) { url += '/v1/token-count'; args.body = JSON.stringify({ 'prompt': text }); - } - else if (request.body.use_tabby) { - url += '/v1/token/encode'; - args.body = JSON.stringify({ 'text': text }); - } - else if (request.body.use_koboldcpp) { - url += '/api/extra/tokencount'; - args.body = JSON.stringify({ 'prompt': text }); - } - else { - url += '/v1/internal/encode'; - args.body = JSON.stringify({ 'text': text }); + } else { + switch (request.body.api_type) { + case 'tabby': + url += '/v1/token/encode'; + args.body = JSON.stringify({ 'text': text }); + break; + case 'koboldcpp': + url += '/api/extra/tokencount'; + args.body = JSON.stringify({ 'prompt': text }); + break; + default: + url += '/v1/internal/encode'; + args.body = JSON.stringify({ 'text': text }); + break; + } } const result = await fetch(url, args); From 047c897ead7c9c04fe473844cd71f16707c3a705 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sun, 3 Dec 2023 02:55:38 -0500 Subject: [PATCH 2/6] Remove is[API] functions Just use an equality comparison. It's a bit longer, but only because "textgenerationwebui_settings" is a long identifier. --- public/script.js | 19 ++++++------ public/scripts/RossAscends-mods.js | 4 +-- public/scripts/textgen-settings.js | 50 ++++++++++++------------------ public/scripts/tokenizers.js | 11 +++++-- 4 files changed, 39 insertions(+), 45 deletions(-) diff --git a/public/script.js b/public/script.js index 9be6275a6..ef2bc002a 100644 --- a/public/script.js +++ b/public/script.js @@ -17,14 +17,9 @@ import { getTextGenGenerationData, formatTextGenURL, getTextGenUrlSourceId, - isMancer, - isAphrodite, - isTabby, textgen_types, textgenerationwebui_banned_in_macros, - isOoba, MANCER_SERVER, - isKoboldCpp, } from './scripts/textgen-settings.js'; import { @@ -888,14 +883,17 @@ async function getStatus() { main_api, api_server: endpoint, api_type: textgenerationwebui_settings.type, - legacy_api: main_api == 'textgenerationwebui' ? textgenerationwebui_settings.legacy_api && !isMancer() : false, + legacy_api: main_api == 'textgenerationwebui' ? + textgenerationwebui_settings.legacy_api && + textgenerationwebui_settings.type !== textgen_types.MANCER : + false, }), signal: abortStatusCheck.signal, }); const data = await response.json(); - if (main_api == 'textgenerationwebui' && isMancer()) { + if (main_api == 'textgenerationwebui' && textgenerationwebui_settings.type === textgen_types.MANCER) { online_status = textgenerationwebui_settings.mancer_model; loadMancerModels(data?.data); } else { @@ -943,7 +941,7 @@ export function resultCheckStatus() { export function getAPIServerUrl() { if (main_api == 'textgenerationwebui') { - if (isMancer()) { + if (textgenerationwebui_settings.type === textgen_types.MANCER) { return MANCER_SERVER; } @@ -2847,7 +2845,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, return; } - if (main_api === 'textgenerationwebui' && textgenerationwebui_settings.streaming && textgenerationwebui_settings.legacy_api && !isMancer()) { + if (main_api === 'textgenerationwebui' && + textgenerationwebui_settings.streaming && + textgenerationwebui_settings.legacy_api && + textgenerationwebui_settings.type !== textgen_types.MANCER) { toastr.error('Streaming is not supported for the Legacy API. Update Ooba and use --extensions openai to enable streaming.', undefined, { timeOut: 10000, preventDuplicates: true }); unblockGeneration(); return; diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index ae2fc297f..e53cb0a19 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -34,7 +34,7 @@ import { import { debounce, delay, getStringHash, isValidUrl } from './utils.js'; import { chat_completion_sources, oai_settings } from './openai.js'; import { getTokenCount } from './tokenizers.js'; -import { isMancer } from './textgen-settings.js'; +import { textgen_types, textgenerationwebui_settings } from './textgen-settings.js'; var RPanelPin = document.getElementById('rm_button_panel_pin'); @@ -401,7 +401,7 @@ function RA_autoconnect(PrevApi) { } break; case 'textgenerationwebui': - if (isMancer() && secret_state[SECRET_KEYS.MANCER]) { + if (textgenerationwebui_settings.type === textgen_types.MANCER && secret_state[SECRET_KEYS.MANCER]) { $('#api_button_textgenerationwebui').trigger('click'); } else if (api_server_textgenerationwebui && isValidUrl(api_server_textgenerationwebui)) { diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 42a339c33..9bcd09de5 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -162,7 +162,7 @@ async function selectPreset(name) { function formatTextGenURL(value) { try { // Mancer doesn't need any formatting (it's hardcoded) - if (isMancer()) { + if (textgenerationwebui_settings.type === textgen_types.MANCER) { return value; } @@ -265,7 +265,7 @@ function loadTextGenSettings(data, settings) { $('#textgen_type').val(textgenerationwebui_settings.type); showTypeSpecificControls(textgenerationwebui_settings.type); //this is needed because showTypeSpecificControls() does not handle NOT declarations - if (isAphrodite()) { + if (textgenerationwebui_settings.type === textgen_types.APHRODITE) { $('[data-forAphro=False]').each(function () { $(this).hide(); }); @@ -285,26 +285,6 @@ function loadTextGenSettings(data, settings) { }); } -export function isMancer() { - return textgenerationwebui_settings.type === textgen_types.MANCER; -} - -export function isAphrodite() { - return textgenerationwebui_settings.type === textgen_types.APHRODITE; -} - -export function isTabby() { - return textgenerationwebui_settings.type === textgen_types.TABBY; -} - -export function isOoba() { - return textgenerationwebui_settings.type === textgen_types.OOBA; -} - -export function isKoboldCpp() { - return textgenerationwebui_settings.type === textgen_types.KOBOLDCPP; -} - export function getTextGenUrlSourceId() { switch (textgenerationwebui_settings.type) { case textgen_types.OOBA: @@ -357,7 +337,7 @@ jQuery(function () { const type = String($(this).val()); textgenerationwebui_settings.type = type; - if (isAphrodite()) { + if (textgenerationwebui_settings.type === textgen_types.APHRODITE) { //this is needed because showTypeSpecificControls() does not handle NOT declarations $('[data-forAphro=False]').each(function () { $(this).hide(); @@ -419,7 +399,9 @@ jQuery(function () { $(`#${id}_counter_textgenerationwebui`).val(value); textgenerationwebui_settings[id] = value; //special handling for aphrodite using -1 as disabled instead of 0 - if ($(this).attr('id') === 'top_k_textgenerationwebui' && isAphrodite() && value === 0) { + if ($(this).attr('id') === 'top_k_textgenerationwebui' && + textgenerationwebui_settings.type === textgen_types.APHRODITE && + value === 0) { textgenerationwebui_settings[id] = -1; $(this).val(-1); } @@ -575,11 +557,11 @@ function toIntArray(string) { } function getModel() { - if (isMancer()) { + if (textgenerationwebui_settings.type === textgen_types.MANCER) { return textgenerationwebui_settings.mancer_model; } - if (isAphrodite()) { + if (textgenerationwebui_settings.type === textgen_types.APHRODITE) { return online_status; } @@ -619,11 +601,17 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, 'mirostat_mode': textgenerationwebui_settings.mirostat_mode, 'mirostat_tau': textgenerationwebui_settings.mirostat_tau, 'mirostat_eta': textgenerationwebui_settings.mirostat_eta, - 'custom_token_bans': isAphrodite() ? toIntArray(getCustomTokenBans()) : getCustomTokenBans(), + 'custom_token_bans': textgenerationwebui_settings.type === textgen_types.APHRODITE ? + toIntArray(getCustomTokenBans()) : + getCustomTokenBans(), 'api_type': textgenerationwebui_settings.type, - 'api_server': isMancer() ? MANCER_SERVER : api_server_textgenerationwebui, - 'legacy_api': textgenerationwebui_settings.legacy_api && !isMancer(), - 'sampler_order': isKoboldCpp() ? textgenerationwebui_settings.sampler_order : undefined, + 'api_server': textgenerationwebui_settings.type === textgen_types.MANCER ? + MANCER_SERVER : + api_server_textgenerationwebui, + 'legacy_api': textgenerationwebui_settings.legacy_api && textgenerationwebui_settings.type !== textgen_types.MANCER, + 'sampler_order': textgenerationwebui_settings.type === textgen_types.KOBOLDCPP ? + textgenerationwebui_settings.sampler_order : + undefined, }; let aphroditeExclusionFlags = { 'repetition_penalty_range': textgenerationwebui_settings.rep_pen_range, @@ -646,7 +634,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, //'logprobs': textgenerationwebui_settings.log_probs_aphrodite, //'prompt_logprobs': textgenerationwebui_settings.prompt_log_probs_aphrodite, }; - if (isAphrodite()) { + if (textgenerationwebui_settings.type === textgen_types.APHRODITE) { APIflags = Object.assign(APIflags, aphroditeFlags); } else { APIflags = Object.assign(APIflags, aphroditeExclusionFlags); diff --git a/public/scripts/tokenizers.js b/public/scripts/tokenizers.js index 9b106e23f..2008bea1f 100644 --- a/public/scripts/tokenizers.js +++ b/public/scripts/tokenizers.js @@ -4,7 +4,7 @@ import { chat_completion_sources, model_list, oai_settings } from './openai.js'; import { groups, selected_group } from './group-chats.js'; import { getStringHash } from './utils.js'; import { kai_flags } from './kai-settings.js'; -import { isKoboldCpp, isMancer, isOoba, isTabby, textgenerationwebui_settings } from './textgen-settings.js'; +import { textgen_types, textgenerationwebui_settings } from './textgen-settings.js'; export const CHARACTERS_PER_TOKEN_RATIO = 3.35; const TOKENIZER_WARNING_KEY = 'tokenizationWarningShown'; @@ -129,7 +129,10 @@ export function getTokenizerBestMatch(forApi) { // - Tokenizer haven't reported an error previously const hasTokenizerError = sessionStorage.getItem(TOKENIZER_WARNING_KEY); const isConnected = online_status !== 'no_connection'; - const isTokenizerSupported = isOoba() || isTabby() || isKoboldCpp(); + const isTokenizerSupported = + textgenerationwebui_settings.type === textgen_types.OOBA || + textgenerationwebui_settings.type === textgen_types.TABBY || + textgenerationwebui_settings.type === textgen_types.KOBOLDCPP; if (!hasTokenizerError && isConnected) { if (forApi === 'kobold' && kai_flags.can_use_tokenization) { @@ -395,7 +398,9 @@ function getRemoteTokenizationParams(str) { main_api, api_type: textgenerationwebui_settings.type, url: getAPIServerUrl(), - legacy_api: main_api === 'textgenerationwebui' && textgenerationwebui_settings.legacy_api && !isMancer(), + legacy_api: main_api === 'textgenerationwebui' && + textgenerationwebui_settings.legacy_api && + textgenerationwebui_settings.type !== textgen_types.MANCER, }; } From 9c33ddbafcf76fdddfd9304a857f23c24151a851 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sun, 3 Dec 2023 10:03:19 -0500 Subject: [PATCH 3/6] Make textgen settings type checks more concise --- public/script.js | 28 ++--- public/scripts/RossAscends-mods.js | 4 +- public/scripts/mancer-settings.js | 6 +- public/scripts/preset-manager.js | 4 +- public/scripts/textgen-settings.js | 158 +++++++++++++++-------------- public/scripts/tokenizers.js | 15 ++- 6 files changed, 109 insertions(+), 106 deletions(-) diff --git a/public/script.js b/public/script.js index ef2bc002a..78b718775 100644 --- a/public/script.js +++ b/public/script.js @@ -11,7 +11,7 @@ import { } from './scripts/kai-settings.js'; import { - textgenerationwebui_settings, + textgenerationwebui_settings as textgen_settings, loadTextGenSettings, generateTextGenWithStreaming, getTextGenGenerationData, @@ -22,6 +22,8 @@ import { MANCER_SERVER, } from './scripts/textgen-settings.js'; +const { MANCER } = textgen_types; + import { world_info, getWorldInfoPrompt, @@ -882,10 +884,10 @@ async function getStatus() { body: JSON.stringify({ main_api, api_server: endpoint, - api_type: textgenerationwebui_settings.type, + api_type: textgen_settings.type, legacy_api: main_api == 'textgenerationwebui' ? - textgenerationwebui_settings.legacy_api && - textgenerationwebui_settings.type !== textgen_types.MANCER : + textgen_settings.legacy_api && + textgen_settings.type !== MANCER : false, }), signal: abortStatusCheck.signal, @@ -893,8 +895,8 @@ async function getStatus() { const data = await response.json(); - if (main_api == 'textgenerationwebui' && textgenerationwebui_settings.type === textgen_types.MANCER) { - online_status = textgenerationwebui_settings.mancer_model; + if (main_api == 'textgenerationwebui' && textgen_settings.type === MANCER) { + online_status = textgen_settings.mancer_model; loadMancerModels(data?.data); } else { online_status = data?.result; @@ -941,7 +943,7 @@ export function resultCheckStatus() { export function getAPIServerUrl() { if (main_api == 'textgenerationwebui') { - if (textgenerationwebui_settings.type === textgen_types.MANCER) { + if (textgen_settings.type === MANCER) { return MANCER_SERVER; } @@ -2465,7 +2467,7 @@ function isStreamingEnabled() { return ((main_api == 'openai' && oai_settings.stream_openai && !noStreamSources.includes(oai_settings.chat_completion_source)) || (main_api == 'kobold' && kai_settings.streaming_kobold && kai_flags.can_use_streaming) || (main_api == 'novel' && nai_settings.streaming_novel) - || (main_api == 'textgenerationwebui' && textgenerationwebui_settings.streaming)); + || (main_api == 'textgenerationwebui' && textgen_settings.streaming)); } function showStopButton() { @@ -2846,9 +2848,9 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, } if (main_api === 'textgenerationwebui' && - textgenerationwebui_settings.streaming && - textgenerationwebui_settings.legacy_api && - textgenerationwebui_settings.type !== textgen_types.MANCER) { + textgen_settings.streaming && + textgen_settings.legacy_api && + textgen_settings.type !== MANCER) { toastr.error('Streaming is not supported for the Legacy API. Update Ooba and use --extensions openai to enable streaming.', undefined, { timeOut: 10000, preventDuplicates: true }); unblockGeneration(); return; @@ -4691,7 +4693,7 @@ function getGeneratingApi() { case 'openai': return oai_settings.chat_completion_source || 'openai'; case 'textgenerationwebui': - return textgenerationwebui_settings.type === textgen_types.OOBA ? 'textgenerationwebui' : textgenerationwebui_settings.type; + return textgen_settings.type === textgen_types.OOBA ? 'textgenerationwebui' : textgen_settings.type; default: return main_api; } @@ -5658,7 +5660,7 @@ async function saveSettings(type) { max_context: max_context, main_api: main_api, world_info_settings: getWorldInfoSettings(), - textgenerationwebui_settings: textgenerationwebui_settings, + textgenerationwebui_settings: textgen_settings, swipes: swipes, horde_settings: horde_settings, power_user: power_user, diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index e53cb0a19..4b013758c 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -34,7 +34,7 @@ import { import { debounce, delay, getStringHash, isValidUrl } from './utils.js'; import { chat_completion_sources, oai_settings } from './openai.js'; import { getTokenCount } from './tokenizers.js'; -import { textgen_types, textgenerationwebui_settings } from './textgen-settings.js'; +import { textgen_types, textgenerationwebui_settings as textgen_settings } from './textgen-settings.js'; var RPanelPin = document.getElementById('rm_button_panel_pin'); @@ -401,7 +401,7 @@ function RA_autoconnect(PrevApi) { } break; case 'textgenerationwebui': - if (textgenerationwebui_settings.type === textgen_types.MANCER && secret_state[SECRET_KEYS.MANCER]) { + if (textgen_settings.type === textgen_types.MANCER && secret_state[SECRET_KEYS.MANCER]) { $('#api_button_textgenerationwebui').trigger('click'); } else if (api_server_textgenerationwebui && isValidUrl(api_server_textgenerationwebui)) { diff --git a/public/scripts/mancer-settings.js b/public/scripts/mancer-settings.js index c93c048c9..422a51ab4 100644 --- a/public/scripts/mancer-settings.js +++ b/public/scripts/mancer-settings.js @@ -1,6 +1,6 @@ import { setGenerationParamsFromPreset } from '../script.js'; import { getDeviceInfo } from './RossAscends-mods.js'; -import { textgenerationwebui_settings } from './textgen-settings.js'; +import { textgenerationwebui_settings as textgen_settings } from './textgen-settings.js'; let models = []; @@ -17,14 +17,14 @@ export async function loadMancerModels(data) { const option = document.createElement('option'); option.value = model.id; option.text = model.name; - option.selected = model.id === textgenerationwebui_settings.mancer_model; + option.selected = model.id === textgen_settings.mancer_model; $('#mancer_model').append(option); } } function onMancerModelSelect() { const modelId = String($('#mancer_model').val()); - textgenerationwebui_settings.mancer_model = modelId; + textgen_settings.mancer_model = modelId; $('#api_button_textgenerationwebui').trigger('click'); const limits = models.find(x => x.id === modelId)?.limits; diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index 760a364b6..f48ab287b 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -22,7 +22,7 @@ import { context_presets, getContextSettings, power_user } from './power-user.js import { textgenerationwebui_preset_names, textgenerationwebui_presets, - textgenerationwebui_settings, + textgenerationwebui_settings as textgen_settings, } from './textgen-settings.js'; import { download, parseJsonFile, waitUntilCondition } from './utils.js'; @@ -236,7 +236,7 @@ class PresetManager { case 'novel': return nai_settings; case 'textgenerationwebui': - return textgenerationwebui_settings; + return textgen_settings; case 'context': { const context_preset = getContextSettings(); context_preset['name'] = name || power_user.context.preset; diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 9bcd09de5..c577c7e09 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -18,7 +18,7 @@ import { SENTENCEPIECE_TOKENIZERS, getTextTokens, tokenizers } from './tokenizer import { getSortableDelay, onlyUnique } from './utils.js'; export { - textgenerationwebui_settings, + settings as textgenerationwebui_settings, loadTextGenSettings, generateTextGenWithStreaming, formatTextGenURL, @@ -32,6 +32,8 @@ export const textgen_types = { KOBOLDCPP: 'koboldcpp', }; +const { MANCER, APHRODITE } = textgen_types; + // Maybe let it be configurable in the future? // (7 days later) The future has come. const MANCER_SERVER_KEY = 'mancer_server'; @@ -39,7 +41,7 @@ const MANCER_SERVER_DEFAULT = 'https://neuro.mancer.tech'; export let MANCER_SERVER = localStorage.getItem(MANCER_SERVER_KEY) ?? MANCER_SERVER_DEFAULT; const KOBOLDCPP_ORDER = [6, 0, 1, 3, 4, 2, 5]; -const textgenerationwebui_settings = { +const settings = { temp: 0.7, temperature_last: true, top_p: 0.5, @@ -150,7 +152,7 @@ async function selectPreset(name) { return; } - textgenerationwebui_settings.preset = name; + settings.preset = name; for (const name of setting_names) { const value = preset[name]; setSettingByName(name, value, true); @@ -162,17 +164,17 @@ async function selectPreset(name) { function formatTextGenURL(value) { try { // Mancer doesn't need any formatting (it's hardcoded) - if (textgenerationwebui_settings.type === textgen_types.MANCER) { + if (settings.type === MANCER) { return value; } const url = new URL(value); - if (url.pathname === '/api' && !textgenerationwebui_settings.legacy_api) { + if (url.pathname === '/api' && !settings.legacy_api) { toastr.info('Enable Legacy API or start Ooba with the OpenAI extension enabled.', 'Legacy API URL detected. Generation may fail.', { preventDuplicates: true, timeOut: 10000, extendedTimeOut: 20000 }); url.pathname = ''; } - if (!power_user.relaxed_api_urls && textgenerationwebui_settings.legacy_api) { + if (!power_user.relaxed_api_urls && settings.legacy_api) { url.pathname = '/api'; } return url.toString(); @@ -190,13 +192,13 @@ function convertPresets(presets) { * @returns {string} String with comma-separated banned token IDs */ function getCustomTokenBans() { - if (!textgenerationwebui_settings.banned_tokens && !textgenerationwebui_banned_in_macros.length) { + if (!settings.banned_tokens && !textgenerationwebui_banned_in_macros.length) { return ''; } const tokenizer = SENTENCEPIECE_TOKENIZERS.includes(power_user.tokenizer) ? power_user.tokenizer : tokenizers.LLAMA; const result = []; - const sequences = textgenerationwebui_settings.banned_tokens + const sequences = settings.banned_tokens .split('\n') .concat(textgenerationwebui_banned_in_macros) .filter(x => x.length > 0) @@ -240,10 +242,10 @@ function getCustomTokenBans() { function loadTextGenSettings(data, settings) { textgenerationwebui_presets = convertPresets(data.textgenerationwebui_presets); textgenerationwebui_preset_names = data.textgenerationwebui_preset_names ?? []; - Object.assign(textgenerationwebui_settings, settings.textgenerationwebui_settings ?? {}); + Object.assign(settings, settings.textgenerationwebui_settings ?? {}); if (settings.api_use_mancer_webui) { - textgenerationwebui_settings.type = textgen_types.MANCER; + settings.type = MANCER; } for (const name of textgenerationwebui_preset_names) { @@ -253,19 +255,19 @@ function loadTextGenSettings(data, settings) { $('#settings_preset_textgenerationwebui').append(option); } - if (textgenerationwebui_settings.preset) { - $('#settings_preset_textgenerationwebui').val(textgenerationwebui_settings.preset); + if (settings.preset) { + $('#settings_preset_textgenerationwebui').val(settings.preset); } for (const i of setting_names) { - const value = textgenerationwebui_settings[i]; + const value = settings[i]; setSettingByName(i, value); } - $('#textgen_type').val(textgenerationwebui_settings.type); - showTypeSpecificControls(textgenerationwebui_settings.type); + $('#textgen_type').val(settings.type); + showTypeSpecificControls(settings.type); //this is needed because showTypeSpecificControls() does not handle NOT declarations - if (textgenerationwebui_settings.type === textgen_types.APHRODITE) { + if (settings.type === textgen_types.APHRODITE) { $('[data-forAphro=False]').each(function () { $(this).hide(); }); @@ -286,7 +288,7 @@ function loadTextGenSettings(data, settings) { } export function getTextGenUrlSourceId() { - switch (textgenerationwebui_settings.type) { + switch (settings.type) { case textgen_types.OOBA: return '#textgenerationwebui_api_url_text'; case textgen_types.APHRODITE: @@ -321,23 +323,23 @@ jQuery(function () { $('#koboldcpp_order').children().each(function () { order.push($(this).data('id')); }); - textgenerationwebui_settings.sampler_order = order; - console.log('Samplers reordered:', textgenerationwebui_settings.sampler_order); + settings.sampler_order = order; + console.log('Samplers reordered:', settings.sampler_order); saveSettingsDebounced(); }, }); $('#koboldcpp_default_order').on('click', function () { - textgenerationwebui_settings.sampler_order = KOBOLDCPP_ORDER; - sortItemsByOrder(textgenerationwebui_settings.sampler_order); + settings.sampler_order = KOBOLDCPP_ORDER; + sortItemsByOrder(settings.sampler_order); saveSettingsDebounced(); }); $('#textgen_type').on('change', function () { const type = String($(this).val()); - textgenerationwebui_settings.type = type; + settings.type = type; - if (textgenerationwebui_settings.type === textgen_types.APHRODITE) { + if (settings.type === textgen_types.APHRODITE) { //this is needed because showTypeSpecificControls() does not handle NOT declarations $('[data-forAphro=False]').each(function () { $(this).hide(); @@ -347,8 +349,8 @@ jQuery(function () { $('#ban_eos_token_textgenerationwebui').prop('checked', false); //Aphro should not ban EOS, just ignore it; 'add token '2' to ban list do to this' //special handling for Aphrodite topK -1 disable state $('#top_k_textgenerationwebui').attr('min', -1); - if ($('#top_k_textgenerationwebui').val() === '0' || textgenerationwebui_settings['top_k'] === 0) { - textgenerationwebui_settings['top_k'] = -1; + if ($('#top_k_textgenerationwebui').val() === '0' || settings['top_k'] === 0) { + settings['top_k'] = -1; $('#top_k_textgenerationwebui').val('-1').trigger('input'); } } else { @@ -359,8 +361,8 @@ jQuery(function () { $('#mirostat_mode_textgenerationwebui').attr('step', 1); //undo special Aphrodite setup for topK $('#top_k_textgenerationwebui').attr('min', 0); - if ($('#top_k_textgenerationwebui').val() === '-1' || textgenerationwebui_settings['top_k'] === -1) { - textgenerationwebui_settings['top_k'] = 0; + if ($('#top_k_textgenerationwebui').val() === '-1' || settings['top_k'] === -1) { + settings['top_k'] = 0; $('#top_k_textgenerationwebui').val('0').trigger('input'); } } @@ -388,21 +390,21 @@ jQuery(function () { if (isCheckbox) { const value = $(this).prop('checked'); - textgenerationwebui_settings[id] = value; + settings[id] = value; } else if (isText) { const value = $(this).val(); - textgenerationwebui_settings[id] = value; + settings[id] = value; } else { const value = Number($(this).val()); $(`#${id}_counter_textgenerationwebui`).val(value); - textgenerationwebui_settings[id] = value; + settings[id] = value; //special handling for aphrodite using -1 as disabled instead of 0 if ($(this).attr('id') === 'top_k_textgenerationwebui' && - textgenerationwebui_settings.type === textgen_types.APHRODITE && + settings.type === textgen_types.APHRODITE && value === 0) { - textgenerationwebui_settings[id] = -1; + settings[id] = -1; $(this).val(-1); } } @@ -430,7 +432,7 @@ function setSettingByName(setting, value, trigger) { if ('sampler_order' === setting) { value = Array.isArray(value) ? value : KOBOLDCPP_ORDER; sortItemsByOrder(value); - textgenerationwebui_settings.sampler_order = value; + settings.sampler_order = value; return; } @@ -557,11 +559,11 @@ function toIntArray(string) { } function getModel() { - if (textgenerationwebui_settings.type === textgen_types.MANCER) { - return textgenerationwebui_settings.mancer_model; + if (settings.type === MANCER) { + return settings.mancer_model; } - if (textgenerationwebui_settings.type === textgen_types.APHRODITE) { + if (settings.type === APHRODITE) { return online_status; } @@ -575,66 +577,66 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, 'model': getModel(), 'max_new_tokens': maxTokens, 'max_tokens': maxTokens, - 'temperature': textgenerationwebui_settings.temp, - 'top_p': textgenerationwebui_settings.top_p, - 'typical_p': textgenerationwebui_settings.typical_p, - 'min_p': textgenerationwebui_settings.min_p, - 'repetition_penalty': textgenerationwebui_settings.rep_pen, - 'frequency_penalty': textgenerationwebui_settings.freq_pen, - 'presence_penalty': textgenerationwebui_settings.presence_pen, - 'top_k': textgenerationwebui_settings.top_k, - 'min_length': textgenerationwebui_settings.min_length, - 'min_tokens': textgenerationwebui_settings.min_length, - 'num_beams': textgenerationwebui_settings.num_beams, - 'length_penalty': textgenerationwebui_settings.length_penalty, - 'early_stopping': textgenerationwebui_settings.early_stopping, - 'add_bos_token': textgenerationwebui_settings.add_bos_token, + 'temperature': settings.temp, + 'top_p': settings.top_p, + 'typical_p': settings.typical_p, + 'min_p': settings.min_p, + 'repetition_penalty': settings.rep_pen, + 'frequency_penalty': settings.freq_pen, + 'presence_penalty': settings.presence_pen, + 'top_k': settings.top_k, + 'min_length': settings.min_length, + 'min_tokens': settings.min_length, + 'num_beams': settings.num_beams, + 'length_penalty': settings.length_penalty, + 'early_stopping': settings.early_stopping, + 'add_bos_token': settings.add_bos_token, 'stopping_strings': getStoppingStrings(isImpersonate, isContinue), 'stop': getStoppingStrings(isImpersonate, isContinue), 'truncation_length': max_context, - 'ban_eos_token': textgenerationwebui_settings.ban_eos_token, - 'skip_special_tokens': textgenerationwebui_settings.skip_special_tokens, - 'top_a': textgenerationwebui_settings.top_a, - 'tfs': textgenerationwebui_settings.tfs, - 'epsilon_cutoff': textgenerationwebui_settings.epsilon_cutoff, - 'eta_cutoff': textgenerationwebui_settings.eta_cutoff, - 'mirostat_mode': textgenerationwebui_settings.mirostat_mode, - 'mirostat_tau': textgenerationwebui_settings.mirostat_tau, - 'mirostat_eta': textgenerationwebui_settings.mirostat_eta, - 'custom_token_bans': textgenerationwebui_settings.type === textgen_types.APHRODITE ? + 'ban_eos_token': settings.ban_eos_token, + 'skip_special_tokens': settings.skip_special_tokens, + 'top_a': settings.top_a, + 'tfs': settings.tfs, + 'epsilon_cutoff': settings.epsilon_cutoff, + 'eta_cutoff': settings.eta_cutoff, + 'mirostat_mode': settings.mirostat_mode, + 'mirostat_tau': settings.mirostat_tau, + 'mirostat_eta': settings.mirostat_eta, + 'custom_token_bans': settings.type === textgen_types.APHRODITE ? toIntArray(getCustomTokenBans()) : getCustomTokenBans(), - 'api_type': textgenerationwebui_settings.type, - 'api_server': textgenerationwebui_settings.type === textgen_types.MANCER ? + 'api_type': settings.type, + 'api_server': settings.type === MANCER ? MANCER_SERVER : api_server_textgenerationwebui, - 'legacy_api': textgenerationwebui_settings.legacy_api && textgenerationwebui_settings.type !== textgen_types.MANCER, - 'sampler_order': textgenerationwebui_settings.type === textgen_types.KOBOLDCPP ? - textgenerationwebui_settings.sampler_order : + 'legacy_api': settings.legacy_api && settings.type !== MANCER, + 'sampler_order': settings.type === textgen_types.KOBOLDCPP ? + settings.sampler_order : undefined, }; let aphroditeExclusionFlags = { - 'repetition_penalty_range': textgenerationwebui_settings.rep_pen_range, - 'encoder_repetition_penalty': textgenerationwebui_settings.encoder_rep_pen, - 'no_repeat_ngram_size': textgenerationwebui_settings.no_repeat_ngram_size, - 'penalty_alpha': textgenerationwebui_settings.penalty_alpha, - 'temperature_last': textgenerationwebui_settings.temperature_last, - 'do_sample': textgenerationwebui_settings.do_sample, - 'seed': textgenerationwebui_settings.seed, - 'guidance_scale': cfgValues?.guidanceScale?.value ?? textgenerationwebui_settings.guidance_scale ?? 1, - 'negative_prompt': cfgValues?.negativePrompt ?? substituteParams(textgenerationwebui_settings.negative_prompt) ?? '', - 'grammar_string': textgenerationwebui_settings.grammar_string, + 'repetition_penalty_range': settings.rep_pen_range, + 'encoder_repetition_penalty': settings.encoder_rep_pen, + 'no_repeat_ngram_size': settings.no_repeat_ngram_size, + 'penalty_alpha': settings.penalty_alpha, + 'temperature_last': settings.temperature_last, + 'do_sample': settings.do_sample, + 'seed': settings.seed, + 'guidance_scale': cfgValues?.guidanceScale?.value ?? settings.guidance_scale ?? 1, + 'negative_prompt': cfgValues?.negativePrompt ?? substituteParams(settings.negative_prompt) ?? '', + 'grammar_string': settings.grammar_string, }; let aphroditeFlags = { 'n': canMultiSwipe ? textgenerationwebui_settings.n : 1, 'best_of': canMultiSwipe ? textgenerationwebui_settings.n : 1, - 'ignore_eos': textgenerationwebui_settings.ignore_eos_token_aphrodite, - 'spaces_between_special_tokens': textgenerationwebui_settings.spaces_between_special_tokens_aphrodite, + 'ignore_eos': settings.ignore_eos_token_aphrodite, + 'spaces_between_special_tokens': settings.spaces_between_special_tokens_aphrodite, //'logits_processors': textgenerationwebui_settings.logits_processors_aphrodite, //'logprobs': textgenerationwebui_settings.log_probs_aphrodite, //'prompt_logprobs': textgenerationwebui_settings.prompt_log_probs_aphrodite, }; - if (textgenerationwebui_settings.type === textgen_types.APHRODITE) { + if (settings.type === textgen_types.APHRODITE) { APIflags = Object.assign(APIflags, aphroditeFlags); } else { APIflags = Object.assign(APIflags, aphroditeExclusionFlags); diff --git a/public/scripts/tokenizers.js b/public/scripts/tokenizers.js index 2008bea1f..ce52b6704 100644 --- a/public/scripts/tokenizers.js +++ b/public/scripts/tokenizers.js @@ -4,7 +4,9 @@ import { chat_completion_sources, model_list, oai_settings } from './openai.js'; import { groups, selected_group } from './group-chats.js'; import { getStringHash } from './utils.js'; import { kai_flags } from './kai-settings.js'; -import { textgen_types, textgenerationwebui_settings } from './textgen-settings.js'; +import { textgen_types, textgenerationwebui_settings as textgen_settings } from './textgen-settings.js'; + +const { OOBA, TABBY, KOBOLDCPP, MANCER } = textgen_types; export const CHARACTERS_PER_TOKEN_RATIO = 3.35; const TOKENIZER_WARNING_KEY = 'tokenizationWarningShown'; @@ -129,10 +131,7 @@ export function getTokenizerBestMatch(forApi) { // - Tokenizer haven't reported an error previously const hasTokenizerError = sessionStorage.getItem(TOKENIZER_WARNING_KEY); const isConnected = online_status !== 'no_connection'; - const isTokenizerSupported = - textgenerationwebui_settings.type === textgen_types.OOBA || - textgenerationwebui_settings.type === textgen_types.TABBY || - textgenerationwebui_settings.type === textgen_types.KOBOLDCPP; + const isTokenizerSupported = textgen_settings.type === OOBA || textgen_settings.type === TABBY || textgen_settings.type === KOBOLDCPP; if (!hasTokenizerError && isConnected) { if (forApi === 'kobold' && kai_flags.can_use_tokenization) { @@ -396,11 +395,11 @@ function getRemoteTokenizationParams(str) { return { text: str, main_api, - api_type: textgenerationwebui_settings.type, + api_type: textgen_settings.type, url: getAPIServerUrl(), legacy_api: main_api === 'textgenerationwebui' && - textgenerationwebui_settings.legacy_api && - textgenerationwebui_settings.type !== textgen_types.MANCER, + textgen_settings.legacy_api && + textgen_settings.type !== MANCER, }; } From a68505e8575676cb9863ca95813250554dd41753 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sun, 3 Dec 2023 15:00:25 -0500 Subject: [PATCH 4/6] Copy textgen-types enum to server code --- server.js | 36 ++++++++++++++++++------------------ src/constants.js | 10 ++++++++++ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/server.js b/server.js index ad8c75a44..0d38c2637 100644 --- a/server.js +++ b/server.js @@ -180,13 +180,13 @@ function setAdditionalHeaders(request, args, server) { let headers; switch (request.body.api_type) { - case 'mancer': + case TEXTGEN_TYPES.MANCER: headers = getMancerHeaders(); break; - case 'aphrodite': + case TEXTGEN_TYPES.APHRODITE: headers = getAphroditeHeaders(); break; - case 'tabby': + case TEXTGEN_TYPES.TABBY: headers = getTabbyHeaders(); break; default: @@ -217,7 +217,7 @@ const AVATAR_WIDTH = 400; const AVATAR_HEIGHT = 600; const jsonParser = express.json({ limit: '200mb' }); const urlencodedParser = express.urlencoded({ extended: true, limit: '200mb' }); -const { DIRECTORIES, UPLOADS_PATH, PALM_SAFETY } = require('./src/constants'); +const { DIRECTORIES, UPLOADS_PATH, PALM_SAFETY, TEXTGEN_TYPES } = require('./src/constants'); const { TavernCardValidator } = require('./src/validator/TavernCardValidator'); // CSRF Protection // @@ -569,15 +569,15 @@ app.post('/api/textgenerationwebui/status', jsonParser, async function (request, url += '/v1/model'; } else { switch (request.body.api_type) { - case 'ooba': - case 'aphrodite': - case 'koboldcpp': + case TEXTGEN_TYPES.OOBA: + case TEXTGEN_TYPES.APHRODITE: + case TEXTGEN_TYPES.KOBOLDCPP: url += '/v1/models'; break; - case 'mancer': + case TEXTGEN_TYPES.MANCER: url += '/oai/v1/models'; break; - case 'tabby': + case TEXTGEN_TYPES.TABBY: url += '/v1/model/list'; break; } @@ -608,7 +608,7 @@ app.post('/api/textgenerationwebui/status', jsonParser, async function (request, // Set result to the first model ID result = modelIds[0] || 'Valid'; - if (request.body.api_type === 'ooba') { + if (request.body.api_type === TEXTGEN_TYPES.OOBA) { try { const modelInfoUrl = baseUrl + '/v1/internal/model/info'; const modelInfoReply = await fetch(modelInfoUrl, args); @@ -623,7 +623,7 @@ app.post('/api/textgenerationwebui/status', jsonParser, async function (request, } catch (error) { console.error(`Failed to get Ooba model info: ${error}`); } - } else if (request.body.api_type === 'tabby') { + } else if (request.body.api_type === TEXTGEN_TYPES.TABBY) { try { const modelInfoUrl = baseUrl + '/v1/model'; const modelInfoReply = await fetch(modelInfoUrl, args); @@ -675,13 +675,13 @@ app.post('/api/textgenerationwebui/generate', jsonParser, async function (reques url += '/v1/generate'; } else { switch (request.body.api_type) { - case 'aphrodite': - case 'ooba': - case 'tabby': - case 'koboldcpp': + case TEXTGEN_TYPES.APHRODITE: + case TEXTGEN_TYPES.OOBA: + case TEXTGEN_TYPES.TABBY: + case TEXTGEN_TYPES.KOBOLDCPP: url += '/v1/completions'; break; - case 'mancer': + case TEXTGEN_TYPES.MANCER: url += '/oai/v1/completions'; break; } @@ -3500,11 +3500,11 @@ app.post('/tokenize_via_api', jsonParser, async function (request, response) { args.body = JSON.stringify({ 'prompt': text }); } else { switch (request.body.api_type) { - case 'tabby': + case TEXTGEN_TYPES.TABBY: url += '/v1/token/encode'; args.body = JSON.stringify({ 'text': text }); break; - case 'koboldcpp': + case TEXTGEN_TYPES.KOBOLDCPP: url += '/api/extra/tokencount'; args.body = JSON.stringify({ 'prompt': text }); break; diff --git a/src/constants.js b/src/constants.js index b23066ff3..978cc7c43 100644 --- a/src/constants.js +++ b/src/constants.js @@ -134,9 +134,19 @@ const PALM_SAFETY = [ const UPLOADS_PATH = './uploads'; +// TODO: this is copied from the client code; there should be a way to de-duplicate it eventually +const TEXTGEN_TYPES = { + OOBA: 'ooba', + MANCER: 'mancer', + APHRODITE: 'aphrodite', + TABBY: 'tabby', + KOBOLDCPP: 'koboldcpp', +}; + module.exports = { DIRECTORIES, UNSAFE_EXTENSIONS, UPLOADS_PATH, PALM_SAFETY, + TEXTGEN_TYPES, }; From 24ccef3abac5641309b25df889fdba4e04ee8c15 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sun, 3 Dec 2023 15:44:36 -0500 Subject: [PATCH 5/6] Fix "settings" variable being shadowed --- public/scripts/textgen-settings.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index c577c7e09..f79096f36 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -239,12 +239,12 @@ function getCustomTokenBans() { return result.filter(onlyUnique).map(x => String(x)).join(','); } -function loadTextGenSettings(data, settings) { +function loadTextGenSettings(data, loadedSettings) { textgenerationwebui_presets = convertPresets(data.textgenerationwebui_presets); textgenerationwebui_preset_names = data.textgenerationwebui_preset_names ?? []; - Object.assign(settings, settings.textgenerationwebui_settings ?? {}); + Object.assign(settings, loadedSettings.textgenerationwebui_settings ?? {}); - if (settings.api_use_mancer_webui) { + if (loadedSettings.api_use_mancer_webui) { settings.type = MANCER; } From 0a092629ce4141b09512f1e288e0d1665017a58c Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 3 Dec 2023 23:24:39 +0200 Subject: [PATCH 6/6] Fix undefined variable reference --- public/scripts/textgen-settings.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index f79096f36..53ecc65a3 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -628,13 +628,13 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, 'grammar_string': settings.grammar_string, }; let aphroditeFlags = { - 'n': canMultiSwipe ? textgenerationwebui_settings.n : 1, - 'best_of': canMultiSwipe ? textgenerationwebui_settings.n : 1, + 'n': canMultiSwipe ? settings.n : 1, + 'best_of': canMultiSwipe ? settings.n : 1, 'ignore_eos': settings.ignore_eos_token_aphrodite, 'spaces_between_special_tokens': settings.spaces_between_special_tokens_aphrodite, - //'logits_processors': textgenerationwebui_settings.logits_processors_aphrodite, - //'logprobs': textgenerationwebui_settings.log_probs_aphrodite, - //'prompt_logprobs': textgenerationwebui_settings.prompt_log_probs_aphrodite, + //'logits_processors': settings.logits_processors_aphrodite, + //'logprobs': settings.log_probs_aphrodite, + //'prompt_logprobs': settings.prompt_log_probs_aphrodite, }; if (settings.type === textgen_types.APHRODITE) { APIflags = Object.assign(APIflags, aphroditeFlags);