diff --git a/CHANGELOG.md b/CHANGELOG.md index d827cff9..32679bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ 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] - 2024-02-25 + +### Added + +- **🔄 Check for Updates**: Keep your system current by checking for updates conveniently located in Settings > About. +- **🗑️ Automatic Tag Deletion**: Unused tags on the sidebar will now be deleted automatically with just a click. + +### Changed + +- **🎨 Modernized Styling**: Enjoy a refreshed look with updated styling for a more contemporary experience. + ## [0.1.103] - 2024-02-25 ### Added diff --git a/backend/apps/web/models/tags.py b/backend/apps/web/models/tags.py index c14658cf..d4264501 100644 --- a/backend/apps/web/models/tags.py +++ b/backend/apps/web/models/tags.py @@ -167,6 +167,27 @@ class TagTable: .count() ) + def delete_tag_by_tag_name_and_user_id(self, tag_name: str, user_id: str) -> bool: + try: + query = ChatIdTag.delete().where( + (ChatIdTag.tag_name == tag_name) & (ChatIdTag.user_id == user_id) + ) + res = query.execute() # Remove the rows, return number of rows removed. + print(res) + + tag_count = self.count_chat_ids_by_tag_name_and_user_id(tag_name, user_id) + if tag_count == 0: + # Remove tag item from Tag col as well + query = Tag.delete().where( + (Tag.name == tag_name) & (Tag.user_id == user_id) + ) + query.execute() # Remove the rows, return number of rows removed. + + return True + except Exception as e: + print("delete_tag", e) + return False + def delete_tag_by_tag_name_and_chat_id_and_user_id( self, tag_name: str, chat_id: str, user_id: str ) -> bool: diff --git a/backend/apps/web/routers/chats.py b/backend/apps/web/routers/chats.py index 00dcfb6e..1ce537ec 100644 --- a/backend/apps/web/routers/chats.py +++ b/backend/apps/web/routers/chats.py @@ -115,9 +115,12 @@ async def get_user_chats_by_tag_name( for chat_id_tag in Tags.get_chat_ids_by_tag_name_and_user_id(tag_name, user.id) ] - print(chat_ids) + chats = Chats.get_chat_lists_by_chat_ids(chat_ids, skip, limit) - return Chats.get_chat_lists_by_chat_ids(chat_ids, skip, limit) + if len(chats) == 0: + Tags.delete_tag_by_tag_name_and_user_id(tag_name, user.id) + + return chats ############################ 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 a432e9ed..94938b24 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,23 @@ 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"] + + return {"current": VERSION, "latest": latest_version[1:]} + except Exception as e: + raise HTTPException( + status_code=status.HTTP_503_SERVICE_UNAVAILABLE, + detail=ERROR_MESSAGES.RATE_LIMIT_EXCEEDED, + ) + + app.mount("/static", StaticFiles(directory="static"), name="static") 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/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index bb03cdac..67bb3d88 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -490,7 +490,7 @@ }} />