From c4937cc14421bd807676d3034059872331204fec Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 25 Dec 2024 09:50:57 -0700 Subject: [PATCH] enh: webui url --- backend/open_webui/config.py | 6 +++++ backend/open_webui/env.py | 2 -- backend/open_webui/main.py | 9 ++++---- backend/open_webui/routers/auths.py | 5 ++++ backend/open_webui/routers/channels.py | 15 ++++++++---- backend/open_webui/utils/middleware.py | 5 ++-- .../components/admin/Settings/General.svelte | 23 +++++++++++++++++++ 7 files changed, 51 insertions(+), 14 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 48c623bef..e6e66f34a 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -720,6 +720,12 @@ OPENAI_API_BASE_URL = "https://api.openai.com/v1" # WEBUI #################################### + +WEBUI_URL = PersistentConfig( + "WEBUI_URL", "webui.url", os.environ.get("WEBUI_URL", "http://localhost:3000") +) + + ENABLE_SIGNUP = PersistentConfig( "ENABLE_SIGNUP", "ui.enable_signup", diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 0fd6080de..a5f848b62 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -103,8 +103,6 @@ WEBUI_NAME = os.environ.get("WEBUI_NAME", "Open WebUI") if WEBUI_NAME != "Open WebUI": WEBUI_NAME += " (Open WebUI)" -WEBUI_URL = os.environ.get("WEBUI_URL", "http://localhost:3000") - WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png" diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 56e967ae4..190102041 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -239,6 +239,7 @@ from open_webui.config import ( CORS_ALLOW_ORIGIN, DEFAULT_LOCALE, OAUTH_PROVIDERS, + WEBUI_URL, # Admin ENABLE_ADMIN_CHAT_ACCESS, ENABLE_ADMIN_EXPORT, @@ -264,7 +265,6 @@ from open_webui.env import ( SAFE_MODE, SRC_LOG_LEVELS, VERSION, - WEBUI_URL, WEBUI_BUILD_HASH, WEBUI_SECRET_KEY, WEBUI_SESSION_COOKIE_SAME_SITE, @@ -389,6 +389,7 @@ app.state.OPENAI_MODELS = {} # ######################################## +app.state.config.WEBUI_URL = WEBUI_URL app.state.config.ENABLE_SIGNUP = ENABLE_SIGNUP app.state.config.ENABLE_LOGIN_FORM = ENABLE_LOGIN_FORM app.state.config.ENABLE_API_KEY = ENABLE_API_KEY @@ -1138,9 +1139,9 @@ async def get_opensearch_xml(): {WEBUI_NAME} Search {WEBUI_NAME} UTF-8 - {WEBUI_URL}/static/favicon.png - - {WEBUI_URL} + {app.state.config.WEBUI_URL}/static/favicon.png + + {app.state.config.WEBUI_URL} """ return Response(content=xml_content, media_type="application/xml") diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index e8739a12c..d7cd8de2c 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -613,6 +613,7 @@ async def get_admin_details(request: Request, user=Depends(get_current_user)): async def get_admin_config(request: Request, user=Depends(get_admin_user)): return { "SHOW_ADMIN_DETAILS": request.app.state.config.SHOW_ADMIN_DETAILS, + "WEBUI_URL": request.app.state.config.WEBUI_URL, "ENABLE_SIGNUP": request.app.state.config.ENABLE_SIGNUP, "ENABLE_API_KEY": request.app.state.config.ENABLE_API_KEY, "ENABLE_CHANNELS": request.app.state.config.ENABLE_CHANNELS, @@ -625,6 +626,7 @@ async def get_admin_config(request: Request, user=Depends(get_admin_user)): class AdminConfig(BaseModel): SHOW_ADMIN_DETAILS: bool + WEBUI_URL: str ENABLE_SIGNUP: bool ENABLE_API_KEY: bool ENABLE_CHANNELS: bool @@ -639,6 +641,7 @@ async def update_admin_config( request: Request, form_data: AdminConfig, user=Depends(get_admin_user) ): request.app.state.config.SHOW_ADMIN_DETAILS = form_data.SHOW_ADMIN_DETAILS + request.app.state.config.WEBUI_URL = form_data.WEBUI_URL request.app.state.config.ENABLE_SIGNUP = form_data.ENABLE_SIGNUP request.app.state.config.ENABLE_API_KEY = form_data.ENABLE_API_KEY request.app.state.config.ENABLE_CHANNELS = form_data.ENABLE_CHANNELS @@ -659,8 +662,10 @@ async def update_admin_config( return { "SHOW_ADMIN_DETAILS": request.app.state.config.SHOW_ADMIN_DETAILS, + "WEBUI_URL": request.app.state.config.WEBUI_URL, "ENABLE_SIGNUP": request.app.state.config.ENABLE_SIGNUP, "ENABLE_API_KEY": request.app.state.config.ENABLE_API_KEY, + "ENABLE_CHANNELS": request.app.state.config.ENABLE_CHANNELS, "DEFAULT_USER_ROLE": request.app.state.config.DEFAULT_USER_ROLE, "JWT_EXPIRES_IN": request.app.state.config.JWT_EXPIRES_IN, "ENABLE_COMMUNITY_SHARING": request.app.state.config.ENABLE_COMMUNITY_SHARING, diff --git a/backend/open_webui/routers/channels.py b/backend/open_webui/routers/channels.py index 5272bd59d..292f33e78 100644 --- a/backend/open_webui/routers/channels.py +++ b/backend/open_webui/routers/channels.py @@ -16,7 +16,7 @@ from open_webui.models.messages import Messages, MessageModel, MessageForm from open_webui.config import ENABLE_ADMIN_CHAT_ACCESS, ENABLE_ADMIN_EXPORT from open_webui.constants import ERROR_MESSAGES -from open_webui.env import SRC_LOG_LEVELS, WEBUI_URL +from open_webui.env import SRC_LOG_LEVELS from open_webui.utils.auth import get_admin_user, get_verified_user @@ -181,7 +181,7 @@ async def get_channel_messages( ############################ -async def send_notification(channel, message, active_user_ids): +async def send_notification(webui_url, channel, message, active_user_ids): users = get_users_with_access("read", channel.access_control) for user in users: @@ -196,18 +196,19 @@ async def send_notification(channel, message, active_user_ids): if webhook_url: post_webhook( webhook_url, - f"#{channel.name} - {WEBUI_URL}/channels/{channel.id}\n\n{message.content}", + f"#{channel.name} - {webui_url}/channels/{channel.id}\n\n{message.content}", { "action": "channel", "message": message.content, "title": channel.name, - "url": f"{WEBUI_URL}/channels/{channel.id}", + "url": f"{webui_url}/channels/{channel.id}", }, ) @router.post("/{id}/messages/post", response_model=Optional[MessageModel]) async def post_new_message( + request: Request, id: str, form_data: MessageForm, background_tasks: BackgroundTasks, @@ -253,7 +254,11 @@ async def post_new_message( active_user_ids = get_user_ids_from_room(f"channel:{channel.id}") background_tasks.add_task( - send_notification, channel, message, active_user_ids + send_notification, + request.app.state.config.WEBUI_URL, + channel, + message, + active_user_ids, ) return MessageModel(**message.model_dump()) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index c055eea21..b818fe540 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -65,7 +65,6 @@ from open_webui.env import ( SRC_LOG_LEVELS, GLOBAL_LOG_LEVEL, BYPASS_MODEL_ACCESS_CONTROL, - WEBUI_URL, ) from open_webui.constants import TASKS @@ -859,12 +858,12 @@ async def process_chat_response( if webhook_url: post_webhook( webhook_url, - f"{title} - {WEBUI_URL}/c/{metadata['chat_id']}\n\n{content}", + f"{title} - {request.app.state.config.WEBUI_URL}/c/{metadata['chat_id']}\n\n{content}", { "action": "chat", "message": content, "title": title, - "url": f"{WEBUI_URL}/c/{metadata['chat_id']}", + "url": f"{request.app.state.config.WEBUI_URL}/c/{metadata['chat_id']}", }, ) diff --git a/src/lib/components/admin/Settings/General.svelte b/src/lib/components/admin/Settings/General.svelte index ce3cfec26..231ddc95d 100644 --- a/src/lib/components/admin/Settings/General.svelte +++ b/src/lib/components/admin/Settings/General.svelte @@ -142,6 +142,29 @@
+
+
+
{$i18n.t('WebUI URL')}
+
+ +
+ +
+ +
+ {$i18n.t( + 'Enter the public URL of your WebUI. This URL will be used to generate links in the notifications.' + )} +
+
+ +
+
{$i18n.t('JWT Expiration')}