diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 9d1bd72d8..ee96a072a 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -904,6 +904,12 @@ TAGS_GENERATION_PROMPT_TEMPLATE = PersistentConfig( os.environ.get("TAGS_GENERATION_PROMPT_TEMPLATE", ""), ) +ENABLE_TAGS_GENERATION = PersistentConfig( + "ENABLE_TAGS_GENERATION", + "task.tags.enable", + os.environ.get("ENABLE_TAGS_GENERATION", "True").lower() == "true", +) + ENABLE_SEARCH_QUERY = PersistentConfig( "ENABLE_SEARCH_QUERY", "task.search.enable", diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 35f707328..3fa4b6233 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -73,6 +73,7 @@ from open_webui.config import ( ENABLE_MODEL_FILTER, ENABLE_OLLAMA_API, ENABLE_OPENAI_API, + ENABLE_TAGS_GENERATION, ENV, FRONTEND_BUILD_DIR, MODEL_FILTER_LIST, @@ -199,6 +200,7 @@ app.state.config.TASK_MODEL = TASK_MODEL app.state.config.TASK_MODEL_EXTERNAL = TASK_MODEL_EXTERNAL app.state.config.TITLE_GENERATION_PROMPT_TEMPLATE = TITLE_GENERATION_PROMPT_TEMPLATE app.state.config.TAGS_GENERATION_PROMPT_TEMPLATE = TAGS_GENERATION_PROMPT_TEMPLATE +app.state.config.ENABLE_TAGS_GENERATION = ENABLE_TAGS_GENERATION app.state.config.SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE = ( SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE ) @@ -1473,6 +1475,7 @@ async def get_task_config(user=Depends(get_verified_user)): "TASK_MODEL_EXTERNAL": app.state.config.TASK_MODEL_EXTERNAL, "TITLE_GENERATION_PROMPT_TEMPLATE": app.state.config.TITLE_GENERATION_PROMPT_TEMPLATE, "TAGS_GENERATION_PROMPT_TEMPLATE": app.state.config.TAGS_GENERATION_PROMPT_TEMPLATE, + "ENABLE_TAGS_GENERATION": app.state.config.ENABLE_TAGS_GENERATION, "ENABLE_SEARCH_QUERY": app.state.config.ENABLE_SEARCH_QUERY, "SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE": app.state.config.SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE, "TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE": app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE, @@ -1484,6 +1487,7 @@ class TaskConfigForm(BaseModel): TASK_MODEL_EXTERNAL: Optional[str] TITLE_GENERATION_PROMPT_TEMPLATE: str TAGS_GENERATION_PROMPT_TEMPLATE: str + ENABLE_TAGS_GENERATION: bool SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE: str ENABLE_SEARCH_QUERY: bool TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE: str @@ -1499,6 +1503,7 @@ async def update_task_config(form_data: TaskConfigForm, user=Depends(get_admin_u app.state.config.TAGS_GENERATION_PROMPT_TEMPLATE = ( form_data.TAGS_GENERATION_PROMPT_TEMPLATE ) + app.state.config.ENABLE_TAGS_GENERATION = form_data.ENABLE_TAGS_GENERATION app.state.config.SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE = ( form_data.SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE @@ -1513,6 +1518,7 @@ async def update_task_config(form_data: TaskConfigForm, user=Depends(get_admin_u "TASK_MODEL_EXTERNAL": app.state.config.TASK_MODEL_EXTERNAL, "TITLE_GENERATION_PROMPT_TEMPLATE": app.state.config.TITLE_GENERATION_PROMPT_TEMPLATE, "TAGS_GENERATION_PROMPT_TEMPLATE": app.state.config.TAGS_GENERATION_PROMPT_TEMPLATE, + "ENABLE_TAGS_GENERATION": app.state.config.ENABLE_TAGS_GENERATION, "SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE": app.state.config.SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE, "ENABLE_SEARCH_QUERY": app.state.config.ENABLE_SEARCH_QUERY, "TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE": app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE, @@ -1602,6 +1608,12 @@ Artificial Intelligence in Healthcare @app.post("/api/task/tags/completions") async def generate_chat_tags(form_data: dict, user=Depends(get_verified_user)): print("generate_chat_tags") + if not app.state.config.ENABLE_TAGS_GENERATION: + return JSONResponse( + status_code=status.HTTP_200_OK, + content={"detail": "Tags generation is disabled"}, + ) + model_id = form_data["model"] if model_id not in app.state.MODELS: raise HTTPException( diff --git a/src/lib/components/admin/Settings/Interface.svelte b/src/lib/components/admin/Settings/Interface.svelte index 54819ed9e..aafa3ed05 100644 --- a/src/lib/components/admin/Settings/Interface.svelte +++ b/src/lib/components/admin/Settings/Interface.svelte @@ -25,6 +25,7 @@ TASK_MODEL_EXTERNAL: '', TITLE_GENERATION_PROMPT_TEMPLATE: '', TAGS_GENERATION_PROMPT_TEMPLATE: '', + ENABLE_TAGS_GENERATION: true, ENABLE_SEARCH_QUERY: true, SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE: '' }; @@ -133,20 +134,32 @@ -