diff --git a/public/index.html b/public/index.html
index a50b3d0a3..918384bf6 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1832,8 +1832,17 @@
-
+
+
+
Group by vendor names
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);