From 1349c6049e3c2ec19b4f92e4807c902049003eb9 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 9 Dec 2024 23:39:23 -0800 Subject: [PATCH] fix: BYPASS_MODEL_ACCESS_CONTROL env var --- backend/open_webui/apps/ollama/main.py | 8 ++++++-- backend/open_webui/main.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/apps/ollama/main.py b/backend/open_webui/apps/ollama/main.py index 31ae57fa1..48142fd9f 100644 --- a/backend/open_webui/apps/ollama/main.py +++ b/backend/open_webui/apps/ollama/main.py @@ -432,6 +432,7 @@ async def get_ollama_versions(url_idx: Optional[int] = None): else: return {"version": False} + @app.get("/api/ps") async def get_ollama_loaded_models(user=Depends(get_verified_user)): """ @@ -966,6 +967,9 @@ async def generate_chat_completion( user=Depends(get_verified_user), bypass_filter: Optional[bool] = False, ): + if BYPASS_MODEL_ACCESS_CONTROL: + bypass_filter = True + payload = {**form_data.model_dump(exclude_none=True)} log.debug(f"generate_chat_completion() - 1.payload = {payload}") if "metadata" in payload: @@ -1090,7 +1094,7 @@ async def generate_openai_completion( payload = apply_model_params_to_body_openai(params, payload) # Check if user has access to the model - if user.role == "user" and not BYPASS_MODEL_ACCESS_CONTROL: + if user.role == "user": if not ( user.id == model_info.user_id or has_access( @@ -1163,7 +1167,7 @@ async def generate_openai_chat_completion( payload = apply_model_system_prompt_to_body(params, payload, user) # Check if user has access to the model - if user.role == "user" and not BYPASS_MODEL_ACCESS_CONTROL: + if user.role == "user": if not ( user.id == model_info.user_id or has_access( diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 8f16a33c8..253a7a165 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1265,6 +1265,9 @@ async def get_base_models(user=Depends(get_admin_user)): async def generate_chat_completions( form_data: dict, user=Depends(get_verified_user), bypass_filter: bool = False ): + if BYPASS_MODEL_ACCESS_CONTROL: + bypass_filter = True + model_list = await get_all_models() models = {model["id"]: model for model in model_list}