From a16e34bcef721775b365e4093eba0ca0234641e0 Mon Sep 17 00:00:00 2001 From: artisticMink Date: Sun, 12 Nov 2023 15:15:30 +0100 Subject: [PATCH 1/6] Add optional toggle for grouping openrouter models By vendor --- public/index.html | 6 ++++ public/scripts/openai.js | 69 +++++++++++++++++++++++++++++++++------- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/public/index.html b/public/index.html index d89ed730e..a50b3d0a3 100644 --- a/public/index.html +++ b/public/index.html @@ -1831,6 +1831,12 @@ +
+ +
-
+
+
diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 1975aafae..f1a209dbc 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -209,6 +209,8 @@ const default_settings = { openrouter_model: openrouter_website_model, openrouter_use_fallback: false, openrouter_force_instruct: false, + openrouter_group_models: false, + openrouter_sort_models: 'alphabetically', jailbreak_system: false, reverse_proxy: '', legacy_streaming: false, @@ -257,6 +259,8 @@ const oai_settings = { openrouter_model: openrouter_website_model, openrouter_use_fallback: false, openrouter_force_instruct: false, + openrouter_group_models: false, + openrouter_sort_models: 'alphabetically', jailbreak_system: false, reverse_proxy: '', legacy_streaming: false, @@ -1241,11 +1245,14 @@ function saveModelList(data) { model_list.sort((a, b) => a?.id && b?.id && a.id.localeCompare(b.id)); if (oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER) { + const sortingProperty = document.getElementById('openrouter_sort_models').value; + model_list = openRouterSortBy(model_list, sortingProperty); + $('#model_openrouter_select').empty(); - const groupModels = document.getElementById('openrouter_group_options')?.checked ?? false; + const groupModels = document.getElementById('openrouter_group_models')?.checked ?? false; if (groupModels) { - appendOpenRouterOptions(groupByVendor(model_list), groupModels); + appendOpenRouterOptions(openRouterGroupByVendor(model_list), groupModels); } else { appendOpenRouterOptions(model_list); } @@ -1301,7 +1308,20 @@ function appendOpenRouterOptions(model_list, groupModels = false, sort = false) } } -function groupByVendor(array) { +const openRouterSortBy = (data, property = 'alphabetically') => { + return data.sort((a, b) => { + if (property === 'context_length') { + return b.context_length - a.context_length; + } else if (property === 'pricing.prompt') { + return parseFloat(a.pricing.prompt) - parseFloat(b.pricing.prompt); + } else { + // Alphabetically + return a?.id && b?.id && a.id.localeCompare(b.id); + } + }); +}; + +function openRouterGroupByVendor(array) { const unsorted = array.reduce((acc, curr) => { const vendor = curr.id.split('/')[0]; @@ -1314,7 +1334,7 @@ function groupByVendor(array) { return acc; }, new Map()); - return new Map([...unsorted.entries()].sort()); + return unsorted; } async function sendAltScaleRequest(openai_msgs_tosend, logit_bias, signal, type) { @@ -2247,6 +2267,7 @@ function loadOpenAISettings(data, settings) { oai_settings.windowai_model = settings.windowai_model ?? default_settings.windowai_model; oai_settings.openrouter_model = settings.openrouter_model ?? default_settings.openrouter_model; oai_settings.openrouter_group_models = settings.openrouter_group_models ?? default_settings.openrouter_group_models; + oai_settings.openrouter_sort_models = settings.openrouter_sort_models ?? default_settings.openrouter_sort_models; oai_settings.openrouter_use_fallback = settings.openrouter_use_fallback ?? default_settings.openrouter_use_fallback; oai_settings.openrouter_force_instruct = settings.openrouter_force_instruct ?? default_settings.openrouter_force_instruct; oai_settings.ai21_model = settings.ai21_model ?? default_settings.ai21_model; @@ -2292,6 +2313,7 @@ function loadOpenAISettings(data, settings) { $('#openai_max_context_counter').val(`${oai_settings.openai_max_context}`); $('#model_openrouter_select').val(oai_settings.openrouter_model); $('#openrouter_group_models').val(oai_settings.openrouter_group_models); + $('#openrouter_sort_models').val(oai_settings.openrouter_sort_models); $('#openai_max_tokens').val(oai_settings.openai_max_tokens); @@ -2833,6 +2855,7 @@ function onSettingsPresetChange() { openrouter_use_fallback: ['#openrouter_use_fallback', 'openrouter_use_fallback', true], openrouter_force_instruct: ['#openrouter_force_instruct', 'openrouter_force_instruct', true], openrouter_group_models: ['#openrouter_group_models', 'openrouter_group_models', false], + openrouter_sort_models: ['#openrouter_sort_models', 'openrouter_sort_models', false], ai21_model: ['#model_ai21_select', 'ai21_model', false], openai_max_context: ['#openai_max_context', 'openai_max_context', false], openai_max_tokens: ['#openai_max_tokens', 'openai_max_tokens', false], @@ -3635,6 +3658,8 @@ $(document).ready(async function () { $("#model_scale_select").on("change", onModelChange); $("#model_palm_select").on("change", onModelChange); $("#model_openrouter_select").on("change", onModelChange); + $("#openrouter_group_models").on("change", getStatusOpen); + $("#openrouter_sort_models").on("change", getStatusOpen); $("#model_ai21_select").on("change", onModelChange); $("#settings_preset_openai").on("change", onSettingsPresetChange); $("#new_oai_preset").on("click", onNewPresetClick); From 3bbbf0d8e4a85ce5efd9e4ac0e532a60ec490659 Mon Sep 17 00:00:00 2001 From: artisticMink Date: Sun, 12 Nov 2023 18:51:41 +0100 Subject: [PATCH 3/6] Put openrouter model sorting in drawer Renames 'Infinity'k tokens to 'Free' --- public/index.html | 41 +++++++++++----- public/scripts/openai.js | 102 ++++++++++++++++++++++----------------- 2 files changed, 87 insertions(+), 56 deletions(-) diff --git a/public/index.html b/public/index.html index 918384bf6..7ebd44ec0 100644 --- a/public/index.html +++ b/public/index.html @@ -1832,19 +1832,34 @@
- -
-
- +
+
+ Openrouter Model Sorting +
+
+
+
+ +
+
+ +
+ + Group models by their vendor. I.e. put all OpenAI models in one group, all Anthropic models in one group etc. Can be combined with sorting. + +
+
+
+
- + Group models by their vendor. I.e. put all OpenAI models in one group, all Anthropic models in one group etc. Can be combined with sorting.
From cc0b4e817474dc0dd9ef03b043df8acc1e131d7d Mon Sep 17 00:00:00 2001 From: artisticMink Date: Sun, 12 Nov 2023 20:54:40 +0100 Subject: [PATCH 5/6] Access oai_settings instead of dom --- public/scripts/openai.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 74216cfe0..df00673d4 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -1244,14 +1244,12 @@ function saveModelList(data) { model_list.sort((a, b) => a?.id && b?.id && a.id.localeCompare(b.id)); if (oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER) { - const sortingProperty = document.getElementById('openrouter_sort_models').value; - model_list = openRouterSortBy(model_list, sortingProperty); + model_list = openRouterSortBy(model_list, oai_settings.openrouter_sort_models); $('#model_openrouter_select').empty(); - const groupModels = document.getElementById('openrouter_group_models')?.checked ?? false; - if (groupModels) { - appendOpenRouterOptions(openRouterGroupByVendor(model_list), groupModels); + if (true === oai_settings.openrouter_group_models) { + appendOpenRouterOptions(openRouterGroupByVendor(model_list), oai_settings.openrouter_group_models); } else { appendOpenRouterOptions(model_list); } From 5bcd49b7caa0a78ee5a2a3d2b9853131901bb2b7 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 12 Nov 2023 22:12:16 +0200 Subject: [PATCH 6/6] More concise UI texts, fix button spam clicks --- public/index.html | 10 +++++----- public/script.js | 4 ++-- public/style.css | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/public/index.html b/public/index.html index e8ddb8d1c..46db49a84 100644 --- a/public/index.html +++ b/public/index.html @@ -1834,7 +1834,7 @@
- Openrouter Model Sorting + OpenRouter Model Sorting
@@ -1850,11 +1850,11 @@
- - Group models by their vendor. I.e. put all OpenAI models in one group, all Anthropic models in one group etc. Can be combined with sorting. + + Put OpenAI models in one group, Anthropic models in other group, etc. Can be combined with sorting.
@@ -1962,7 +1962,7 @@
- + diff --git a/public/script.js b/public/script.js index 53e89cc6e..921ef236d 100644 --- a/public/script.js +++ b/public/script.js @@ -926,12 +926,12 @@ async function getStatus() { export function startStatusLoading() { $(".api_loading").show(); - $(".api_button").attr("disabled", "disabled").addClass("disabled"); + $(".api_button").addClass("disabled"); } export function stopStatusLoading() { $(".api_loading").hide(); - $(".api_button").removeAttr("disabled").removeClass("disabled"); + $(".api_button").removeClass("disabled"); } export function resultCheckStatus() { diff --git a/public/style.css b/public/style.css index e63db8100..1dc1888b4 100644 --- a/public/style.css +++ b/public/style.css @@ -1383,7 +1383,8 @@ select option:not(:checked) { .menu_button.disabled { filter: brightness(75%) grayscale(1); - cursor: not-allowed; + opacity: 0.5; + pointer-events: none; } .fav_on {