forked from open-webui/open-webui
Merge pull request #375 from ollama-webui/modellist-sort
feat: sort model list by alphabetical order
This commit is contained in:
commit
bdb3f50771
3 changed files with 17 additions and 27 deletions
|
@ -67,7 +67,9 @@ export const getOllamaModels = async (
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res?.models ?? [];
|
return (res?.models ?? []).sort((a, b) => {
|
||||||
|
return a.name.localeCompare(b.name);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateTitle = async (
|
export const generateTitle = async (
|
||||||
|
|
|
@ -29,5 +29,8 @@ export const getOpenAIModels = async (
|
||||||
|
|
||||||
return models
|
return models
|
||||||
.map((model) => ({ name: model.id, external: true }))
|
.map((model) => ({ name: model.id, external: true }))
|
||||||
.filter((model) => (base_url.includes('openai') ? model.name.includes('gpt') : true));
|
.filter((model) => (base_url.includes('openai') ? model.name.includes('gpt') : true))
|
||||||
|
.sort((a, b) => {
|
||||||
|
return a.name.localeCompare(b.name);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import { config, models, settings, user, chats } from '$lib/stores';
|
import { config, models, settings, user, chats } from '$lib/stores';
|
||||||
import { splitStream, getGravatarURL } from '$lib/utils';
|
import { splitStream, getGravatarURL } from '$lib/utils';
|
||||||
|
|
||||||
import { getOllamaVersion } from '$lib/apis/ollama';
|
import { getOllamaVersion, getOllamaModels } from '$lib/apis/ollama';
|
||||||
import { createNewChat, deleteAllChats, getAllChats, getChatList } from '$lib/apis/chats';
|
import { createNewChat, deleteAllChats, getAllChats, getChatList } from '$lib/apis/chats';
|
||||||
import {
|
import {
|
||||||
WEB_UI_VERSION,
|
WEB_UI_VERSION,
|
||||||
|
@ -545,30 +545,15 @@
|
||||||
|
|
||||||
const getModels = async (url = '', type = 'all') => {
|
const getModels = async (url = '', type = 'all') => {
|
||||||
let models = [];
|
let models = [];
|
||||||
const res = await fetch(`${url ? url : $settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/tags`, {
|
models.push(
|
||||||
method: 'GET',
|
...(await getOllamaModels(
|
||||||
headers: {
|
url ? url : $settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
|
||||||
Accept: 'application/json',
|
localStorage.token
|
||||||
'Content-Type': 'application/json',
|
).catch((error) => {
|
||||||
...($settings.authHeader && { Authorization: $settings.authHeader }),
|
toast.error(error);
|
||||||
...($user && { Authorization: `Bearer ${localStorage.token}` })
|
return [];
|
||||||
}
|
}))
|
||||||
})
|
);
|
||||||
.then(async (res) => {
|
|
||||||
if (!res.ok) throw await res.json();
|
|
||||||
return res.json();
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(error);
|
|
||||||
if ('detail' in error) {
|
|
||||||
toast.error(error.detail);
|
|
||||||
} else {
|
|
||||||
toast.error('Server connection failed');
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
console.log(res);
|
|
||||||
models.push(...(res?.models ?? []));
|
|
||||||
|
|
||||||
// If OpenAI API Key exists
|
// If OpenAI API Key exists
|
||||||
if (type === 'all' && $settings.OPENAI_API_KEY) {
|
if (type === 'all' && $settings.OPENAI_API_KEY) {
|
||||||
|
|
Loading…
Reference in a new issue