From f61c2403d66377fadcdbf5e4685ca4a4ae092651 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:05:50 +0300 Subject: [PATCH] Featherless: Fix model pagination init --- public/scripts/textgen-models.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/public/scripts/textgen-models.js b/public/scripts/textgen-models.js index 32b288b39..793be430b 100644 --- a/public/scripts/textgen-models.js +++ b/public/scripts/textgen-models.js @@ -288,15 +288,19 @@ export async function loadFeatherlessModels(data) { originalModels = data; // Store the original data for search featherlessModels = data; + if (!data.find(x => x.id === textgen_settings.featherless_model)) { + textgen_settings.featherless_model = data[0]?.id || ''; + } + // Populate class select options with unique classes populateClassSelection(data); - // Retrieve the stored number of items per page or default to 5 + // Retrieve the stored number of items per page or default to 10 const perPage = Number(localStorage.getItem(storageKey)) || 10; // Initialize pagination with the full set of models - const selectedModelPage = (data.findIndex(x => x.id === textgen_settings.featherless_model) / perPage) + 1; - featherlessCurrentPage = selectedModelPage > 0 ? selectedModelPage : 1; + const currentModelIndex = data.findIndex(x => x.id === textgen_settings.featherless_model); + featherlessCurrentPage = currentModelIndex >= 0 ? (currentModelIndex / perPage) + 1 : 1; setupPagination(originalModels, perPage); // Function to set up pagination (also used for filtered results)