mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
feat: model ordering
This commit is contained in:
@@ -29,8 +29,24 @@ export const getModels = async (token: string = '') => {
|
||||
|
||||
models = models
|
||||
.filter((models) => models)
|
||||
// Sort the models
|
||||
.sort((a, b) => {
|
||||
// Compare case-insensitively
|
||||
// Check if models have position property
|
||||
const aHasPosition = a.info?.meta?.position !== undefined;
|
||||
const bHasPosition = b.info?.meta?.position !== undefined;
|
||||
|
||||
// If both a and b have the position property
|
||||
if (aHasPosition && bHasPosition) {
|
||||
return a.info.meta.position - b.info.meta.position;
|
||||
}
|
||||
|
||||
// If only a has the position property, it should come first
|
||||
if (aHasPosition) return -1;
|
||||
|
||||
// If only b has the position property, it should come first
|
||||
if (bHasPosition) return 1;
|
||||
|
||||
// Compare case-insensitively by name for models without position property
|
||||
const lowerA = a.name.toLowerCase();
|
||||
const lowerB = b.name.toLowerCase();
|
||||
|
||||
@@ -39,8 +55,8 @@ export const getModels = async (token: string = '') => {
|
||||
|
||||
// If same case-insensitively, sort by original strings,
|
||||
// lowercase will come before uppercase due to ASCII values
|
||||
if (a < b) return -1;
|
||||
if (a > b) return 1;
|
||||
if (a.name < b.name) return -1;
|
||||
if (a.name > b.name) return 1;
|
||||
|
||||
return 0; // They are equal
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user