From 04ddbf43065fd8372c39665730c6a159d6013ff1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 7 Mar 2024 11:07:27 -0800 Subject: [PATCH 01/24] fix: button click issue --- src/lib/components/chat/Settings/Account.svelte | 4 +++- src/lib/components/chat/Settings/Chats.svelte | 4 +++- src/lib/components/chat/Settings/Models.svelte | 4 +++- src/routes/(app)/documents/+page.svelte | 4 +++- src/routes/(app)/modelfiles/+page.svelte | 4 +++- src/routes/(app)/prompts/+page.svelte | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lib/components/chat/Settings/Account.svelte b/src/lib/components/chat/Settings/Account.svelte index 98f4aa17..8aceae18 100644 --- a/src/lib/components/chat/Settings/Account.svelte +++ b/src/lib/components/chat/Settings/Account.svelte @@ -109,7 +109,9 @@ {showLiteLLM ? 'Hide' : 'Show'} -
-
-
- -
- - - +
+ +
+
+
+ - - +
+ + +
+ + {#if showLiteLLMParams} +
+
Model Name
+
+
+ +
+
+
+ +
+
API Base URL
+
+
+ +
+
+
+ +
+
API Key
+
+
+ +
+
+
+ +
+
API RPM
+
+
+ +
+
+
+ +
+
Max Tokens
+
+
+ +
+
+
+ {/if}
- {#if showLiteLLMParams} -
-
Model Name
-
-
- -
-
-
- -
-
API Base URL
-
-
- -
-
-
- -
-
API Key
-
-
- -
-
-
- -
-
API RPM
-
-
- -
-
-
- -
-
Max Tokens
-
-
- -
-
-
- {/if} -
- -
- Not sure what to add? - - Click here for help. - -
- -
-
Delete a model
-
-
- -
- + Click here for help. +
-
+ +
+
Delete a model
+
+
+ +
+ +
+
+ {/if} From 219466374d5dea11e74ca713e5a02dae74a71446 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 9 Mar 2024 01:43:02 -0800 Subject: [PATCH 12/24] feat: model whitelist --- .../components/admin/Settings/Users.svelte | 79 ++++++++++++++++++ .../components/chat/Settings/Models.svelte | 82 ------------------- src/routes/(app)/playground/+page.svelte | 2 +- 3 files changed, 80 insertions(+), 83 deletions(-) diff --git a/src/lib/components/admin/Settings/Users.svelte b/src/lib/components/admin/Settings/Users.svelte index 8a442c51..437e437e 100644 --- a/src/lib/components/admin/Settings/Users.svelte +++ b/src/lib/components/admin/Settings/Users.svelte @@ -1,10 +1,15 @@ @@ -24,6 +32,8 @@ on:submit|preventDefault={async () => { // console.log('submit'); await updateUserPermissions(localStorage.token, permissions); + + await updateModelFilterConfig(localStorage.token, whitelistEnabled, whitelistModels); saveHandler(); }} > From a4ca1fc5c4e417a90416c72032e0b749dbef6703 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 9 Mar 2024 21:47:01 -0800 Subject: [PATCH 18/24] feat: model filter list env var --- backend/apps/ollama/main.py | 8 ++++---- backend/apps/openai/main.py | 14 ++++++++++---- backend/config.py | 5 +++++ backend/main.py | 30 ++++++++++++++++++++++-------- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 532e5523..5ecbaa29 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -15,7 +15,7 @@ import asyncio from apps.web.models.users import Users from constants import ERROR_MESSAGES from utils.utils import decode_token, get_current_user, get_admin_user -from config import OLLAMA_BASE_URLS +from config import OLLAMA_BASE_URLS, MODEL_FILTER_ENABLED, MODEL_FILTER_LIST from typing import Optional, List, Union @@ -30,8 +30,8 @@ app.add_middleware( ) -app.state.MODEL_FILTER_ENABLED = False -app.state.MODEL_LIST = [] +app.state.MODEL_FILTER_ENABLED = MODEL_FILTER_ENABLED +app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST app.state.OLLAMA_BASE_URLS = OLLAMA_BASE_URLS app.state.MODELS = {} @@ -140,7 +140,7 @@ async def get_ollama_tags( if user.role == "user": models["models"] = list( filter( - lambda model: model["name"] in app.state.MODEL_LIST, + lambda model: model["name"] in app.state.MODEL_FILTER_LIST, models["models"], ) ) diff --git a/backend/apps/openai/main.py b/backend/apps/openai/main.py index 546de3d5..e902bea2 100644 --- a/backend/apps/openai/main.py +++ b/backend/apps/openai/main.py @@ -18,7 +18,13 @@ from utils.utils import ( get_verified_user, get_admin_user, ) -from config import OPENAI_API_BASE_URLS, OPENAI_API_KEYS, CACHE_DIR +from config import ( + OPENAI_API_BASE_URLS, + OPENAI_API_KEYS, + CACHE_DIR, + MODEL_FILTER_ENABLED, + MODEL_FILTER_LIST, +) from typing import List, Optional @@ -34,8 +40,8 @@ app.add_middleware( allow_headers=["*"], ) -app.state.MODEL_FILTER_ENABLED = False -app.state.MODEL_LIST = [] +app.state.MODEL_FILTER_ENABLED = MODEL_FILTER_ENABLED +app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST app.state.OPENAI_API_BASE_URLS = OPENAI_API_BASE_URLS app.state.OPENAI_API_KEYS = OPENAI_API_KEYS @@ -198,7 +204,7 @@ async def get_models(url_idx: Optional[int] = None, user=Depends(get_current_use if user.role == "user": models["data"] = list( filter( - lambda model: model["id"] in app.state.MODEL_LIST, + lambda model: model["id"] in app.state.MODEL_FILTER_LIST, models["data"], ) ) diff --git a/backend/config.py b/backend/config.py index 05ed686b..019e44e0 100644 --- a/backend/config.py +++ b/backend/config.py @@ -292,6 +292,11 @@ DEFAULT_USER_ROLE = os.getenv("DEFAULT_USER_ROLE", "pending") USER_PERMISSIONS = {"chat": {"deletion": True}} +MODEL_FILTER_ENABLED = os.environ.get("MODEL_FILTER_ENABLED", False) +MODEL_FILTER_LIST = os.environ.get("MODEL_FILTER_LIST", "") +MODEL_FILTER_LIST = [model.strip() for model in MODEL_FILTER_LIST.split(";")] + + #################################### # WEBUI_VERSION #################################### diff --git a/backend/main.py b/backend/main.py index 07543e7e..c7523ec6 100644 --- a/backend/main.py +++ b/backend/main.py @@ -30,7 +30,15 @@ from typing import List from utils.utils import get_admin_user from apps.rag.utils import query_doc, query_collection, rag_template -from config import WEBUI_NAME, ENV, VERSION, CHANGELOG, FRONTEND_BUILD_DIR +from config import ( + WEBUI_NAME, + ENV, + VERSION, + CHANGELOG, + FRONTEND_BUILD_DIR, + MODEL_FILTER_ENABLED, + MODEL_FILTER_LIST, +) from constants import ERROR_MESSAGES @@ -47,8 +55,8 @@ class SPAStaticFiles(StaticFiles): app = FastAPI(docs_url="/docs" if ENV == "dev" else None, redoc_url=None) -app.state.MODEL_FILTER_ENABLED = False -app.state.MODEL_LIST = [] +app.state.MODEL_FILTER_ENABLED = MODEL_FILTER_ENABLED +app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST origins = ["*"] @@ -222,7 +230,10 @@ async def get_app_config(): @app.get("/api/config/model/filter") async def get_model_filter_config(user=Depends(get_admin_user)): - return {"enabled": app.state.MODEL_FILTER_ENABLED, "models": app.state.MODEL_LIST} + return { + "enabled": app.state.MODEL_FILTER_ENABLED, + "models": app.state.MODEL_FILTER_LIST, + } class ModelFilterConfigForm(BaseModel): @@ -236,15 +247,18 @@ async def get_model_filter_config( ): app.state.MODEL_FILTER_ENABLED = form_data.enabled - app.state.MODEL_LIST = form_data.models + app.state.MODEL_FILTER_LIST = form_data.models ollama_app.state.MODEL_FILTER_ENABLED = app.state.MODEL_FILTER_ENABLED - ollama_app.state.MODEL_LIST = app.state.MODEL_LIST + ollama_app.state.MODEL_FILTER_LIST = app.state.MODEL_FILTER_LIST openai_app.state.MODEL_FILTER_ENABLED = app.state.MODEL_FILTER_ENABLED - openai_app.state.MODEL_LIST = app.state.MODEL_LIST + openai_app.state.MODEL_FILTER_LIST = app.state.MODEL_FILTER_LIST - return {"enabled": app.state.MODEL_FILTER_ENABLED, "models": app.state.MODEL_LIST} + return { + "enabled": app.state.MODEL_FILTER_ENABLED, + "models": app.state.MODEL_FILTER_LIST, + } @app.get("/api/version") From bd84753c6b9a9c4a60c30fcb6e7ac648ed5fca85 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 9 Mar 2024 21:52:19 -0800 Subject: [PATCH 19/24] feat: title auto-generate for openai apis --- src/routes/(app)/+page.svelte | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index bb3668dc..07fcc176 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -675,7 +675,12 @@ if (messages.length == 2) { window.history.replaceState(history.state, '', `/c/${_chatId}`); - await setChatTitle(_chatId, userPrompt); + + if ($settings?.titleAutoGenerateModel) { + await generateChatTitle(_chatId, userPrompt); + } else { + await setChatTitle(_chatId, userPrompt); + } } }; From c6667510c4db3f47db43e99523d6281aa448d0c6 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 9 Mar 2024 21:55:13 -0800 Subject: [PATCH 20/24] refac: confusing icon --- src/lib/components/chat/Settings/Interface.svelte | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/components/chat/Settings/Interface.svelte b/src/lib/components/chat/Settings/Interface.svelte index 39922868..a15ef148 100644 --- a/src/lib/components/chat/Settings/Interface.svelte +++ b/src/lib/components/chat/Settings/Interface.svelte @@ -186,7 +186,7 @@