From 759883a4c87566cfc60a5faa954655a2ca81e0ab Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 25 Feb 2024 11:55:15 -0800 Subject: [PATCH] feat: check for updates --- CHANGELOG.md | 6 +++ backend/constants.py | 1 + backend/main.py | 8 +--- package.json | 2 +- src/lib/apis/index.ts | 34 ++++++++++++++ src/lib/components/chat/Settings/About.svelte | 45 ++++++++++++++++++- src/lib/utils/index.ts | 5 +-- src/routes/(app)/+layout.svelte | 4 +- 8 files changed, 91 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d827cff9c..1249a626a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.104] - UNRELEASED + +### Added + +- Check for updates in Settings > About. + ## [0.1.103] - 2024-02-25 ### Added diff --git a/backend/constants.py b/backend/constants.py index cb802c7f4..006fa7bbe 100644 --- a/backend/constants.py +++ b/backend/constants.py @@ -47,3 +47,4 @@ class ERROR_MESSAGES(str, Enum): INCORRECT_FORMAT = ( lambda err="": f"Invalid format. Please use the correct format{err if err else ''}" ) + RATE_LIMIT_EXCEEDED = "API rate limit exceeded" diff --git a/backend/main.py b/backend/main.py index 3f971d395..94938b249 100644 --- a/backend/main.py +++ b/backend/main.py @@ -139,15 +139,11 @@ async def get_app_latest_release_version(): response.raise_for_status() latest_version = response.json()["tag_name"] - # Compare versions - return { - "current": VERSION, - "latest": latest_version[1:], - } + return {"current": VERSION, "latest": latest_version[1:]} except Exception as e: raise HTTPException( status_code=status.HTTP_503_SERVICE_UNAVAILABLE, - detail=ERROR_MESSAGES.NOT_FOUND, + detail=ERROR_MESSAGES.RATE_LIMIT_EXCEEDED, ) diff --git a/package.json b/package.json index 7938558db..4a33ec43a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "open-webui", - "version": "0.1.103", + "version": "0.1.104", "private": true, "scripts": { "dev": "vite dev --host", diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index db29e5485..b7b346c0d 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -19,6 +19,10 @@ export const getBackendConfig = async () => { return null; }); + if (error) { + throw error; + } + return res; }; @@ -41,5 +45,35 @@ export const getChangelog = async () => { return null; }); + if (error) { + throw error; + } + + return res; +}; + +export const getVersionUpdates = async () => { + let error = null; + + const res = await fetch(`${WEBUI_BASE_URL}/api/version/updates`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .catch((err) => { + console.log(err); + error = err; + return null; + }); + + if (error) { + throw error; + } + return res; }; diff --git a/src/lib/components/chat/Settings/About.svelte b/src/lib/components/chat/Settings/About.svelte index 60c0d7168..78a76bc63 100644 --- a/src/lib/components/chat/Settings/About.svelte +++ b/src/lib/components/chat/Settings/About.svelte @@ -1,14 +1,39 @@ @@ -20,10 +45,17 @@ {$WEBUI_NAME} Version -
-
+ + +
diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 79e53d9a5..a2c6cb29d 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -101,11 +101,10 @@ export const copyToClipboard = (text) => { ); }; -export const checkVersion = (required, current) => { - // Returns true when current version is below required +export const compareVersion = (latest, current) => { return current === '0.0.0' ? false - : current.localeCompare(required, undefined, { + : current.localeCompare(latest, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 54922fd0f..ede00a1d9 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -28,7 +28,7 @@ config } from '$lib/stores'; import { REQUIRED_OLLAMA_VERSION, WEBUI_API_BASE_URL } from '$lib/constants'; - import { checkVersion } from '$lib/utils'; + import { compareVersion } from '$lib/utils'; import SettingsModal from '$lib/components/chat/SettingsModal.svelte'; import Sidebar from '$lib/components/layout/Sidebar.svelte'; @@ -79,7 +79,7 @@ ollamaVersion = version; console.log(ollamaVersion); - if (checkVersion(REQUIRED_OLLAMA_VERSION, ollamaVersion)) { + if (compareVersion(REQUIRED_OLLAMA_VERSION, ollamaVersion)) { toast.error(`Ollama Version: ${ollamaVersion !== '' ? ollamaVersion : 'Not Detected'}`); } };