Remove is[API] functions

Just use an equality comparison. It's a bit longer, but only because
"textgenerationwebui_settings" is a long identifier.
This commit is contained in:
valadaptive
2023-12-03 02:55:38 -05:00
parent ba54e3dea0
commit 047c897ead
4 changed files with 39 additions and 45 deletions

View File

@@ -17,14 +17,9 @@ import {
getTextGenGenerationData, getTextGenGenerationData,
formatTextGenURL, formatTextGenURL,
getTextGenUrlSourceId, getTextGenUrlSourceId,
isMancer,
isAphrodite,
isTabby,
textgen_types, textgen_types,
textgenerationwebui_banned_in_macros, textgenerationwebui_banned_in_macros,
isOoba,
MANCER_SERVER, MANCER_SERVER,
isKoboldCpp,
} from './scripts/textgen-settings.js'; } from './scripts/textgen-settings.js';
import { import {
@@ -888,14 +883,17 @@ async function getStatus() {
main_api, main_api,
api_server: endpoint, api_server: endpoint,
api_type: textgenerationwebui_settings.type, 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, signal: abortStatusCheck.signal,
}); });
const data = await response.json(); 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; online_status = textgenerationwebui_settings.mancer_model;
loadMancerModels(data?.data); loadMancerModels(data?.data);
} else { } else {
@@ -943,7 +941,7 @@ export function resultCheckStatus() {
export function getAPIServerUrl() { export function getAPIServerUrl() {
if (main_api == 'textgenerationwebui') { if (main_api == 'textgenerationwebui') {
if (isMancer()) { if (textgenerationwebui_settings.type === textgen_types.MANCER) {
return MANCER_SERVER; return MANCER_SERVER;
} }
@@ -2847,7 +2845,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
return; 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 }); 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(); unblockGeneration();
return; return;

View File

@@ -34,7 +34,7 @@ import {
import { debounce, delay, getStringHash, isValidUrl } from './utils.js'; import { debounce, delay, getStringHash, isValidUrl } from './utils.js';
import { chat_completion_sources, oai_settings } from './openai.js'; import { chat_completion_sources, oai_settings } from './openai.js';
import { getTokenCount } from './tokenizers.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'); var RPanelPin = document.getElementById('rm_button_panel_pin');
@@ -401,7 +401,7 @@ function RA_autoconnect(PrevApi) {
} }
break; break;
case 'textgenerationwebui': 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'); $('#api_button_textgenerationwebui').trigger('click');
} }
else if (api_server_textgenerationwebui && isValidUrl(api_server_textgenerationwebui)) { else if (api_server_textgenerationwebui && isValidUrl(api_server_textgenerationwebui)) {

View File

@@ -162,7 +162,7 @@ async function selectPreset(name) {
function formatTextGenURL(value) { function formatTextGenURL(value) {
try { try {
// Mancer doesn't need any formatting (it's hardcoded) // Mancer doesn't need any formatting (it's hardcoded)
if (isMancer()) { if (textgenerationwebui_settings.type === textgen_types.MANCER) {
return value; return value;
} }
@@ -265,7 +265,7 @@ function loadTextGenSettings(data, settings) {
$('#textgen_type').val(textgenerationwebui_settings.type); $('#textgen_type').val(textgenerationwebui_settings.type);
showTypeSpecificControls(textgenerationwebui_settings.type); showTypeSpecificControls(textgenerationwebui_settings.type);
//this is needed because showTypeSpecificControls() does not handle NOT declarations //this is needed because showTypeSpecificControls() does not handle NOT declarations
if (isAphrodite()) { if (textgenerationwebui_settings.type === textgen_types.APHRODITE) {
$('[data-forAphro=False]').each(function () { $('[data-forAphro=False]').each(function () {
$(this).hide(); $(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() { export function getTextGenUrlSourceId() {
switch (textgenerationwebui_settings.type) { switch (textgenerationwebui_settings.type) {
case textgen_types.OOBA: case textgen_types.OOBA:
@@ -357,7 +337,7 @@ jQuery(function () {
const type = String($(this).val()); const type = String($(this).val());
textgenerationwebui_settings.type = type; textgenerationwebui_settings.type = type;
if (isAphrodite()) { if (textgenerationwebui_settings.type === textgen_types.APHRODITE) {
//this is needed because showTypeSpecificControls() does not handle NOT declarations //this is needed because showTypeSpecificControls() does not handle NOT declarations
$('[data-forAphro=False]').each(function () { $('[data-forAphro=False]').each(function () {
$(this).hide(); $(this).hide();
@@ -419,7 +399,9 @@ jQuery(function () {
$(`#${id}_counter_textgenerationwebui`).val(value); $(`#${id}_counter_textgenerationwebui`).val(value);
textgenerationwebui_settings[id] = value; textgenerationwebui_settings[id] = value;
//special handling for aphrodite using -1 as disabled instead of 0 //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; textgenerationwebui_settings[id] = -1;
$(this).val(-1); $(this).val(-1);
} }
@@ -575,11 +557,11 @@ function toIntArray(string) {
} }
function getModel() { function getModel() {
if (isMancer()) { if (textgenerationwebui_settings.type === textgen_types.MANCER) {
return textgenerationwebui_settings.mancer_model; return textgenerationwebui_settings.mancer_model;
} }
if (isAphrodite()) { if (textgenerationwebui_settings.type === textgen_types.APHRODITE) {
return online_status; return online_status;
} }
@@ -619,11 +601,17 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
'mirostat_mode': textgenerationwebui_settings.mirostat_mode, 'mirostat_mode': textgenerationwebui_settings.mirostat_mode,
'mirostat_tau': textgenerationwebui_settings.mirostat_tau, 'mirostat_tau': textgenerationwebui_settings.mirostat_tau,
'mirostat_eta': textgenerationwebui_settings.mirostat_eta, '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_type': textgenerationwebui_settings.type,
'api_server': isMancer() ? MANCER_SERVER : api_server_textgenerationwebui, 'api_server': textgenerationwebui_settings.type === textgen_types.MANCER ?
'legacy_api': textgenerationwebui_settings.legacy_api && !isMancer(), MANCER_SERVER :
'sampler_order': isKoboldCpp() ? textgenerationwebui_settings.sampler_order : undefined, 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 = { let aphroditeExclusionFlags = {
'repetition_penalty_range': textgenerationwebui_settings.rep_pen_range, 'repetition_penalty_range': textgenerationwebui_settings.rep_pen_range,
@@ -646,7 +634,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
//'logprobs': textgenerationwebui_settings.log_probs_aphrodite, //'logprobs': textgenerationwebui_settings.log_probs_aphrodite,
//'prompt_logprobs': textgenerationwebui_settings.prompt_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); APIflags = Object.assign(APIflags, aphroditeFlags);
} else { } else {
APIflags = Object.assign(APIflags, aphroditeExclusionFlags); APIflags = Object.assign(APIflags, aphroditeExclusionFlags);

View File

@@ -4,7 +4,7 @@ import { chat_completion_sources, model_list, oai_settings } from './openai.js';
import { groups, selected_group } from './group-chats.js'; import { groups, selected_group } from './group-chats.js';
import { getStringHash } from './utils.js'; import { getStringHash } from './utils.js';
import { kai_flags } from './kai-settings.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; export const CHARACTERS_PER_TOKEN_RATIO = 3.35;
const TOKENIZER_WARNING_KEY = 'tokenizationWarningShown'; const TOKENIZER_WARNING_KEY = 'tokenizationWarningShown';
@@ -129,7 +129,10 @@ export function getTokenizerBestMatch(forApi) {
// - Tokenizer haven't reported an error previously // - Tokenizer haven't reported an error previously
const hasTokenizerError = sessionStorage.getItem(TOKENIZER_WARNING_KEY); const hasTokenizerError = sessionStorage.getItem(TOKENIZER_WARNING_KEY);
const isConnected = online_status !== 'no_connection'; 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 (!hasTokenizerError && isConnected) {
if (forApi === 'kobold' && kai_flags.can_use_tokenization) { if (forApi === 'kobold' && kai_flags.can_use_tokenization) {
@@ -395,7 +398,9 @@ function getRemoteTokenizationParams(str) {
main_api, main_api,
api_type: textgenerationwebui_settings.type, api_type: textgenerationwebui_settings.type,
url: getAPIServerUrl(), 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,
}; };
} }