Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
bdb3f507
Unverified
Commit
bdb3f507
authored
Jan 04, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Jan 04, 2024
Browse files
Merge pull request #375 from ollama-webui/modellist-sort
feat: sort model list by alphabetical order
parents
c6c32e2a
f6640c4e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
27 deletions
+17
-27
src/lib/apis/ollama/index.ts
src/lib/apis/ollama/index.ts
+3
-1
src/lib/apis/openai/index.ts
src/lib/apis/openai/index.ts
+4
-1
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+10
-25
No files found.
src/lib/apis/ollama/index.ts
View file @
bdb3f507
...
@@ -67,7 +67,9 @@ export const getOllamaModels = async (
...
@@ -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
(
...
...
src/lib/apis/openai/index.ts
View file @
bdb3f507
...
@@ -29,5 +29,8 @@ export const getOpenAIModels = 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
);
});
};
};
src/lib/components/chat/SettingsModal.svelte
View file @
bdb3f507
...
@@ -7,7 +7,7 @@
...
@@ -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 @@
...
@@ -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) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment