From 429242b4d3bb6e24badfc403f690540b3b44cd6f Mon Sep 17 00:00:00 2001 From: Self Denial Date: Wed, 10 Apr 2024 20:30:00 -0600 Subject: [PATCH 01/23] Introduce Whisper model auto-update control. * Introduce WHISPER_MODEL_AUTO_UPDATE env var * Pass local_files_only to WhisperModel() * Handle cases where auto-update is disabled but model is non-existent --- backend/apps/audio/main.py | 23 +++++++++++++++++------ backend/config.py | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/backend/apps/audio/main.py b/backend/apps/audio/main.py index 02d1f5e8..4f65b5f5 100644 --- a/backend/apps/audio/main.py +++ b/backend/apps/audio/main.py @@ -28,6 +28,7 @@ from config import ( UPLOAD_DIR, WHISPER_MODEL, WHISPER_MODEL_DIR, + WHISPER_MODEL_AUTO_UPDATE, DEVICE_TYPE, ) @@ -69,12 +70,22 @@ def transcribe( f.write(contents) f.close() - model = WhisperModel( - WHISPER_MODEL, - device=whisper_device_type, - compute_type="int8", - download_root=WHISPER_MODEL_DIR, - ) + whisper_kwargs = { + "model_size_or_path": WHISPER_MODEL, + "device": whisper_device_type, + "compute_type": "int8", + "download_root": WHISPER_MODEL_DIR, + "local_files_only": not WHISPER_MODEL_AUTO_UPDATE, + } + + log.debug(f"whisper_kwargs: {whisper_kwargs}") + + try: + model = WhisperModel(**whisper_kwargs) + except: + log.debug("WhisperModel initialization failed, attempting download with local_files_only=False") + whisper_kwargs["local_files_only"] = False + model = WhisperModel(**whisper_kwargs) segments, info = model.transcribe(file_path, beam_size=5) log.info( diff --git a/backend/config.py b/backend/config.py index 6e3cf92a..4436a5a0 100644 --- a/backend/config.py +++ b/backend/config.py @@ -446,6 +446,9 @@ Query: [query]""" WHISPER_MODEL = os.getenv("WHISPER_MODEL", "base") WHISPER_MODEL_DIR = os.getenv("WHISPER_MODEL_DIR", f"{CACHE_DIR}/whisper/models") +WHISPER_MODEL_AUTO_UPDATE = ( + os.environ.get("WHISPER_MODEL_AUTO_UPDATE", "").lower() == "true" +) #################################### From 81c8717d75170a5d5a8526dea35894060105d222 Mon Sep 17 00:00:00 2001 From: Self Denial Date: Wed, 10 Apr 2024 20:44:44 -0600 Subject: [PATCH 02/23] Format fix --- backend/apps/audio/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/apps/audio/main.py b/backend/apps/audio/main.py index 4f65b5f5..0111ebaf 100644 --- a/backend/apps/audio/main.py +++ b/backend/apps/audio/main.py @@ -80,10 +80,12 @@ def transcribe( log.debug(f"whisper_kwargs: {whisper_kwargs}") - try: + try: model = WhisperModel(**whisper_kwargs) except: - log.debug("WhisperModel initialization failed, attempting download with local_files_only=False") + log.debug( + "WhisperModel initialization failed, attempting download with local_files_only=False" + ) whisper_kwargs["local_files_only"] = False model = WhisperModel(**whisper_kwargs) From 3b8ea55bc8ec0cd00b31001e431021c39b174150 Mon Sep 17 00:00:00 2001 From: Self Denial Date: Wed, 10 Apr 2024 23:21:12 -0600 Subject: [PATCH 03/23] Add IMAGE_GENERATION_ENABLED env var With default of `False`. --- backend/apps/images/main.py | 4 ++-- backend/config.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/apps/images/main.py b/backend/apps/images/main.py index af8cbf7c..bf312598 100644 --- a/backend/apps/images/main.py +++ b/backend/apps/images/main.py @@ -29,7 +29,7 @@ import base64 import json import logging -from config import SRC_LOG_LEVELS, CACHE_DIR, AUTOMATIC1111_BASE_URL, COMFYUI_BASE_URL +from config import SRC_LOG_LEVELS, CACHE_DIR, IMAGE_GENERATION_ENABLED, AUTOMATIC1111_BASE_URL, COMFYUI_BASE_URL log = logging.getLogger(__name__) @@ -48,7 +48,7 @@ app.add_middleware( ) app.state.ENGINE = "" -app.state.ENABLED = False +app.state.ENABLED = IMAGE_GENERATION_ENABLED app.state.OPENAI_API_KEY = "" app.state.MODEL = "" diff --git a/backend/config.py b/backend/config.py index 6e3cf92a..24ccaa47 100644 --- a/backend/config.py +++ b/backend/config.py @@ -452,5 +452,8 @@ WHISPER_MODEL_DIR = os.getenv("WHISPER_MODEL_DIR", f"{CACHE_DIR}/whisper/models" # Images #################################### +IMAGE_GENERATION_ENABLED = ( + os.environ.get("IMAGE_GENERATION_ENABLED", "").lower() == "true" +) AUTOMATIC1111_BASE_URL = os.getenv("AUTOMATIC1111_BASE_URL", "") COMFYUI_BASE_URL = os.getenv("COMFYUI_BASE_URL", "") From ff0139881212d636232880f7b5bf1656104f0e0d Mon Sep 17 00:00:00 2001 From: Self Denial Date: Wed, 10 Apr 2024 23:39:11 -0600 Subject: [PATCH 04/23] Format fix --- backend/apps/images/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/apps/images/main.py b/backend/apps/images/main.py index bf312598..271928f0 100644 --- a/backend/apps/images/main.py +++ b/backend/apps/images/main.py @@ -29,7 +29,13 @@ import base64 import json import logging -from config import SRC_LOG_LEVELS, CACHE_DIR, IMAGE_GENERATION_ENABLED, AUTOMATIC1111_BASE_URL, COMFYUI_BASE_URL +from config import ( + SRC_LOG_LEVELS, + CACHE_DIR, + IMAGE_GENERATION_ENABLED, + AUTOMATIC1111_BASE_URL, + COMFYUI_BASE_URL, +) log = logging.getLogger(__name__) From 872ea83c50a38cacea30c77cd0e64ea67f36d2aa Mon Sep 17 00:00:00 2001 From: tabacoWang <7a6ac0@users.noreply.github.com> Date: Tue, 2 Apr 2024 18:22:56 +0800 Subject: [PATCH 05/23] feat: admin panel user list pagination --- src/lib/components/common/Paginator.svelte | 254 +++++++++++++++++++++ src/routes/(app)/admin/+page.svelte | 18 +- 2 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 src/lib/components/common/Paginator.svelte diff --git a/src/lib/components/common/Paginator.svelte b/src/lib/components/common/Paginator.svelte new file mode 100644 index 00000000..dd5c5296 --- /dev/null +++ b/src/lib/components/common/Paginator.svelte @@ -0,0 +1,254 @@ + + +
+ + {#if settings.amounts.length} + + {/if} + +
+ + {#if showFirstLastButtons} + + {/if} + + {#if showPreviousNextButtons} + + {/if} + + {#if showNumerals === false} + + + {:else} + + {#each controlPages as page} + + {/each} + {/if} + + {#if showPreviousNextButtons} + + {/if} + + {#if showFirstLastButtons} + + {/if} +
+
diff --git a/src/routes/(app)/admin/+page.svelte b/src/routes/(app)/admin/+page.svelte index a90b3262..92a8315b 100644 --- a/src/routes/(app)/admin/+page.svelte +++ b/src/routes/(app)/admin/+page.svelte @@ -12,6 +12,7 @@ import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths'; import EditUserModal from '$lib/components/admin/EditUserModal.svelte'; import SettingsModal from '$lib/components/admin/SettingsModal.svelte'; + import Paginator from '$lib/components/common/Paginator.svelte'; const i18n = getContext('i18n'); @@ -24,6 +25,13 @@ let showSettingsModal = false; let showEditUserModal = false; + let paginatorSettings = { + page: 0, + limit: 5, + size: users.length, + amounts: [5, 10, 15, 20] + }; + const updateRoleHandler = async (id, role) => { const res = await updateUserRole(localStorage.token, id, role).catch((error) => { toast.error(error); @@ -64,6 +72,13 @@ } loaded = true; }); + + $: paginatedSource = users.slice( + paginatorSettings.page * paginatorSettings.limit, + paginatorSettings.page * paginatorSettings.limit + paginatorSettings.limit + ); + + $: paginatorSettings.size = users.length; @@ -159,7 +174,7 @@ - {#each users.filter((user) => { + {#each paginatedSource.filter((user) => { if (search === '') { return true; } else { @@ -265,6 +280,7 @@ {/each} +
From 8a9cf44dbc2c7c377659dfcbeb39905575edfeea Mon Sep 17 00:00:00 2001 From: tabacoWang <7a6ac0@users.noreply.github.com> Date: Mon, 8 Apr 2024 11:23:20 +0800 Subject: [PATCH 06/23] feat: combine with search result --- src/routes/(app)/admin/+page.svelte | 31 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/routes/(app)/admin/+page.svelte b/src/routes/(app)/admin/+page.svelte index 92a8315b..6d153d8a 100644 --- a/src/routes/(app)/admin/+page.svelte +++ b/src/routes/(app)/admin/+page.svelte @@ -73,10 +73,20 @@ loaded = true; }); - $: paginatedSource = users.slice( - paginatorSettings.page * paginatorSettings.limit, - paginatorSettings.page * paginatorSettings.limit + paginatorSettings.limit - ); + $: paginatedSource = users + .filter((user) => { + if (search === '') { + return true; + } else { + let name = user.name.toLowerCase(); + const query = search.toLowerCase(); + return name.includes(query); + } + }) + .slice( + paginatorSettings.page * paginatorSettings.limit, + paginatorSettings.page * paginatorSettings.limit + paginatorSettings.limit + ); $: paginatorSettings.size = users.length; @@ -174,15 +184,7 @@ - {#each paginatedSource.filter((user) => { - if (search === '') { - return true; - } else { - let name = user.name.toLowerCase(); - const query = search.toLowerCase(); - return name.includes(query); - } - }) as user} + {#each paginatedSource as user}
ⓘ {$i18n.t("Click on the user role button to change a user's role.")}
+ + From e17d66eb61bd62ec711c82a291cea05a9f006d6f Mon Sep 17 00:00:00 2001 From: Que Nguyen Date: Fri, 12 Apr 2024 09:44:40 +0700 Subject: [PATCH 07/23] Update locales/vi-VN/translation.json Fixed translation errors in Vietnamese locale file `locales/vi-VN/translation.json` --- src/lib/i18n/locales/vi-VN/translation.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/i18n/locales/vi-VN/translation.json b/src/lib/i18n/locales/vi-VN/translation.json index 1ef7fef8..36ad86ab 100644 --- a/src/lib/i18n/locales/vi-VN/translation.json +++ b/src/lib/i18n/locales/vi-VN/translation.json @@ -55,9 +55,9 @@ "Check for updates": "Kiểm tra cập nhật", "Checking for updates...": "Đang kiểm tra cập nhật...", "Choose a model before saving...": "Chọn mô hình trước khi lưu...", - "Chunk Overlap": "Kích thước chồng lấn (overlap)", + "Chunk Overlap": "Chồng lấn (overlap)", "Chunk Params": "Cài đặt số lượng ký tự cho khối ký tự (chunk)", - "Chunk Size": "Kích thức khối (size)", + "Chunk Size": "Kích thước khối (size)", "Click here for help.": "Bấm vào đây để được trợ giúp.", "Click here to check other modelfiles.": "Bấm vào đây để kiểm tra các tệp mô tả mô hình (modelfiles) khác.", "Click here to select": "Bấm vào đây để chọn", @@ -65,7 +65,7 @@ "click here.": "bấm vào đây.", "Click on the user role button to change a user's role.": "Bấm vào nút trong cột VAI TRÒ để thay đổi quyền của người sử dụng.", "Close": "Đóng", - "Collection": "Bộ sưu tập", + "Collection": "Tổng hợp mọi tài liệu", "Command": "Lệnh", "Confirm Password": "Xác nhận Mật khẩu", "Connections": "Kết nối", @@ -76,7 +76,7 @@ "Copy last response": "Sao chép phản hồi cuối cùng", "Copying to clipboard was successful!": "Sao chép vào clipboard thành công!", "Create a concise, 3-5 word phrase as a header for the following query, strictly adhering to the 3-5 word limit and avoiding the use of the word 'title':": "Tạo một cụm từ súc tích, 3-5 từ làm tiêu đề cho truy vấn sau, tuân thủ nghiêm ngặt giới hạn 3-5 từ và tránh sử dụng từ 'tiêu đề':", - "Create a modelfile": "Tạo tệp mô tả mô hình", + "Create a modelfile": "Tạo tệp mô tả cho mô hình", "Create Account": "Tạo Tài khoản", "Created at": "Được tạo vào lúc", "Created by": "Được tạo bởi", @@ -347,7 +347,7 @@ "Valid time units:": "Đơn vị thời gian hợp lệ:", "variable": "biến", "variable to have them replaced with clipboard content.": "biến để có chúng được thay thế bằng nội dung clipboard.", - "Version": "Phiên bản", + "Version": "Version", "Web": "Web", "WebUI Add-ons": "Tiện ích WebUI", "WebUI Settings": "Cài đặt WebUI", From 922628c1ee21cb1ae601aa1eca43bdbc3be156d6 Mon Sep 17 00:00:00 2001 From: Self Denial Date: Sat, 13 Apr 2024 03:04:11 -0600 Subject: [PATCH 08/23] feat: small change to support ollama pull QOL Use regex replace during trim "sanitize" to support `ollama run ` or `ollama pull ` syntax. --- src/lib/components/chat/Settings/Models.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/chat/Settings/Models.svelte b/src/lib/components/chat/Settings/Models.svelte index baa2f6c4..15b05402 100644 --- a/src/lib/components/chat/Settings/Models.svelte +++ b/src/lib/components/chat/Settings/Models.svelte @@ -139,7 +139,7 @@ }; const pullModelHandler = async () => { - const sanitizedModelTag = modelTag.trim(); + const sanitizedModelTag = modelTag.trim().replace(/^ollama\s+(run|pull)\s+/, ''); if (modelDownloadStatus[sanitizedModelTag]) { toast.error( $i18n.t(`Model '{{modelTag}}' is already in queue for downloading.`, { From faa58841508c181a08e816c1a90d487910adf20c Mon Sep 17 00:00:00 2001 From: Self Denial Date: Sat, 13 Apr 2024 03:18:13 -0600 Subject: [PATCH 09/23] Use log.warning instead of log.debug --- backend/apps/audio/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/apps/audio/main.py b/backend/apps/audio/main.py index 0111ebaf..f93b50f6 100644 --- a/backend/apps/audio/main.py +++ b/backend/apps/audio/main.py @@ -83,7 +83,7 @@ def transcribe( try: model = WhisperModel(**whisper_kwargs) except: - log.debug( + log.warning( "WhisperModel initialization failed, attempting download with local_files_only=False" ) whisper_kwargs["local_files_only"] = False From 838778aa3e6b1166f3b217c07e5ef7cfd3b2cbab Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 13 Apr 2024 14:40:54 -0700 Subject: [PATCH 10/23] fix: typo --- backend/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/config.py b/backend/config.py index cb4aca75..311a9f05 100644 --- a/backend/config.py +++ b/backend/config.py @@ -413,7 +413,7 @@ RAG_EMBEDDING_MODEL_AUTO_UPDATE = ( ) -# device type embbeding models - "cpu" (default), "cuda" (nvidia gpu required) or "mps" (apple silicon) - choosing this right can lead to better performance +# device type embedding models - "cpu" (default), "cuda" (nvidia gpu required) or "mps" (apple silicon) - choosing this right can lead to better performance USE_CUDA = os.environ.get("USE_CUDA_DOCKER", "false") if USE_CUDA.lower() == "true": From 2649d29a3ef455e8180aee6c05b0cba2f62ef2bd Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 13 Apr 2024 14:42:38 -0700 Subject: [PATCH 11/23] fix: manifest.json issue --- src/app.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.html b/src/app.html index f731761c..2d1ef0d1 100644 --- a/src/app.html +++ b/src/app.html @@ -3,7 +3,7 @@ - + + +
+ +
+ + + +
+ {#each pages as page (page.key)} + {#if page.type === 'ellipsis'} +
...
+ {:else} + + {page.value} + + {/if} + {/each} +
+ + + +
+
+
diff --git a/src/lib/components/common/Paginator.svelte b/src/lib/components/common/Paginator.svelte deleted file mode 100644 index dd5c5296..00000000 --- a/src/lib/components/common/Paginator.svelte +++ /dev/null @@ -1,254 +0,0 @@ - - -
- - {#if settings.amounts.length} - - {/if} - -
- - {#if showFirstLastButtons} - - {/if} - - {#if showPreviousNextButtons} - - {/if} - - {#if showNumerals === false} - - - {:else} - - {#each controlPages as page} - - {/each} - {/if} - - {#if showPreviousNextButtons} - - {/if} - - {#if showFirstLastButtons} - - {/if} -
-
diff --git a/src/lib/components/icons/ChevronLeft.svelte b/src/lib/components/icons/ChevronLeft.svelte new file mode 100644 index 00000000..78ee64d2 --- /dev/null +++ b/src/lib/components/icons/ChevronLeft.svelte @@ -0,0 +1,15 @@ + + + + + diff --git a/src/lib/components/icons/ChevronRight.svelte b/src/lib/components/icons/ChevronRight.svelte new file mode 100644 index 00000000..7daf4a14 --- /dev/null +++ b/src/lib/components/icons/ChevronRight.svelte @@ -0,0 +1,15 @@ + + + + + diff --git a/src/routes/(app)/admin/+page.svelte b/src/routes/(app)/admin/+page.svelte index 6d153d8a..a3493cb6 100644 --- a/src/routes/(app)/admin/+page.svelte +++ b/src/routes/(app)/admin/+page.svelte @@ -12,7 +12,7 @@ import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths'; import EditUserModal from '$lib/components/admin/EditUserModal.svelte'; import SettingsModal from '$lib/components/admin/SettingsModal.svelte'; - import Paginator from '$lib/components/common/Paginator.svelte'; + import Pagination from '$lib/components/common/Pagination.svelte'; const i18n = getContext('i18n'); @@ -22,16 +22,11 @@ let search = ''; let selectedUser = null; + let page = 1; + let showSettingsModal = false; let showEditUserModal = false; - let paginatorSettings = { - page: 0, - limit: 5, - size: users.length, - amounts: [5, 10, 15, 20] - }; - const updateRoleHandler = async (id, role) => { const res = await updateUserRole(localStorage.token, id, role).catch((error) => { toast.error(error); @@ -72,23 +67,6 @@ } loaded = true; }); - - $: paginatedSource = users - .filter((user) => { - if (search === '') { - return true; - } else { - let name = user.name.toLowerCase(); - const query = search.toLowerCase(); - return name.includes(query); - } - }) - .slice( - paginatorSettings.page * paginatorSettings.limit, - paginatorSettings.page * paginatorSettings.limit + paginatorSettings.limit - ); - - $: paginatorSettings.size = users.length; @@ -184,7 +162,17 @@ - {#each paginatedSource as user} + {#each users + .filter((user) => { + if (search === '') { + return true; + } else { + let name = user.name.toLowerCase(); + const query = search.toLowerCase(); + return name.includes(query); + } + }) + .slice((page - 1) * 20, page * 20) as user}