From c47eddce3275bf29430e0be75fa8e654e496f538 Mon Sep 17 00:00:00 2001 From: "Nacho G. Mac Dowell" Date: Thu, 13 Feb 2025 16:28:39 +0100 Subject: [PATCH] Optional title generation The boolean configuration var ENABLE_TITLE_GENERATION makes title generation optionaL --- backend/open_webui/config.py | 6 +++ backend/open_webui/main.py | 2 + backend/open_webui/routers/tasks.py | 11 ++++++ .../admin/Settings/Interface.svelte | 39 +++++++++++++------ src/lib/i18n/locales/ar-BH/translation.json | 2 + src/lib/i18n/locales/bg-BG/translation.json | 2 + src/lib/i18n/locales/bn-BD/translation.json | 2 + src/lib/i18n/locales/ceb-PH/translation.json | 2 + src/lib/i18n/locales/cs-CZ/translation.json | 2 + src/lib/i18n/locales/da-DK/translation.json | 2 + src/lib/i18n/locales/dg-DG/translation.json | 2 + src/lib/i18n/locales/el-GR/translation.json | 2 + src/lib/i18n/locales/en-GB/translation.json | 2 + src/lib/i18n/locales/en-US/translation.json | 2 + src/lib/i18n/locales/eu-ES/translation.json | 2 + src/lib/i18n/locales/fa-IR/translation.json | 2 + src/lib/i18n/locales/fr-CA/translation.json | 2 + src/lib/i18n/locales/he-IL/translation.json | 2 + src/lib/i18n/locales/hi-IN/translation.json | 2 + src/lib/i18n/locales/hr-HR/translation.json | 2 + src/lib/i18n/locales/hu-HU/translation.json | 2 + src/lib/i18n/locales/id-ID/translation.json | 2 + src/lib/i18n/locales/it-IT/translation.json | 2 + src/lib/i18n/locales/ja-JP/translation.json | 2 + src/lib/i18n/locales/ka-GE/translation.json | 2 + src/lib/i18n/locales/ko-KR/translation.json | 1 + src/lib/i18n/locales/lt-LT/translation.json | 2 + src/lib/i18n/locales/ms-MY/translation.json | 2 + src/lib/i18n/locales/nb-NO/translation.json | 1 + src/lib/i18n/locales/nl-NL/translation.json | 2 + src/lib/i18n/locales/pa-IN/translation.json | 2 + src/lib/i18n/locales/pl-PL/translation.json | 2 + src/lib/i18n/locales/pt-BR/translation.json | 2 + src/lib/i18n/locales/pt-PT/translation.json | 2 + src/lib/i18n/locales/ro-RO/translation.json | 2 + src/lib/i18n/locales/ru-RU/translation.json | 1 + src/lib/i18n/locales/sk-SK/translation.json | 2 + src/lib/i18n/locales/sr-RS/translation.json | 1 + src/lib/i18n/locales/sv-SE/translation.json | 2 + src/lib/i18n/locales/th-TH/translation.json | 2 + src/lib/i18n/locales/tk-TW/translation.json | 2 + src/lib/i18n/locales/ur-PK/translation.json | 2 + src/lib/i18n/locales/vi-VN/translation.json | 2 + 43 files changed, 120 insertions(+), 12 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index ff298dc5b..e087110fe 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -1190,6 +1190,12 @@ ENABLE_TAGS_GENERATION = PersistentConfig( os.environ.get("ENABLE_TAGS_GENERATION", "True").lower() == "true", ) +ENABLE_TITLE_GENERATION = PersistentConfig( + "ENABLE_TITLE_GENERATION", + "task.title.enable", + os.environ.get("ENABLE_TITLE_GENERATION", "True").lower() == "true", +) + ENABLE_SEARCH_QUERY_GENERATION = PersistentConfig( "ENABLE_SEARCH_QUERY_GENERATION", diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 88b5b3f69..a69221d78 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -264,6 +264,7 @@ from open_webui.config import ( TASK_MODEL, TASK_MODEL_EXTERNAL, ENABLE_TAGS_GENERATION, + ENABLE_TITLE_GENERATION, ENABLE_SEARCH_QUERY_GENERATION, ENABLE_RETRIEVAL_QUERY_GENERATION, ENABLE_AUTOCOMPLETE_GENERATION, @@ -689,6 +690,7 @@ app.state.config.ENABLE_SEARCH_QUERY_GENERATION = ENABLE_SEARCH_QUERY_GENERATION app.state.config.ENABLE_RETRIEVAL_QUERY_GENERATION = ENABLE_RETRIEVAL_QUERY_GENERATION app.state.config.ENABLE_AUTOCOMPLETE_GENERATION = ENABLE_AUTOCOMPLETE_GENERATION app.state.config.ENABLE_TAGS_GENERATION = ENABLE_TAGS_GENERATION +app.state.config.ENABLE_TITLE_GENERATION = ENABLE_TITLE_GENERATION app.state.config.TITLE_GENERATION_PROMPT_TEMPLATE = TITLE_GENERATION_PROMPT_TEMPLATE diff --git a/backend/open_webui/routers/tasks.py b/backend/open_webui/routers/tasks.py index 91ec8e972..f6dcffc23 100644 --- a/backend/open_webui/routers/tasks.py +++ b/backend/open_webui/routers/tasks.py @@ -58,6 +58,7 @@ async def get_task_config(request: Request, user=Depends(get_verified_user)): "AUTOCOMPLETE_GENERATION_INPUT_MAX_LENGTH": request.app.state.config.AUTOCOMPLETE_GENERATION_INPUT_MAX_LENGTH, "TAGS_GENERATION_PROMPT_TEMPLATE": request.app.state.config.TAGS_GENERATION_PROMPT_TEMPLATE, "ENABLE_TAGS_GENERATION": request.app.state.config.ENABLE_TAGS_GENERATION, + "ENABLE_TITLE_GENERATION": request.app.state.config.ENABLE_TITLE_GENERATION, "ENABLE_SEARCH_QUERY_GENERATION": request.app.state.config.ENABLE_SEARCH_QUERY_GENERATION, "ENABLE_RETRIEVAL_QUERY_GENERATION": request.app.state.config.ENABLE_RETRIEVAL_QUERY_GENERATION, "QUERY_GENERATION_PROMPT_TEMPLATE": request.app.state.config.QUERY_GENERATION_PROMPT_TEMPLATE, @@ -68,6 +69,7 @@ async def get_task_config(request: Request, user=Depends(get_verified_user)): class TaskConfigForm(BaseModel): TASK_MODEL: Optional[str] TASK_MODEL_EXTERNAL: Optional[str] + ENABLE_TITLE_GENERATION: bool TITLE_GENERATION_PROMPT_TEMPLATE: str IMAGE_PROMPT_GENERATION_PROMPT_TEMPLATE: str ENABLE_AUTOCOMPLETE_GENERATION: bool @@ -86,6 +88,7 @@ async def update_task_config( ): request.app.state.config.TASK_MODEL = form_data.TASK_MODEL request.app.state.config.TASK_MODEL_EXTERNAL = form_data.TASK_MODEL_EXTERNAL + request.app.state.config.ENABLE_TITLE_GENERATION = form_data.ENABLE_TITLE_GENERATION request.app.state.config.TITLE_GENERATION_PROMPT_TEMPLATE = ( form_data.TITLE_GENERATION_PROMPT_TEMPLATE ) @@ -122,6 +125,7 @@ async def update_task_config( return { "TASK_MODEL": request.app.state.config.TASK_MODEL, "TASK_MODEL_EXTERNAL": request.app.state.config.TASK_MODEL_EXTERNAL, + "ENABLE_TITLE_GENERATION": request.app.state.config.ENABLE_TITLE_GENERATION, "TITLE_GENERATION_PROMPT_TEMPLATE": request.app.state.config.TITLE_GENERATION_PROMPT_TEMPLATE, "IMAGE_PROMPT_GENERATION_PROMPT_TEMPLATE": request.app.state.config.IMAGE_PROMPT_GENERATION_PROMPT_TEMPLATE, "ENABLE_AUTOCOMPLETE_GENERATION": request.app.state.config.ENABLE_AUTOCOMPLETE_GENERATION, @@ -139,6 +143,13 @@ async def update_task_config( async def generate_title( request: Request, form_data: dict, user=Depends(get_verified_user) ): + + if not request.app.state.config.ENABLE_TITLE_GENERATION: + return JSONResponse( + status_code=status.HTTP_200_OK, + content={"detail": "Title generation is disabled"}, + ) + if getattr(request.state, "direct", False) and hasattr(request.state, "model"): models = { request.state.model["id"]: request.state.model, diff --git a/src/lib/components/admin/Settings/Interface.svelte b/src/lib/components/admin/Settings/Interface.svelte index 332d02c5a..ad99bbe66 100644 --- a/src/lib/components/admin/Settings/Interface.svelte +++ b/src/lib/components/admin/Settings/Interface.svelte @@ -23,6 +23,7 @@ let taskConfig = { TASK_MODEL: '', TASK_MODEL_EXTERNAL: '', + ENABLE_TITLE_GENERATION: true, TITLE_GENERATION_PROMPT_TEMPLATE: '', IMAGE_PROMPT_GENERATION_PROMPT_TEMPLATE: '', ENABLE_AUTOCOMPLETE_GENERATION: true, @@ -126,22 +127,36 @@ -
-
{$i18n.t('Title Generation Prompt')}
+
- -