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
e366d113
Commit
e366d113
authored
Nov 19, 2023
by
Timothy J. Baek
Browse files
fix: model list update
parent
2342c503
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
50 deletions
+46
-50
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+44
-48
src/routes/(app)/+layout.svelte
src/routes/(app)/+layout.svelte
+2
-0
src/routes/(app)/+page.svelte
src/routes/(app)/+page.svelte
+0
-2
No files found.
src/lib/components/chat/SettingsModal.svelte
View file @
e366d113
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
import { WEB_UI_VERSION, OLLAMA_API_BASE_URL as BUILD_TIME_API_BASE_URL } from '$lib/constants';
import { WEB_UI_VERSION, OLLAMA_API_BASE_URL as BUILD_TIME_API_BASE_URL } from '$lib/constants';
import toast from 'svelte-french-toast';
import toast from 'svelte-french-toast';
import { onMount } from 'svelte';
import { onMount } from 'svelte';
import { config, settings, user } from '$lib/stores';
import { config,
models,
settings, user } from '$lib/stores';
import { splitStream, getGravatarURL } from '$lib/utils';
import { splitStream, getGravatarURL } from '$lib/utils';
export let show = false;
export let show = false;
...
@@ -50,7 +50,7 @@
...
@@ -50,7 +50,7 @@
if (API_BASE_URL === '') {
if (API_BASE_URL === '') {
API_BASE_URL = BUILD_TIME_API_BASE_URL;
API_BASE_URL = BUILD_TIME_API_BASE_URL;
}
}
const res = await getModel
Tag
s(API_BASE_URL, 'ollama');
const res = await getModels(API_BASE_URL, 'ollama');
if (res) {
if (res) {
toast.success('Server connection verified');
toast.success('Server connection verified');
...
@@ -97,6 +97,7 @@
...
@@ -97,6 +97,7 @@
method: 'POST',
method: 'POST',
headers: {
headers: {
'Content-Type': 'text/event-stream',
'Content-Type': 'text/event-stream',
...($settings.authHeader && { Authorization: $settings.authHeader }),
...($user && { Authorization: `Bearer ${localStorage.token}` })
...($user && { Authorization: `Bearer ${localStorage.token}` })
},
},
body: JSON.stringify({
body: JSON.stringify({
...
@@ -150,7 +151,7 @@
...
@@ -150,7 +151,7 @@
}
}
modelTag = '';
modelTag = '';
await getModel
Tag
s();
models.set(
await getModels()
)
;
};
};
const deleteModelHandler = async () => {
const deleteModelHandler = async () => {
...
@@ -158,6 +159,7 @@
...
@@ -158,6 +159,7 @@
method: 'DELETE',
method: 'DELETE',
headers: {
headers: {
'Content-Type': 'text/event-stream',
'Content-Type': 'text/event-stream',
...($settings.authHeader && { Authorization: $settings.authHeader }),
...($user && { Authorization: `Bearer ${localStorage.token}` })
...($user && { Authorization: `Bearer ${localStorage.token}` })
},
},
body: JSON.stringify({
body: JSON.stringify({
...
@@ -203,7 +205,7 @@
...
@@ -203,7 +205,7 @@
}
}
deleteModelTag = '';
deleteModelTag = '';
await getModel
Tag
s();
models.set(
await getModels()
)
;
};
};
$: if (show) {
$: if (show) {
...
@@ -226,14 +228,14 @@
...
@@ -226,14 +228,14 @@
OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
}
}
const getModel
Tag
s = async (url =
null
, type = 'all') => {
const getModels = async (url =
''
, type = 'all') => {
let models = [];
let models = [];
const res = await fetch(`${url
=== null ? API_BASE_URL : url
}/tags`, {
const res = await fetch(`${url
? url : $settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL
}/tags`, {
method: 'GET',
method: 'GET',
headers: {
headers: {
Accept: 'application/json',
Accept: 'application/json',
'Content-Type': 'application/json',
'Content-Type': 'application/json',
...(settings.authHeader && { Authorization: settings.authHeader }),
...(
$
settings.authHeader && { Authorization:
$
settings.authHeader }),
...($user && { Authorization: `Bearer ${localStorage.token}` })
...($user && { Authorization: `Bearer ${localStorage.token}` })
}
}
})
})
...
@@ -250,50 +252,44 @@
...
@@ -250,50 +252,44 @@
}
}
return null;
return null;
});
});
console.log(res);
console.log(res);
models.push(...(res?.models ?? []));
if (type === 'all') {
if (settings.OPENAI_API_KEY) {
// If OpenAI API Key exists
// Validate OPENAI_API_KEY
if (type === 'all' && $settings.OPENAI_API_KEY) {
const openaiModelRes = await fetch(`https://api.openai.com/v1/models`, {
// Validate OPENAI_API_KEY
method: 'GET',
const openaiModelRes = await fetch(`https://api.openai.com/v1/models`, {
headers: {
method: 'GET',
'Content-Type': 'application/json',
headers: {
Authorization: `Bearer ${settings.OPENAI_API_KEY}`
'Content-Type': 'application/json',
}
Authorization: `Bearer ${$settings.OPENAI_API_KEY}`
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((error) => {
console.log(error);
toast.error(`OpenAI: ${error?.error?.message ?? 'Network Problem'}`);
return null;
});
const openaiModels = openaiModelRes?.data ?? null;
if (openaiModels) {
models = [
...(res?.models ?? []),
{ name: 'hr' },
...openaiModels
.map((model) => ({ name: model.id, label: 'OpenAI' }))
.filter((model) => model.name.includes('gpt'))
];
} else {
models = res?.models ?? [];
}
}
} else {
})
models = res?.models ?? [];
.then(async (res) => {
}
if (!res.ok) throw await res.json();
return res.json();
return models;
})
} else {
.catch((error) => {
return res?.models ?? null;
console.log(error);
toast.error(`OpenAI: ${error?.error?.message ?? 'Network Problem'}`);
return null;
});
const openAIModels = openaiModelRes?.data ?? null;
models.push(
...(openAIModels
? [
{ name: 'hr' },
...openAIModels
.map((model) => ({ name: model.id, label: 'OpenAI' }))
.filter((model) => model.name.includes('gpt'))
]
: [])
);
}
}
return models;
};
};
onMount(() => {
onMount(() => {
...
...
src/routes/(app)/+layout.svelte
View file @
e366d113
...
@@ -93,6 +93,8 @@
...
@@ -93,6 +93,8 @@
await goto('/auth');
await goto('/auth');
}
}
await settings.set(JSON.parse(localStorage.getItem('settings') ?? JSON.stringify($settings)));
let _models = await getModels();
let _models = await getModels();
await models.set(_models);
await models.set(_models);
let _db = await getDB();
let _db = await getDB();
...
...
src/routes/(app)/+page.svelte
View file @
e366d113
...
@@ -62,8 +62,6 @@
...
@@ -62,8 +62,6 @@
messages: {},
messages: {},
currentId: null
currentId: null
};
};
await settings.set(JSON.parse(localStorage.getItem('settings') ?? JSON.stringify($settings)));
selectedModels = $settings.models ?? [''];
selectedModels = $settings.models ?? [''];
};
};
...
...
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