new search bar for featherless

bebd0e438bfc9aa735b06e45a9d7218b2e268cfd

DarokCx <77368869+DarokCx@users.noreply.github.com>

3 files changed, +288 -15Showing whitespace changes
public/index.html+28 -0
@@ -2263,6 +2263,34 @@
22632263 <div data-for="api_key_featherless" class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you reload the page.">
22642264 For privacy reasons, your API key will be hidden after you reload the page.
22652265 </div>
2266+ <hr>
2267+ <h4 data-i18n="Featherless Model">Featherless Model Selection</h4>
2268+ <div id="Model-management-block" class="flex-container wide100p flexGap10">
2269+ <div class="flex1 overflowHidden wide100p">
2270+ <div class="flex-container marginBot10 alignitemscenter">
2271+ <input id="model_search_bar" class="text_pole width100p flex1 margin0" type="search" data-i18n="[placeholder]Search..." placeholder="Search...">
2272+ <select id="model_sort_order" class="margin0">
2273+ <option value="search" data-i18n="Search" hidden>A-Z</option>
2274+ <option value="asc">A-Z</option>
2275+ <option value="desc">Z-A</option>
2276+ </select>
2277+ <select id="featherless_selection">
2278+ <option value="" disabled selected data-i18n="category">category</option>
2279+ <option value="Favorite" data-i18n="Top">Favorite</option>
2280+ <option value="Top" data-i18n="Top">Top</option>
2281+ <option value="New" data-i18n="New">New</option>
2282+ <option value="All" data-i18n="All">All</option>
2283+ </select>
2284+ <select id="class_selection">
2285+ <option value="" selected data-i18n="class">All Classes</option>
2286+ </select>
2287+ <div id="model_pagination_container" class="flex1"></div>
2288+ <i id="model_grid_toggle" class="fa-solid fa-table-cells-large menu_button" data-i18n="[title]Toggle grid view" title="Toggle grid view"></i>
2289+ </div>
2290+ <div id="model_card_block" data-i18n="[no_desc_text]No model description" no_desc_text="[No description]"></div>
2291+
2292+ </div>
2293+ </div>
22662294 <select id="featherless_model">
22672295 <option value="" data-i18n="-- Connect to the API --">
22682296 -- Connect to the API --
public/scripts/textgen-models.js+151 -15
@@ -266,37 +266,173 @@ export async function loadAphroditeModels(data) {
266266}
267267
268268export async function loadFeatherlessModels(data) {
269+ const searchBar = document.getElementById('model_search_bar');
270+ const modelCardBlock = document.getElementById('model_card_block');
271+ const paginationContainer = $('#model_pagination_container');
272+ const sortOrderSelect = document.getElementById('model_sort_order');
273+ const classSelect = document.getElementById('class_selection');
274+ const storageKey = 'Models_PerPage';
275+
276+ // Store the original models data for search and filtering
277+ let originalModels = [];
278+
269279 if (!Array.isArray(data)) {
270280 console.error('Invalid Featherless models data', data);
271281 return;
272282 }
273283
284+ // Sort the data by model id (default A-Z)
274285 data.sort((a, b) => a.id.localeCompare(b.id));
275- featherlessModels = data;
286+ originalModels = data; // Store the original data for search
276287
277- if (!data.find(x => x.id === textgen_settings.featherless_model)) {
288+ // Populate class select options with unique classes
278- textgen_settings.featherless_model = data[0]?.id || '';
289+ populateClassSelection(data);
290+
291+ // Retrieve the stored number of items per page or default to 5
292+ const perPage = Number(localStorage.getItem(storageKey)) || 5;
293+
294+ // Initialize pagination with the full set of models
295+ setupPagination(originalModels, perPage);
296+
297+ // Function to set up pagination (also used for filtered results)
298+ function setupPagination(models, perPage) {
299+ paginationContainer.pagination({
300+ dataSource: models,
301+ pageSize: perPage,
302+ sizeChangerOptions: [5, 10, 25, 50, 100, 250, 500, 1000],
303+ pageRange: 1,
304+ pageNumber: 1,
305+ showPageNumbers: true,
306+ showSizeChanger: true,
307+ prevText: '<',
308+ nextText: '>',
309+ formatNavigator: function (currentPage, totalPage) {
310+ return 'Page ' + currentPage + ' of ' + totalPage;
311+ },
312+ showNavigator: true,
313+ callback: function (modelsOnPage) {
314+ // Clear the model card block before adding new cards
315+ modelCardBlock.innerHTML = '';
316+
317+ // Loop through the models for the current page and create cards
318+ modelsOnPage.forEach(model => {
319+ const card = document.createElement('div');
320+ card.classList.add('model-card');
321+
322+ const modelNameContainer = document.createElement('div');
323+ modelNameContainer.classList.add('model-name-container');
324+
325+ const modelTitle = document.createElement('div');
326+ modelTitle.classList.add('model-title');
327+ modelTitle.textContent = model.id;
328+ modelNameContainer.appendChild(modelTitle);
329+
330+ const detailsContainer = document.createElement('div');
331+ detailsContainer.classList.add('details-container');
332+
333+ const modelClassDiv = document.createElement('div');
334+ modelClassDiv.classList.add('model-class');
335+ modelClassDiv.textContent = `Class: ${model.model_class || 'N/A'}`;
336+
337+ const contextLengthDiv = document.createElement('div');
338+ contextLengthDiv.classList.add('model-context-length');
339+ contextLengthDiv.textContent = `Context Length: ${model.context_length}`;
340+
341+ detailsContainer.appendChild(modelClassDiv);
342+ detailsContainer.appendChild(contextLengthDiv);
343+
344+ card.appendChild(modelNameContainer);
345+ card.appendChild(detailsContainer);
346+
347+ // Append the card to the container
348+ modelCardBlock.appendChild(card);
349+
350+ // Check if this card is the currently selected model
351+ if (model.id === selectedModelId) {
352+ card.classList.add('selected'); // Keep the selected class if it's the same model
353+ }
354+
355+ // Add click event listener to the card
356+ card.addEventListener('click', function() {
357+ // Remove the selected class from all other cards
358+ document.querySelectorAll('.model-card').forEach(c => c.classList.remove('selected'));
359+
360+ // Add the selected class to the clicked card
361+ card.classList.add('selected');
362+
363+ // Call the onFeatherlessModelSelect function with the selected model ID
364+ onFeatherlessModelSelect(model.id);
365+ });
366+ });
367+ },
368+ afterSizeSelectorChange: function (e) {
369+ const newPerPage = e.target.value;
370+ localStorage.setItem('Models_PerPage', newPerPage); // Save the new value in localStorage
371+ setupPagination(models, Number(newPerPage)); // Reinitialize pagination with the new per page value
372+ },
373+ });
279374 }
280375
281- $('#featherless_model').empty();
376+ // Add event listener for input on the search bar
282- for (const model of data) {
377+ searchBar.addEventListener('input', function() {
378+ applyFiltersAndSort();
379+ });
380+
381+ // Add event listener for the sort order select
382+ sortOrderSelect.addEventListener('change', function() {
383+ applyFiltersAndSort();
384+ });
385+
386+ // Add event listener for the class select
387+ classSelect.addEventListener('change', function() {
388+ applyFiltersAndSort();
389+ });
390+
391+ // Function to populate class selection dropdown
392+ function populateClassSelection(models) {
393+ const uniqueClasses = [...new Set(models.map(model => model.model_class).filter(Boolean))]; // Get unique class names
394+ uniqueClasses.forEach(className => {
283395 const option = document.createElement('option');
284396 option.value = model.idclassName;
285397 option.texttextContent = model.idclassName;
286- option.selected = model.id === textgen_settings.featherless_model;
398+ classSelect.appendChild(option);
287- $('#featherless_model').append(option);
399+ });
288400 }
401+
402+ // Function to apply sorting and filtering based on user input
403+ function applyFiltersAndSort() {
404+ const searchQuery = searchBar.value.toLowerCase();
405+ const selectedSortOrder = sortOrderSelect.value;
406+ const selectedClass = classSelect.value;
407+
408+ // Filter the models based on the search query and selected class
409+ let filteredModels = originalModels.filter(model => {
410+ const matchesSearch = model.id.toLowerCase().includes(searchQuery);
411+ const matchesClass = selectedClass ? model.model_class === selectedClass : true;
412+ return matchesSearch && matchesClass;
413+ });
414+
415+ // Sort the filtered models based on selected sort order (A-Z or Z-A)
416+ if (selectedSortOrder === 'asc') {
417+ filteredModels.sort((a, b) => a.id.localeCompare(b.id));
418+ } else if (selectedSortOrder === 'desc') {
419+ filteredModels.sort((a, b) => b.id.localeCompare(a.id));
289420 }
290421
291-function onFeatherlessModelSelect() {
422+ // Reinitialize pagination with the filtered and sorted models
292- const modelId = String($('#featherless_model').val());
423+ setupPagination(filteredModels, Number(localStorage.getItem(storageKey)) || perPage);
424+ }
425+}
426+
427+let selectedModelId = null;
428+function onFeatherlessModelSelect(modelId) {
429+ // Find the selected model and set the settings
430+ const model = featherlessModels.find(x => x.id === modelId);
293431 textgen_settings.featherless_model = modelId;
294432 $('#api_button_textgenerationwebui').trigger('click');
295- const model = featherlessModels.find(x => x.id === modelId);
296433 setGenerationParamsFromPreset({ max_length: model.context_length });
434+ selectedModelId = modelId; // Store the selected model ID
297435}
298-
299-
300436function onMancerModelSelect() {
301437 const modelId = String($('#mancer_model').val());
302438 textgen_settings.mancer_model = modelId;
public/style.css+109 -0
@@ -5478,3 +5478,112 @@ body:not(.movingUI) .drawer-content.maximized {
54785478#InstructSequencesColumn details:not(:last-of-type) {
54795479 margin-bottom: 5px;
54805480}
5481+
5482+#user_avatar_block {
5483+ display: flex;
5484+ flex-wrap: wrap; /* Ensures cards go to the next row if there's not enough space */
5485+ gap: 10px; /* Adds space between cards */
5486+}
5487+
5488+/* Main structure for the model cards */
5489+.model-card {
5490+ display: flex;
5491+ justify-content: space-between; /* Align the title and details across the card */
5492+ align-items: center; /* Center align the items vertically */
5493+ padding: 15px; /* Padding around the content */
5494+ border: 1px solid #333; /* Border for the card */
5495+ border-radius: 8px; /* Rounded corners for the card */
5496+ background-color: #222; /* Card background color */
5497+ color: #fff; /* Text color */
5498+ margin: 10px; /* Space between cards */
5499+ width: calc(100% - 20px); /* Full width minus margin */
5500+ box-sizing: border-box; /* Include padding and border in the width */
5501+ transition: transform 0.2s ease-in-out, background-color 0.2s ease-in-out, border 0.2s ease-in-out;
5502+}
5503+
5504+.model-card:hover {
5505+ transform: scale(1.05); /* Grow the card slightly on hover */
5506+ background-color: #444; /* Highlight background on hover */
5507+ transition: transform 0.2s ease-in-out, background-color 0.2s ease-in-out; /* Smooth transition */
5508+}
5509+
5510+/* Highlight the selected model card */
5511+.model-card.selected {
5512+ border: 2px solid #00f; /* Add a blue border to indicate selection */
5513+ background-color: #333; /* Slightly darker background for selected state */
5514+}
5515+
5516+/* Model title information */
5517+.model-info {
5518+ flex: 1; /* Take up the remaining space */
5519+ white-space: nowrap;
5520+ overflow: hidden;
5521+ text-overflow: ellipsis; /* Ellipsis for overflow text */
5522+}
5523+
5524+.model-title {
5525+ font-size: 16px;
5526+ font-weight: bold; /* Bold text for the model title */
5527+}
5528+
5529+/* Model details section */
5530+.model-details {
5531+ display: flex;
5532+ flex-direction: column; /* Stack class and context length vertically */
5533+ align-items: flex-end; /* Align details to the end (right) */
5534+ text-align: right; /* Right-aligned text for class and context length */
5535+ min-width: 120px; /* Minimum width to prevent excessive squeezing */
5536+}
5537+
5538+.model-class, .model-context-length {
5539+ font-size: 14px; /* Smaller font size for details */
5540+}
5541+
5542+.model-class {
5543+ margin-bottom: 5px; /* Space between class and context length */
5544+}
5545+
5546+/* Grid-view layout for the card container */
5547+#model_card_block.grid-view {
5548+ display: flex;
5549+ flex-wrap: wrap; /* Cards wrap onto new lines when necessary */
5550+ gap: 15px; /* Space between grid items */
5551+ justify-content: flex-start; /* Align cards to the left */
5552+}
5553+
5554+/* Grid-view card */
5555+#model_card_block.grid-view .model-card {
5556+ flex-direction: column; /* Stack title, class, and context length vertically for grid */
5557+ flex: 1 1 calc(33.33% - 30px); /* 3 cards per row with spacing */
5558+ margin-bottom: 10px;
5559+}
5560+
5561+/* Ensure the search bar takes most of the width */
5562+#model_search_bar {
5563+ flex-grow: 1;
5564+ min-width: 0;
5565+}
5566+
5567+/* Sort dropdown should be auto-sized based on its content */
5568+#model_sort_order {
5569+ width: auto; /* Set the width of the dropdown to its content size */
5570+ flex-shrink: 0; /* Prevent it from shrinking */
5571+}
5572+
5573+/* Grid toggle button */
5574+#model_grid_toggle {
5575+ flex-shrink: 0;
5576+ width: auto; /* Keep default button size */
5577+ cursor: pointer;
5578+}
5579+
5580+#featherless_selection
5581+{
5582+ display: flex;
5583+ width: auto;
5584+}
5585+#class_selection
5586+{
5587+ display: flex;
5588+ width: auto;
5589+}