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
b777b6d2
Commit
b777b6d2
authored
Dec 26, 2023
by
Timothy J. Baek
Browse files
chore: version check refac
parent
cc49e0d1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
35 deletions
+56
-35
src/lib/apis/ollama/index.ts
src/lib/apis/ollama/index.ts
+1
-1
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+14
-3
src/lib/stores/index.ts
src/lib/stores/index.ts
+0
-1
src/lib/utils/index.ts
src/lib/utils/index.ts
+10
-0
src/routes/(app)/+layout.svelte
src/routes/(app)/+layout.svelte
+31
-30
No files found.
src/lib/apis/ollama/index.ts
View file @
b777b6d2
...
...
@@ -32,7 +32,7 @@ export const getOllamaVersion = async (
throw
error
;
}
return
res
?.
version
??
'
0
'
;
return
res
?.
version
??
''
;
};
export
const
getOllamaModels
=
async
(
...
...
src/lib/components/chat/SettingsModal.svelte
View file @
b777b6d2
...
...
@@ -9,10 +9,11 @@
} from '$lib/constants';
import toast from 'svelte-french-toast';
import { onMount } from 'svelte';
import { config,
info,
models, settings, user } from '$lib/stores';
import { config, models, settings, user } from '$lib/stores';
import { splitStream, getGravatarURL } from '$lib/utils';
import Advanced from './Settings/Advanced.svelte';
import { stringify } from 'postcss';
import { getOllamaVersion } from '$lib/apis/ollama';
export let show = false;
...
...
@@ -79,6 +80,9 @@
let authType = 'Basic';
let authContent = '';
// About
let ollamaVersion = '';
const checkOllamaConnection = async () => {
if (API_BASE_URL === '') {
API_BASE_URL = OLLAMA_API_BASE_URL;
...
...
@@ -553,7 +557,7 @@
return models;
};
onMount(() => {
onMount(
async
() => {
let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
console.log(settings);
...
...
@@ -586,6 +590,13 @@
authType = settings.authHeader.split(' ')[0];
authContent = settings.authHeader.split(' ')[1];
}
ollamaVersion = await getOllamaVersion(
API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token
).catch((error) => {
return '';
});
});
</script>
...
...
@@ -1607,7 +1618,7 @@
<div class=" mb-2.5 text-sm font-medium">Ollama Version</div>
<div class="flex w-full">
<div class="flex-1 text-xs text-gray-700 dark:text-gray-200">
{
$info?.
ollama
?.v
ersion ?? 'N/A'}
{ollama
V
ersion ?? 'N/A'}
</div>
</div>
</div>
...
...
src/lib/stores/index.ts
View file @
b777b6d2
import
{
writable
}
from
'
svelte/store
'
;
// Backend
export
const
info
=
writable
({});
export
const
config
=
writable
(
undefined
);
export
const
user
=
writable
(
undefined
);
...
...
src/lib/utils/index.ts
View file @
b777b6d2
...
...
@@ -100,3 +100,13 @@ export const copyToClipboard = (text) => {
}
);
};
export
const
checkVersion
=
(
required
,
current
)
=>
{
return
(
current
.
localeCompare
(
required
,
undefined
,
{
numeric
:
true
,
sensitivity
:
'
case
'
,
caseFirst
:
'
upper
'
})
<
0
);
};
src/routes/(app)/+layout.svelte
View file @
b777b6d2
<script lang="ts">
import
{ v4 as uuidv4 } from 'uuid
';
import
toast from 'svelte-french-toast
';
import { onMount, tick } from 'svelte';
import { goto } from '$app/navigation';
import toast from 'svelte-french-toast';
import { info, user, showSettings, settings, models, modelfiles } from '$lib/stores';
import { OLLAMA_API_BASE_URL, REQUIRED_OLLAMA_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import { getOllamaModels, getOllamaVersion } from '$lib/apis/ollama';
import { getOpenAIModels } from '$lib/apis/openai';
import { user, showSettings, settings, models, modelfiles } from '$lib/stores';
import { OLLAMA_API_BASE_URL, REQUIRED_OLLAMA_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
import Sidebar from '$lib/components/layout/Sidebar.svelte';
import { checkVersion } from '$lib/utils';
let ollamaVersion = '';
let loaded = false;
const getModels = async () => {
let models = [];
models.push(
...(await getOllamaModels($settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL, localStorage.token))
...(await getOllamaModels(
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token
).catch((error) => {
toast.error(error);
return [];
}))
);
// If OpenAI API Key exists
if ($settings.OPENAI_API_KEY) {
...
...
@@ -42,42 +49,36 @@
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token
).catch((error) => {
return '
0
';
return '';
});
}
await info.set({ ...$info, ollama: { version: version } });
if (
version.localeCompare(REQUIRED_OLLAMA_VERSION, undefined, {
numeric: true,
sensitivity: 'case',
caseFirst: 'upper'
}) < 0
) {
toast.error(`Ollama Version: ${version}`);
ollamaVersion = version;
console.log(ollamaVersion);
if (checkVersion(REQUIRED_OLLAMA_VERSION, ollamaVersion)) {
toast.error(`Ollama Version: ${ollamaVersion !== '' ? ollamaVersion : 'Not Detected'}`);
}
};
onMount(async () => {
if ($user === undefined) {
await goto('/auth');
}
} else if (['user', 'admin'].includes($user.role)) {
await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
await models.set(await getModels());
await modelfiles.set(JSON.parse(localStorage.getItem('modelfiles') ?? '[]'));
await modelfiles.set(JSON.parse(localStorage.getItem('modelfiles') ?? '[]'));
modelfiles.subscribe(async () => {
// should fetch models
});
await setOllamaVersion();
await tick();
}
loaded = true;
});
let child;
</script>
{#if loaded}
...
...
@@ -121,7 +122,7 @@
</div>
</div>
</div>
{:else if
($info?.ollama?.version ?? '0').localeCompare( REQUIRED_OLLAMA_VERSION, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' } ) < 0
}
{:else if
checkVersion(REQUIRED_OLLAMA_VERSION, ollamaVersion ?? '0')
}
<div class="absolute w-full h-full flex z-50">
<div
class="absolute rounded-xl w-full h-full backdrop-blur bg-gray-900/60 flex justify-center"
...
...
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