diff --git a/public/index.html b/public/index.html index 46942e6d9..9a00e5cbd 100644 --- a/public/index.html +++ b/public/index.html @@ -2224,6 +2224,14 @@ Example: http://127.0.0.1:5000 +
+

Tabby API Model

+ +
diff --git a/public/script.js b/public/script.js index 84a0e9d5d..e91794046 100644 --- a/public/script.js +++ b/public/script.js @@ -22,7 +22,7 @@ import { parseTabbyLogprobs, } from './scripts/textgen-settings.js'; -const { MANCER, TOGETHERAI, OOBA, APHRODITE, OLLAMA, INFERMATICAI, DREAMGEN, OPENROUTER } = textgen_types; +const { MANCER, TOGETHERAI, OOBA, APHRODITE, OLLAMA, INFERMATICAI, DREAMGEN, OPENROUTER , TABBY } = textgen_types; import { world_info, @@ -1149,6 +1149,9 @@ async function getStatusTextgen() { } else if (textgen_settings.type === APHRODITE) { loadAphroditeModels(data?.data); online_status = textgen_settings.aphrodite_model; + } else if (textgen_settings.type === TABBY) { + loadTabbyApiModels(data?.data); + online_status = textgen_settings.tabby_api_model; } else { online_status = data?.result; } diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index 1a28f075c..502db0ff6 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -310,6 +310,7 @@ class PresetManager { 'togetherai_model', 'ollama_model', 'aphrodite_model', + 'tabby_api_model', 'server_urls', 'type', 'custom_model', diff --git a/public/scripts/textgen-models.js b/public/scripts/textgen-models.js index 0c580a3d4..e9881ee38 100644 --- a/public/scripts/textgen-models.js +++ b/public/scripts/textgen-models.js @@ -1,13 +1,24 @@ import { isMobile } from './RossAscends-mods.js'; -import { amount_gen, callPopup, eventSource, event_types, getRequestHeaders, max_context, setGenerationParamsFromPreset } from '../script.js'; +import { + amount_gen, + callPopup, + eventSource, + event_types, + getRequestHeaders, + max_context, + setGenerationParamsFromPreset, + token, settings, +} from '../script.js'; import { textgenerationwebui_settings as textgen_settings, textgen_types } from './textgen-settings.js'; import { tokenizers } from './tokenizers.js'; +import { findSecret, readSecretState, SECRET_KEYS } from './secrets.js'; let mancerModels = []; let togetherModels = []; let infermaticAIModels = []; let dreamGenModels = []; let aphroditeModels = []; +let tabbyApiModels = []; export let openRouterModels = []; export async function loadOllamaModels(data) { @@ -178,6 +189,28 @@ export async function loadAphroditeModels(data) { } } +export async function loadTabbyApiModels(data) { + if (!Array.isArray(data)) { + console.error('Invalid Tabby API models data', data); + return; + } + + tabbyApiModels = data; + + if (!data.find(x => x.id === textgen_settings.tabby_api_model)) { + textgen_settings.tabby_api_model = data[0]?.id || ''; + } + + $('#tabby_api_model').empty(); + for (const model of data) { + const option = document.createElement('option'); + option.value = model.id; + option.text = model.id; + option.selected = model.id === textgen_settings.aphrodite_model; + $('#tabby_api_model').append(option); + } +} + function onMancerModelSelect() { const modelId = String($('#mancer_model').val()); textgen_settings.mancer_model = modelId; @@ -230,6 +263,37 @@ function onAphroditeModelSelect() { $('#api_button_textgenerationwebui').trigger('click'); } +async function onTabbyApiModelSelect() { + const modelId = String($('#tabby_api_model').val()); + textgen_settings.tabby_api_model = modelId; + + try { + const url = String($('#tabby_api_url_text').val()) + 'v1/model/load'; + fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRF-Token': token, + 'x-admin-key': await findSecret(SECRET_KEYS.TABBY), + }, + body: JSON.stringify({ + name: textgen_settings.tabby_api_model, + }), + }).then( + (value) => { + console.log(value); // Success! + }, + (reason) => { + console.error('Could not load model: ' + reason); // Error! + }, + ); + } catch (err) { + console.error('Error setting model ', err); + } + + $('#api_button_textgenerationwebui').trigger('click'); +} + function getMancerModelTemplate(option) { const model = mancerModels.find(x => x.id === option?.element?.value); @@ -324,6 +388,20 @@ function getAphroditeModelTemplate(option) { `)); } +function getTabbyApiModelTemplate(option) { + const model = tabbyApiModels.find(x => x.id === option?.element?.value); + + if (!option.id || !model) { + return option.text; + } + + return $((` +
+
${DOMPurify.sanitize(model.id)}
+
+ `)); +} + async function downloadOllamaModel() { try { const serverUrl = textgen_settings.server_urls[textgen_types.OLLAMA]; @@ -427,6 +505,7 @@ jQuery(function () { $('#openrouter_model').on('change', onOpenRouterModelSelect); $('#ollama_download_model').on('click', downloadOllamaModel); $('#aphrodite_model').on('change', onAphroditeModelSelect); + $('#tabby_api_model').on('change', onTabbyApiModelSelect); if (!isMobile()) { $('#mancer_model').select2({ @@ -477,5 +556,12 @@ jQuery(function () { width: '100%', templateResult: getAphroditeModelTemplate, }); + $('#tabby_api_model').select2({ + placeholder: 'Select a model', + searchInputPlaceholder: 'Search models...', + searchInputCssClass: 'text_pole', + width: '100%', + templateResult: getTabbyApiModelTemplate, + }); } }); diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 4f8156a38..80b902a81 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -146,6 +146,7 @@ const settings = { ollama_model: '', openrouter_model: 'openrouter/auto', aphrodite_model: '', + tabby_api_model: '', dreamgen_model: 'opus-v1-xl/text', legacy_api: false, sampler_order: KOBOLDCPP_ORDER, @@ -1113,4 +1114,3 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, return params; } -