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 @@
15 z-index: 40000;15 z-index: 40000;
16}16}
1717
18.select2-selection__clear {18.select2-container .select2-selection .select2-selection__clear {
19 color: var(--SmartThemeBodyColor);19 color: var(--SmartThemeBodyColor);
20 font-size: 24px;
21 padding: 0;
22 position: absolute;
23 right: 5px;
24 top: 0;
20}25}
2126
22.select2-container .select2-search__field {27.select2-container .select2-search__field {
public/index.html+14 -3
@@ -2335,8 +2335,7 @@
2335 </div>2335 </div>
2336 <div class="flex1">2336 <div class="flex1">
2337 <h4>2337 <h4>
2338 <span data-i18n="Ollama Model">Ollama Model2338 <span data-i18n="Ollama Model">Ollama Model</span>
2339 </h4>
2340 </h4>2339 </h4>
2341 <select id="ollama_model">2340 <select id="ollama_model">
2342 <option data-i18n="-- Connect to the API --">2341 <option data-i18n="-- Connect to the API --">
@@ -2373,7 +2372,19 @@
2373 <h4>2372 <h4>
2374 <span data-i18n="Tabby Model">Tabby Model</span>2373 <span data-i18n="Tabby Model">Tabby Model</span>
2375 </h4>2374 </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>
2377 <div id="tabby_download_model" class="menu_button menu_button_icon">2388 <div id="tabby_download_model" class="menu_button menu_button_icon">
2378 <i class="fa-solid fa-download"></i>2389 <i class="fa-solid fa-download"></i>
2379 <span data-i18n="Download">Download</span>2390 <span data-i18n="Download">Download</span>
public/script.js+4 -1
@@ -224,7 +224,7 @@ import {
224import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js';224import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js';
225import { hideLoader, showLoader } from './scripts/loader.js';225import { hideLoader, showLoader } from './scripts/loader.js';
226import { BulkEditOverlay, CharacterContextMenu } from './scripts/BulkEditOverlay.js';226import { BulkEditOverlay, CharacterContextMenu } from './scripts/BulkEditOverlay.js';
227import { loadFeatherlessModels, loadMancerModels, loadOllamaModels, loadTogetherAIModels, loadInfermaticAIModels, loadOpenRouterModels, loadVllmModels, loadAphroditeModels, loadDreamGenModels, initTextGenModels } from './scripts/textgen-models.js';227import { loadFeatherlessModels, loadMancerModels, loadOllamaModels, loadTogetherAIModels, loadInfermaticAIModels, loadOpenRouterModels, loadVllmModels, loadAphroditeModels, loadDreamGenModels, initTextGenModels, loadTabbyModels } from './scripts/textgen-models.js';
228import { appendFileContent, hasPendingFileAttachment, populateFileAttachment, decodeStyleTags, encodeStyleTags, isExternalMediaAllowed, getCurrentEntityId } from './scripts/chats.js';228import { appendFileContent, hasPendingFileAttachment, populateFileAttachment, decodeStyleTags, encodeStyleTags, isExternalMediaAllowed, getCurrentEntityId } from './scripts/chats.js';
229import { initPresetManager } from './scripts/preset-manager.js';229import { initPresetManager } from './scripts/preset-manager.js';
230import { MacrosParser, evaluateMacros, getLastMessageId } from './scripts/macros.js';230import { MacrosParser, evaluateMacros, getLastMessageId } from './scripts/macros.js';
@@ -1214,6 +1214,9 @@ async function getStatusTextgen() {
1214 } else if (textgen_settings.type === FEATHERLESS) {1214 } else if (textgen_settings.type === FEATHERLESS) {
1215 loadFeatherlessModels(data?.data);1215 loadFeatherlessModels(data?.data);
1216 setOnlineStatus(textgen_settings.featherless_model);1216 setOnlineStatus(textgen_settings.featherless_model);
1217 } else if (textgen_settings.type === TABBY) {
1218 loadTabbyModels(data?.data);
1219 setOnlineStatus(textgen_settings.tabby_model || data?.result);
1217 } else {1220 } else {
1218 setOnlineStatus(data?.result);1221 setOnlineStatus(data?.result);
1219 }1222 }
public/scripts/preset-manager.js+1 -0
@@ -338,6 +338,7 @@ class PresetManager {
338 'max_tokens_second',338 'max_tokens_second',
339 'openrouter_providers',339 'openrouter_providers',
340 'openrouter_allow_fallbacks',340 'openrouter_allow_fallbacks',
341 'tabby_model',
341 ];342 ];
342 const settings = Object.assign({}, getSettingsByApiId(this.apiId));343 const settings = Object.assign({}, getSettingsByApiId(this.apiId));
343344
public/scripts/slash-commands.js+1 -0
@@ -3426,6 +3426,7 @@ function getModelOptions(quiet) {
3426 { id: 'vllm_model', api: 'textgenerationwebui', type: textgen_types.VLLM },3426 { id: 'vllm_model', api: 'textgenerationwebui', type: textgen_types.VLLM },
3427 { id: 'aphrodite_model', api: 'textgenerationwebui', type: textgen_types.APHRODITE },3427 { id: 'aphrodite_model', api: 'textgenerationwebui', type: textgen_types.APHRODITE },
3428 { id: 'ollama_model', api: 'textgenerationwebui', type: textgen_types.OLLAMA },3428 { id: 'ollama_model', api: 'textgenerationwebui', type: textgen_types.OLLAMA },
3429 { id: 'tabby_model', api: 'textgenerationwebui', type: textgen_types.TABBY },
3429 { id: 'model_openai_select', api: 'openai', type: chat_completion_sources.OPENAI },3430 { id: 'model_openai_select', api: 'openai', type: chat_completion_sources.OPENAI },
3430 { id: 'model_claude_select', api: 'openai', type: chat_completion_sources.CLAUDE },3431 { id: 'model_claude_select', api: 'openai', type: chat_completion_sources.CLAUDE },
3431 { id: 'model_windowai_select', api: 'openai', type: chat_completion_sources.WINDOWAI },3432 { id: 'model_windowai_select', api: 'openai', type: chat_completion_sources.WINDOWAI },
public/scripts/textgen-models.js+39 -0
@@ -12,6 +12,7 @@ let dreamGenModels = [];
12let vllmModels = [];12let vllmModels = [];
13let aphroditeModels = [];13let aphroditeModels = [];
14let featherlessModels = [];14let featherlessModels = [];
15let tabbyModels = [];
15export let openRouterModels = [];16export let openRouterModels = [];
1617
17/**18/**
@@ -66,6 +67,30 @@ export async function loadOllamaModels(data) {
66 }67 }
67}68}
6869
70export 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
69export async function loadTogetherAIModels(data) {94export async function loadTogetherAIModels(data) {
70 if (!Array.isArray(data)) {95 if (!Array.isArray(data)) {
71 console.error('Invalid Together AI models data', data);96 console.error('Invalid Together AI models data', data);
@@ -310,6 +335,12 @@ function onOllamaModelSelect() {
310 $('#api_button_textgenerationwebui').trigger('click');335 $('#api_button_textgenerationwebui').trigger('click');
311}336}
312337
338function onTabbyModelSelect() {
339 const modelId = String($('#tabby_model').val());
340 textgen_settings.tabby_model = modelId;
341 $('#api_button_textgenerationwebui').trigger('click');
342}
343
313function onOpenRouterModelSelect() {344function onOpenRouterModelSelect() {
314 const modelId = String($('#openrouter_model').val());345 const modelId = String($('#openrouter_model').val());
315 textgen_settings.openrouter_model = modelId;346 textgen_settings.openrouter_model = modelId;
@@ -641,6 +672,7 @@ export function initTextGenModels() {
641 $('#aphrodite_model').on('change', onAphroditeModelSelect);672 $('#aphrodite_model').on('change', onAphroditeModelSelect);
642 $('#featherless_model').on('change', onFeatherlessModelSelect);673 $('#featherless_model').on('change', onFeatherlessModelSelect);
643 $('#tabby_download_model').on('click', downloadTabbyModel);674 $('#tabby_download_model').on('click', downloadTabbyModel);
675 $('#tabby_model').on('change', onTabbyModelSelect);
644676
645 const providersSelect = $('.openrouter_providers');677 const providersSelect = $('.openrouter_providers');
646 for (const provider of OPENROUTER_PROVIDERS) {678 for (const provider of OPENROUTER_PROVIDERS) {
@@ -671,6 +703,13 @@ export function initTextGenModels() {
671 searchInputCssClass: 'text_pole',703 searchInputCssClass: 'text_pole',
672 width: '100%',704 width: '100%',
673 });705 });
706 $('#tabby_model').select2({
707 placeholder: '[Currently loaded]',
708 searchInputPlaceholder: 'Search models...',
709 searchInputCssClass: 'text_pole',
710 width: '100%',
711 allowClear: true,
712 });
674 $('#model_infermaticai_select').select2({713 $('#model_infermaticai_select').select2({
675 placeholder: 'Select a model',714 placeholder: 'Select a model',
676 searchInputPlaceholder: 'Search models...',715 searchInputPlaceholder: 'Search models...',
public/scripts/textgen-settings.js+6 -0
@@ -180,6 +180,7 @@ const settings = {
180 vllm_model: '',180 vllm_model: '',
181 aphrodite_model: '',181 aphrodite_model: '',
182 dreamgen_model: 'opus-v1-xl/text',182 dreamgen_model: 'opus-v1-xl/text',
183 tabby_model: '',
183 legacy_api: false,184 legacy_api: false,
184 sampler_order: KOBOLDCPP_ORDER,185 sampler_order: KOBOLDCPP_ORDER,
185 logit_bias: [],186 logit_bias: [],
@@ -1047,6 +1048,11 @@ export function getTextGenModel() {
1047 return settings.featherless_model;1048 return settings.featherless_model;
1048 case HUGGINGFACE:1049 case HUGGINGFACE:
1049 return 'tgi';1050 return 'tgi';
1051 case TABBY:
1052 if (settings.tabby_model) {
1053 return settings.tabby_model;
1054 }
1055 break;
1050 default:1056 default:
1051 return undefined;1057 return undefined;
1052 }1058 }