enh: reintroduce model order/default models

This commit is contained in:
Timothy Jaeryang Baek
2024-11-26 00:55:58 -08:00
parent 29fac5ecca
commit 5fac25a002
12 changed files with 407 additions and 66 deletions
+34 -4
View File
@@ -58,17 +58,46 @@ export const exportConfig = async (token: string) => {
return res;
};
export const setDefaultModels = async (token: string, models: string) => {
export const getModelsConfig = async (token: string) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/default/models`, {
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/models`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.log(err);
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
export const setModelsConfig = async (token: string, config: object) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/models`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({
models: models
...config
})
})
.then(async (res) => {
@@ -88,10 +117,11 @@ export const setDefaultModels = async (token: string, models: string) => {
return res;
};
export const setDefaultPromptSuggestions = async (token: string, promptSuggestions: string) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/default/suggestions`, {
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/suggestions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
-20
View File
@@ -25,26 +25,6 @@ export const getModels = async (token: string = '', base: boolean = false) => {
}
let models = res?.data ?? [];
models = models
.filter((models) => models)
// Sort the models
.sort((a, b) => {
// Compare case-insensitively by name for models without position property
const lowerA = a.name.toLowerCase();
const lowerB = b.name.toLowerCase();
if (lowerA < lowerB) return -1;
if (lowerA > lowerB) return 1;
// If same case-insensitively, sort by original strings,
// lowercase will come before uppercase due to ASCII values
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0; // They are equal
});
console.log(models);
return models;
};