From 6bfe2a6306478ff86368557e9cfc5794329d1b22 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 25 Feb 2024 11:26:58 -0800 Subject: [PATCH 01/10] feat: latest release check api --- backend/main.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/main.py b/backend/main.py index a432e9ed..3f971d39 100644 --- a/backend/main.py +++ b/backend/main.py @@ -4,8 +4,9 @@ import markdown import time import os import sys +import requests -from fastapi import FastAPI, Request, Depends +from fastapi import FastAPI, Request, Depends, status from fastapi.staticfiles import StaticFiles from fastapi import HTTPException from fastapi.responses import JSONResponse @@ -26,6 +27,8 @@ from apps.web.main import app as webui_app from config import WEBUI_NAME, ENV, VERSION, CHANGELOG, FRONTEND_BUILD_DIR +from constants import ERROR_MESSAGES + from utils.utils import get_http_authorization_cred, get_current_user @@ -127,6 +130,27 @@ async def get_app_changelog(): return CHANGELOG +@app.get("/api/version/updates") +async def get_app_latest_release_version(): + try: + response = requests.get( + f"https://api.github.com/repos/open-webui/open-webui/releases/latest" + ) + response.raise_for_status() + latest_version = response.json()["tag_name"] + + # Compare versions + 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, + ) + + app.mount("/static", StaticFiles(directory="static"), name="static") From 759883a4c87566cfc60a5faa954655a2ca81e0ab Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 25 Feb 2024 11:55:15 -0800 Subject: [PATCH 02/10] 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'}`); } }; From fb3804ac9597df10e2e11b5f0e5d0535d63ec019 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 25 Feb 2024 12:10:14 -0800 Subject: [PATCH 03/10] fix: check version loading progress --- src/lib/components/chat/Settings/About.svelte | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/Settings/About.svelte b/src/lib/components/chat/Settings/About.svelte index 78a76bc6..fdeaa8b9 100644 --- a/src/lib/components/chat/Settings/About.svelte +++ b/src/lib/components/chat/Settings/About.svelte @@ -8,13 +8,14 @@ let ollamaVersion = ''; - let updateAvailable = false; + let updateAvailable = null; let version = { current: '', latest: '' }; const checkForVersionUpdates = async () => { + updateAvailable = null; version = await getVersionUpdates(localStorage.token).catch((error) => { return { current: WEBUI_VERSION, @@ -54,7 +55,11 @@ href="https://github.com/open-webui/open-webui/releases/tag/v{version.latest}" target="_blank" > - {updateAvailable ? `(v${version.latest} available!)` : '(latest)'} + {updateAvailable === null + ? 'Checking for updates...' + : updateAvailable + ? `(v${version.latest} available!)` + : '(latest)'} From 0d9e38a0ce1cff7ddb5404c808bf4a71a2f43520 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 25 Feb 2024 12:31:31 -0800 Subject: [PATCH 04/10] refac: styling --- src/lib/components/chat/MessageInput.svelte | 22 +++--- .../chat/MessageInput/Suggestions.svelte | 78 ++++++++++--------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index bb03cdac..f2d9abf8 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -490,7 +490,7 @@ }} />
{ submitPrompt(prompt, user); }} @@ -633,9 +633,9 @@
{#if fileUploadEnabled} -
+
@@ -659,7 +657,7 @@