Initialize page on load
| @@ -266,8 +266,8 @@ export async function loadAphroditeModels(data) { | ||
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | -let selectedModelId = null; | |
| 269 | +// Page -1 will be initialized from a selected model. | |
| 270 | 270 | let currentPage = -1; |
| 271 | 271 | export async function loadFeatherlessModels(data) { |
| 272 | 272 | const searchBar = document.getElementById('model_search_bar'); |
| 273 | 273 | const modelCardBlock = document.getElementById('model_card_block'); |
| @@ -297,6 +297,8 @@ export async function loadFeatherlessModels(data) { | ||
| 297 | 297 | const perPage = Number(localStorage.getItem(storageKey)) || 10; |
| 298 | 298 | |
| 299 | 299 | // Initialize pagination with the full set of models |
| 300 | + const selectedModelPage = (data.findIndex(x => x.id === textgen_settings.featherless_model) / perPage) + 1; | |
| 301 | + currentPage = currentPage === -1 && selectedModelPage > 0 ? selectedModelPage : 1; | |
| 300 | 302 | setupPagination(originalModels, perPage); |
| 301 | 303 | |
| 302 | 304 | // Function to set up pagination (also used for filtered results) |
| @@ -354,7 +356,7 @@ export async function loadFeatherlessModels(data) { | ||
| 354 | 356 | |
| 355 | 357 | modelCardBlock.appendChild(card); |
| 356 | 358 | |
| 357 | 359 | if (model.id === selectedModelIdtextgen_settings.featherless_model) { |
| 358 | 360 | card.classList.add('selected'); |
| 359 | 361 | } |
| 360 | 362 | |
| @@ -376,8 +378,6 @@ export async function loadFeatherlessModels(data) { | ||
| 376 | 378 | }); |
| 377 | 379 | } |
| 378 | 380 | |
| 379 | - | |
| 380 | - | |
| 381 | 381 | // Add event listener for input on the search bar |
| 382 | 382 | searchBar.addEventListener('input', function () { |
| 383 | 383 | applyFiltersAndSort(); |
| @@ -411,6 +411,12 @@ export async function loadFeatherlessModels(data) { | ||
| 411 | 411 | |
| 412 | 412 | // Function to apply sorting and filtering based on user input |
| 413 | 413 | async function applyFiltersAndSort() { |
| 414 | + if (!(searchBar instanceof HTMLInputElement) || | |
| 415 | + !(sortOrderSelect instanceof HTMLSelectElement) || | |
| 416 | + !(classSelect instanceof HTMLSelectElement) || | |
| 417 | + !(categoriesSelect instanceof HTMLSelectElement)) { | |
| 418 | + return; | |
| 419 | + } | |
| 414 | 420 | const searchQuery = searchBar.value.toLowerCase(); |
| 415 | 421 | const selectedSortOrder = sortOrderSelect.value; |
| 416 | 422 | const selectedClass = classSelect.value; |
| @@ -460,7 +466,15 @@ export async function loadFeatherlessModels(data) { | ||
| 460 | 466 | setupPagination(filteredModels, Number(localStorage.getItem(storageKey)) || perPage, currentPage); |
| 461 | 467 | } |
| 462 | 468 | |
| 463 | - | |
| 469 | + // Required to keep the /model command function | |
| 470 | + $('#featherless_model').empty(); | |
| 471 | + for (const model of data) { | |
| 472 | + const option = document.createElement('option'); | |
| 473 | + option.value = model.id; | |
| 474 | + option.text = model.id; | |
| 475 | + option.selected = model.id === textgen_settings.featherless_model; | |
| 476 | + $('#featherless_model').append(option); | |
| 477 | + } | |
| 464 | 478 | } |
| 465 | 479 | |
| 466 | 480 | async function fetchFeatherlessStats() { |
| @@ -476,10 +490,9 @@ async function fetchFeatherlessNew() { | ||
| 476 | 490 | } |
| 477 | 491 | |
| 478 | 492 | function onFeatherlessModelSelect(modelId) { |
| 479 | - | |
| 480 | 493 | const model = featherlessModels.find(x => x.id === modelId); |
| 481 | - selectedModelId = modelId; | |
| 482 | 494 | textgen_settings.featherless_model = modelId; |
| 495 | + $('#featherless_model').val(modelId); | |
| 483 | 496 | $('#api_button_textgenerationwebui').trigger('click'); |
| 484 | 497 | setGenerationParamsFromPreset({ max_length: model.context_length }); |
| 485 | 498 | } |
| @@ -679,20 +692,6 @@ function getAphroditeModelTemplate(option) { | ||
| 679 | 692 | `)); |
| 680 | 693 | } |
| 681 | 694 | |
| 682 | -function getFeatherlessModelTemplate(option) { | |
| 683 | - const model = featherlessModels.find(x => x.id === option?.element?.value); | |
| 684 | - | |
| 685 | - if (!option.id || !model) { | |
| 686 | - return option.text; | |
| 687 | - } | |
| 688 | - | |
| 689 | - return $((` | |
| 690 | - <div class="flex-container flexFlowColumn"> | |
| 691 | - <div><strong>${DOMPurify.sanitize(model.name)}</strong> | <span>${model.context_length || '???'} tokens</span></div> | |
| 692 | - </div> | |
| 693 | - `)); | |
| 694 | -} | |
| 695 | - | |
| 696 | 695 | async function downloadOllamaModel() { |
| 697 | 696 | try { |
| 698 | 697 | const serverUrl = textgen_settings.server_urls[textgen_types.OLLAMA]; |
| @@ -880,7 +879,6 @@ export function initTextGenModels() { | ||
| 880 | 879 | $('#ollama_download_model').on('click', downloadOllamaModel); |
| 881 | 880 | $('#vllm_model').on('change', onVllmModelSelect); |
| 882 | 881 | $('#aphrodite_model').on('change', onAphroditeModelSelect); |
| 883 | - $('#featherless_model').on('change', onFeatherlessModelSelect); | |
| 884 | 882 | $('#tabby_download_model').on('click', downloadTabbyModel); |
| 885 | 883 | $('#tabby_model').on('change', onTabbyModelSelect); |
| 886 | 884 | |
| @@ -955,13 +953,6 @@ export function initTextGenModels() { | ||
| 955 | 953 | width: '100%', |
| 956 | 954 | templateResult: getAphroditeModelTemplate, |
| 957 | 955 | }); |
| 958 | - $('#featherless_model').select2({ | |
| 959 | - placeholder: 'Select a model', | |
| 960 | - searchInputPlaceholder: 'Search models...', | |
| 961 | - searchInputCssClass: 'text_pole', | |
| 962 | - width: '100%', | |
| 963 | - templateResult: getFeatherlessModelTemplate, | |
| 964 | - }); | |
| 965 | 956 | providersSelect.select2({ |
| 966 | 957 | sorter: data => data.sort((a, b) => a.text.localeCompare(b.text)), |
| 967 | 958 | placeholder: 'Select providers. No selection = all providers.', |
| @@ -186,6 +186,7 @@ const settings = { | ||
| 186 | 186 | openrouter_allow_fallbacks: true, |
| 187 | 187 | xtc_threshold: 0.1, |
| 188 | 188 | xtc_probability: 0, |
| 189 | + featherless_model: '', | |
| 189 | 190 | }; |
| 190 | 191 | |
| 191 | 192 | export let textgenerationwebui_banned_in_macros = []; |