From 62f67bed292ae27fec9e63e1ead1c80355319d4b Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 23 Feb 2024 17:12:19 -0800 Subject: [PATCH] feat: sponsor custom name support --- backend/config.py | 39 ++++++++++++++++-- backend/main.py | 6 ++- backend/static/favicon.png | Bin 0 -> 6161 bytes src/lib/components/ChangelogModal.svelte | 8 ++-- .../chat/Messages/Placeholder.svelte | 7 +++- .../chat/Messages/ResponseMessage.svelte | 4 +- src/lib/components/chat/Settings/About.svelte | 8 ++-- .../components/chat/Settings/Models.svelte | 8 ++-- src/lib/components/layout/Navbar.svelte | 7 ++-- src/lib/components/layout/Sidebar.svelte | 7 +++- src/lib/constants.ts | 4 +- src/lib/stores/index.ts | 2 + src/routes/(app)/+page.svelte | 9 ++-- src/routes/(app)/c/[id]/+page.svelte | 5 ++- src/routes/+layout.svelte | 9 ++-- src/routes/auth/+page.svelte | 10 ++--- src/routes/error/+page.svelte | 5 +-- 17 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 backend/static/favicon.png diff --git a/backend/config.py b/backend/config.py index d7c9414f..f630fa94 100644 --- a/backend/config.py +++ b/backend/config.py @@ -1,13 +1,17 @@ import os import chromadb from chromadb import Settings -from secrets import token_bytes from base64 import b64encode -from constants import ERROR_MESSAGES +from bs4 import BeautifulSoup + from pathlib import Path import json import markdown -from bs4 import BeautifulSoup +import requests +import shutil + +from secrets import token_bytes +from constants import ERROR_MESSAGES try: @@ -17,6 +21,8 @@ try: except ImportError: print("dotenv not installed, skipping...") +WEBUI_NAME = "Open WebUI" + #################################### # ENV (dev,test,prod) @@ -24,7 +30,6 @@ except ImportError: ENV = os.environ.get("ENV", "dev") - try: with open(f"../package.json", "r") as f: PACKAGE_DATA = json.load(f) @@ -94,6 +99,32 @@ for version in soup.find_all("h2"): CHANGELOG = changelog_json + +#################################### +# CUSTOM_NAME +#################################### + +CUSTOM_NAME = os.environ.get("CUSTOM_NAME", "") +if CUSTOM_NAME: + r = requests.get(f"https://api.openwebui.com/api/v1/custom/{CUSTOM_NAME}") + data = r.json() + + if "logo" in data: + url = ( + f"https://api.openwebui.com{data['logo']}" + if data["logo"][0] == "/" + else data["logo"] + ) + + r = requests.get(url, stream=True) + if r.status_code == 200: + with open("./static/favicon.png", "wb") as f: + r.raw.decode_content = True + shutil.copyfileobj(r.raw, f) + + WEBUI_NAME = data["name"] + + #################################### # DATA/FRONTEND BUILD DIR #################################### diff --git a/backend/main.py b/backend/main.py index 8a9b9dce..0be56752 100644 --- a/backend/main.py +++ b/backend/main.py @@ -20,7 +20,7 @@ from apps.rag.main import app as rag_app from apps.web.main import app as webui_app -from config import ENV, VERSION, CHANGELOG, FRONTEND_BUILD_DIR +from config import WEBUI_NAME, ENV, VERSION, CHANGELOG, FRONTEND_BUILD_DIR class SPAStaticFiles(StaticFiles): @@ -72,6 +72,7 @@ async def get_app_config(): return { "status": True, + "name": WEBUI_NAME, "version": VERSION, "images": images_app.state.ENABLED, "default_models": webui_app.state.DEFAULT_MODELS, @@ -84,6 +85,9 @@ async def get_app_changelog(): return CHANGELOG +app.mount("/static", StaticFiles(directory="static"), name="static") + + app.mount( "/", SPAStaticFiles(directory=FRONTEND_BUILD_DIR, html=True), diff --git a/backend/static/favicon.png b/backend/static/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..519af1db620dbf4de3694660dae7abd7392f0b3c GIT binary patch literal 6161 zcmeHLc~p|yyGEmwIyrGYmN}H;sZ7c`4u~3N4yjnFDP@|b$1>*`2Q01QPt8nCjTEFT zNh?jw6cvZG98kn5D#x5aQBc4EM7`L$cinr}UH6as|M_FDZ|(Pe_q+FgzWsjBv%i#! z2&?^j754%Ffc-Ys7MB44G2Tv-+#|A(zmBJh9-v@rWEcRj54_XF0M7~zh>T)km#xeJ zWfY}3Q3vP?w}%4&6&d@4p1T16g<=~ExKp&);^<ANhuv)Xl$tys&ZRsJ`1`r9ys$S(fVdZeKcl;htZ>{_w)oWN@&7#z6T_fA9GXXheZuzUT6kO> z3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~p!_-W;bz!c@L4pgI>ksrD5 z^S`z~E`jA;_s_bo2*mC?^)AB`*A?*aJ`{+xJ@szwNr~`#m2YwAAJ$aj2h`PGM6|@V zpfbtCtao#B6ZG1ON~~PCzs6$LRW_KiZ$zc34Qevn((D+R!P7rMvHQ8heVmFU<#}*; z*^p8s?FQ}67zvjRIg)G(7LSligB3qr9FORgRa8!GV<5?$CDsOa`(?lGMOq;)>m zhWj3$O%K!W4RAo&%l{aNiJaXhX@Sm)tTx))%R~9+{Z)l&~7TCFJvXa|1oJrY*spNh~nd*Vh+n zX!s4*XWx7egRi=P)WhYagI9`*ih5{MQ&YFkq(n}VYHDiuxPKWg86{HYv5#VlR|f8F ziwKbrID0fsbaPBsa$1#=%f}Ceceb zN-b3UWW%p^w&7mWtG;yj7M@MSmWMS5h$|)STo18FG#0q@o_quLb^-Vs_6*oW=M9_h|Bv3-FSgyFU+y_*M3wVTvcc&+w&&qd-&MQ7K4S6BZ_ nZvA8UpYrn`JpNBSmbPOCTRwQJXvm2E-~(*VBP`0yZzTRZFN9iO literal 0 HcmV?d00001 diff --git a/src/lib/components/ChangelogModal.svelte b/src/lib/components/ChangelogModal.svelte index 00c12a39..0cf1f006 100644 --- a/src/lib/components/ChangelogModal.svelte +++ b/src/lib/components/ChangelogModal.svelte @@ -2,9 +2,9 @@ import { onMount } from 'svelte'; import { Confetti } from 'svelte-confetti'; - import { config } from '$lib/stores'; + import { WEBUI_NAME, config } from '$lib/stores'; - import { WEBUI_NAME, WEB_UI_VERSION } from '$lib/constants'; + import { WEBUI_VERSION } from '$lib/constants'; import { getChangelog } from '$lib/apis'; import Modal from './common/Modal.svelte'; @@ -23,7 +23,7 @@
- What’s New in {WEBUI_NAME} + What’s New in {$WEBUI_NAME}
- v{WEB_UI_VERSION} + v{WEBUI_VERSION}
diff --git a/src/lib/components/chat/Messages/Placeholder.svelte b/src/lib/components/chat/Messages/Placeholder.svelte index ae9ced14..f1f3e80a 100644 --- a/src/lib/components/chat/Messages/Placeholder.svelte +++ b/src/lib/components/chat/Messages/Placeholder.svelte @@ -1,4 +1,5 @@ - {WEBUI_NAME} + {$WEBUI_NAME} + diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index 05891d4f..30c5a93e 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -1,8 +1,8 @@