Add Tabby model selection

42fa3c79d70d069f483ba8b06d3cc31efbe09b55

Cohee <18619528+Cohee1207@users.noreply.github.com>

7 files changed, +71 -5Showing whitespace changes
public/css/select2-overrides.css+6 -1
@@ -15,8 +15,13 @@
1515 z-index: 40000;
1616}
1717
1818.select2-container .select2-selection .select2-selection__clear {
1919 color: var(--SmartThemeBodyColor);
20+ font-size: 24px;
21+ padding: 0;
22+ position: absolute;
23+ right: 5px;
24+ top: 0;
2025}
2126
2227.select2-container .select2-search__field {
public/index.html+14 -3
@@ -2335,8 +2335,7 @@
23352335 </div>
23362336 <div class="flex1">
23372337 <h4>
23382338 <span data-i18n="Ollama Model">Ollama Model</span>
2339- </h4>
23402339 </h4>
23412340 <select id="ollama_model">
23422341 <option data-i18n="-- Connect to the API --">
@@ -2373,7 +2372,19 @@
23732372 <h4>
23742373 <span data-i18n="Tabby Model">Tabby Model</span>
23752374 </h4>
2376- </h4>
2375+ <select id="tabby_model">
2376+ <option data-i18n="-- Connect to the API --">
2377+ -- Connect to the API --
2378+ </option>
2379+ </select>
2380+ <small>
2381+ <i class="fa-solid fa-lightbulb"></i>
2382+ &nbsp;
2383+ <code>inline_model_loading: true</code>
2384+ <span data-i18n="must be set in Tabby's config.yml to switch models.">
2385+ must be set in Tabby's config.yml to switch models.
2386+ </span>
2387+ </small>
23772388 <div id="tabby_download_model" class="menu_button menu_button_icon">
23782389 <i class="fa-solid fa-download"></i>
23792390 <span data-i18n="Download">Download</span>
public/script.js+4 -1
@@ -224,7 +224,7 @@ import {
224224import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js';
225225import { hideLoader, showLoader } from './scripts/loader.js';
226226import { BulkEditOverlay, CharacterContextMenu } from './scripts/BulkEditOverlay.js';
227227import { loadFeatherlessModels, loadMancerModels, loadOllamaModels, loadTogetherAIModels, loadInfermaticAIModels, loadOpenRouterModels, loadVllmModels, loadAphroditeModels, loadDreamGenModels, initTextGenModels, loadTabbyModels } from './scripts/textgen-models.js';
228228import { appendFileContent, hasPendingFileAttachment, populateFileAttachment, decodeStyleTags, encodeStyleTags, isExternalMediaAllowed, getCurrentEntityId } from './scripts/chats.js';
229229import { initPresetManager } from './scripts/preset-manager.js';
230230import { MacrosParser, evaluateMacros, getLastMessageId } from './scripts/macros.js';
@@ -1214,6 +1214,9 @@ async function getStatusTextgen() {
12141214 } else if (textgen_settings.type === FEATHERLESS) {
12151215 loadFeatherlessModels(data?.data);
12161216 setOnlineStatus(textgen_settings.featherless_model);
1217+ } else if (textgen_settings.type === TABBY) {
1218+ loadTabbyModels(data?.data);
1219+ setOnlineStatus(textgen_settings.tabby_model || data?.result);
12171220 } else {
12181221 setOnlineStatus(data?.result);
12191222 }
public/scripts/preset-manager.js+1 -0
@@ -338,6 +338,7 @@ class PresetManager {
338338 'max_tokens_second',
339339 'openrouter_providers',
340340 'openrouter_allow_fallbacks',
341+ 'tabby_model',
341342 ];
342343 const settings = Object.assign({}, getSettingsByApiId(this.apiId));
343344
public/scripts/slash-commands.js+1 -0
@@ -3426,6 +3426,7 @@ function getModelOptions(quiet) {
34263426 { id: 'vllm_model', api: 'textgenerationwebui', type: textgen_types.VLLM },
34273427 { id: 'aphrodite_model', api: 'textgenerationwebui', type: textgen_types.APHRODITE },
34283428 { id: 'ollama_model', api: 'textgenerationwebui', type: textgen_types.OLLAMA },
3429+ { id: 'tabby_model', api: 'textgenerationwebui', type: textgen_types.TABBY },
34293430 { id: 'model_openai_select', api: 'openai', type: chat_completion_sources.OPENAI },
34303431 { id: 'model_claude_select', api: 'openai', type: chat_completion_sources.CLAUDE },
34313432 { id: 'model_windowai_select', api: 'openai', type: chat_completion_sources.WINDOWAI },
public/scripts/textgen-models.js+39 -0
@@ -12,6 +12,7 @@ let dreamGenModels = [];
1212let vllmModels = [];
1313let aphroditeModels = [];
1414let featherlessModels = [];
15+let tabbyModels = [];
1516export let openRouterModels = [];
1617
1718/**
@@ -66,6 +67,30 @@ export async function loadOllamaModels(data) {
6667 }
6768}
6869
70+export async function loadTabbyModels(data) {
71+ if (!Array.isArray(data)) {
72+ console.error('Invalid Tabby models data', data);
73+ return;
74+ }
75+
76+ tabbyModels = data;
77+ tabbyModels.sort((a, b) => a.id.localeCompare(b.id));
78+ tabbyModels.unshift({ id: '' });
79+
80+ if (!tabbyModels.find(x => x.id === textgen_settings.tabby_model)) {
81+ textgen_settings.tabby_model = tabbyModels[0]?.id || '';
82+ }
83+
84+ $('#tabby_model').empty();
85+ for (const model of tabbyModels) {
86+ const option = document.createElement('option');
87+ option.value = model.id;
88+ option.text = model.id;
89+ option.selected = model.id === textgen_settings.tabby_model;
90+ $('#tabby_model').append(option);
91+ }
92+}
93+
6994export async function loadTogetherAIModels(data) {
7095 if (!Array.isArray(data)) {
7196 console.error('Invalid Together AI models data', data);
@@ -310,6 +335,12 @@ function onOllamaModelSelect() {
310335 $('#api_button_textgenerationwebui').trigger('click');
311336}
312337
338+function onTabbyModelSelect() {
339+ const modelId = String($('#tabby_model').val());
340+ textgen_settings.tabby_model = modelId;
341+ $('#api_button_textgenerationwebui').trigger('click');
342+}
343+
313344function onOpenRouterModelSelect() {
314345 const modelId = String($('#openrouter_model').val());
315346 textgen_settings.openrouter_model = modelId;
@@ -641,6 +672,7 @@ export function initTextGenModels() {
641672 $('#aphrodite_model').on('change', onAphroditeModelSelect);
642673 $('#featherless_model').on('change', onFeatherlessModelSelect);
643674 $('#tabby_download_model').on('click', downloadTabbyModel);
675+ $('#tabby_model').on('change', onTabbyModelSelect);
644676
645677 const providersSelect = $('.openrouter_providers');
646678 for (const provider of OPENROUTER_PROVIDERS) {
@@ -671,6 +703,13 @@ export function initTextGenModels() {
671703 searchInputCssClass: 'text_pole',
672704 width: '100%',
673705 });
706+ $('#tabby_model').select2({
707+ placeholder: '[Currently loaded]',
708+ searchInputPlaceholder: 'Search models...',
709+ searchInputCssClass: 'text_pole',
710+ width: '100%',
711+ allowClear: true,
712+ });
674713 $('#model_infermaticai_select').select2({
675714 placeholder: 'Select a model',
676715 searchInputPlaceholder: 'Search models...',
public/scripts/textgen-settings.js+6 -0
@@ -180,6 +180,7 @@ const settings = {
180180 vllm_model: '',
181181 aphrodite_model: '',
182182 dreamgen_model: 'opus-v1-xl/text',
183+ tabby_model: '',
183184 legacy_api: false,
184185 sampler_order: KOBOLDCPP_ORDER,
185186 logit_bias: [],
@@ -1047,6 +1048,11 @@ export function getTextGenModel() {
10471048 return settings.featherless_model;
10481049 case HUGGINGFACE:
10491050 return 'tgi';
1051+ case TABBY:
1052+ if (settings.tabby_model) {
1053+ return settings.tabby_model;
1054+ }
1055+ break;
10501056 default:
10511057 return undefined;
10521058 }