From 832770e7b23c669a57b2f9c6fb26d3d56ca78ce9 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 14 Dec 2023 19:43:52 -0800 Subject: [PATCH] feat: ollama version check --- src/lib/components/chat/SettingsModal.svelte | 13 ++- src/lib/stores/index.ts | 1 + src/routes/(app)/+layout.svelte | 105 +++++++++++++++++-- 3 files changed, 108 insertions(+), 11 deletions(-) diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 7eb0b87d..d7ee57a5 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -4,7 +4,7 @@ import { WEB_UI_VERSION, OLLAMA_API_BASE_URL } from '$lib/constants'; import toast from 'svelte-french-toast'; import { onMount } from 'svelte'; - import { config, models, settings, user } from '$lib/stores'; + import { config, info, models, settings, user } from '$lib/stores'; import { splitStream, getGravatarURL } from '$lib/utils'; import Advanced from './Settings/Advanced.svelte'; @@ -1075,6 +1075,17 @@
+
+
Ollama Version
+
+
+ {$info?.ollama?.version ?? 'N/A'} +
+
+
+ +
+
Created by { @@ -160,33 +162,116 @@ }; }; + const getOllamaVersion = async () => { + const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/version`, { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...($settings.authHeader && { Authorization: $settings.authHeader }), + ...($user && { Authorization: `Bearer ${localStorage.token}` }) + } + }) + .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); + + return res?.version ?? '0'; + }; + + const setOllamaVersion = async (ollamaVersion) => { + await info.set({ ...$info, ollama: { version: ollamaVersion } }); + + if ( + ollamaVersion.localeCompare(requiredOllamaVersion, undefined, { + numeric: true, + sensitivity: 'case', + caseFirst: 'upper' + }) < 0 + ) { + toast.error(`Ollama Version: ${ollamaVersion}`); + } + }; + onMount(async () => { if ($config && $config.auth && $user === undefined) { await goto('/auth'); } - await settings.set(JSON.parse(localStorage.getItem('settings') ?? JSON.stringify($settings))); + await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}')); - let _models = await getModels(); - await models.set(_models); - let _db = await getDB(); - await db.set(_db); - - await modelfiles.set( - JSON.parse(localStorage.getItem('modelfiles') ?? JSON.stringify($modelfiles)) - ); + await models.set(await getModels()); + await modelfiles.set(JSON.parse(localStorage.getItem('modelfiles') ?? '[]')); modelfiles.subscribe(async () => { await models.set(await getModels()); }); + let _db = await getDB(); + await db.set(_db); + + await setOllamaVersion(await getOllamaVersion()); + await tick(); loaded = true; }); {#if loaded} -
+
+ {#if ($info?.ollama?.version ?? '0').localeCompare( requiredOllamaVersion, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' } ) < 0} +
+
+
+
+ Ollama Update Required +
+ +
+ Oops! It seems like your Ollama needs a little attention. + We encountered a connection issue or noticed that you're running an outdated version. Please + update to + {requiredOllamaVersion} or above. +
+ +
+ + + +
+
+
+
+ {/if} +