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 d827cff9..1249a626 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 cb802c7f..006fa7bb 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 3f971d39..94938b24 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 7938558d..4a33ec43 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 db29e548..b7b346c0 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 60c0d716..78a76bc6 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 79e53d9a..a2c6cb29 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 54922fd0..ede00a1d 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'}`); } };