From dbf7b155399afe9354c4b50523c09b99e24e4407 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 26 Apr 2024 17:17:18 -0400 Subject: [PATCH] refac: naming convention MODEL_FILTER_ENABLED -> ENABLE_MODEL_FILTER --- backend/apps/litellm/main.py | 6 +++--- backend/apps/ollama/main.py | 6 +++--- backend/apps/openai/main.py | 6 +++--- backend/config.py | 6 ++++-- backend/main.py | 16 ++++++++-------- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/backend/apps/litellm/main.py b/backend/apps/litellm/main.py index 119e9107e..547bd80ee 100644 --- a/backend/apps/litellm/main.py +++ b/backend/apps/litellm/main.py @@ -26,7 +26,7 @@ log.setLevel(SRC_LOG_LEVELS["LITELLM"]) from config import ( - MODEL_FILTER_ENABLED, + ENABLE_MODEL_FILTER, MODEL_FILTER_LIST, DATA_DIR, LITELLM_PROXY_PORT, @@ -130,7 +130,7 @@ async def startup_event(): asyncio.create_task(start_litellm_background()) -app.state.MODEL_FILTER_ENABLED = MODEL_FILTER_ENABLED +app.state.ENABLE_MODEL_FILTER = ENABLE_MODEL_FILTER app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST @@ -209,7 +209,7 @@ async def get_models(user=Depends(get_current_user)): data = r.json() - if app.state.MODEL_FILTER_ENABLED: + if app.state.ENABLE_MODEL_FILTER: if user and user.role == "user": data["data"] = list( filter( diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 9258efa66..4ca5c4380 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -36,7 +36,7 @@ from utils.utils import decode_token, get_current_user, get_admin_user from config import ( SRC_LOG_LEVELS, OLLAMA_BASE_URLS, - MODEL_FILTER_ENABLED, + ENABLE_MODEL_FILTER, MODEL_FILTER_LIST, UPLOAD_DIR, ) @@ -55,7 +55,7 @@ app.add_middleware( ) -app.state.MODEL_FILTER_ENABLED = MODEL_FILTER_ENABLED +app.state.ENABLE_MODEL_FILTER = ENABLE_MODEL_FILTER app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST app.state.OLLAMA_BASE_URLS = OLLAMA_BASE_URLS @@ -168,7 +168,7 @@ async def get_ollama_tags( if url_idx == None: models = await get_all_models() - if app.state.MODEL_FILTER_ENABLED: + if app.state.ENABLE_MODEL_FILTER: if user.role == "user": models["models"] = list( filter( diff --git a/backend/apps/openai/main.py b/backend/apps/openai/main.py index 0fbbd365e..d9e378303 100644 --- a/backend/apps/openai/main.py +++ b/backend/apps/openai/main.py @@ -24,7 +24,7 @@ from config import ( OPENAI_API_BASE_URLS, OPENAI_API_KEYS, CACHE_DIR, - MODEL_FILTER_ENABLED, + ENABLE_MODEL_FILTER, MODEL_FILTER_LIST, ) from typing import List, Optional @@ -45,7 +45,7 @@ app.add_middleware( allow_headers=["*"], ) -app.state.MODEL_FILTER_ENABLED = MODEL_FILTER_ENABLED +app.state.ENABLE_MODEL_FILTER = ENABLE_MODEL_FILTER app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST app.state.OPENAI_API_BASE_URLS = OPENAI_API_BASE_URLS @@ -225,7 +225,7 @@ async def get_all_models(): async def get_models(url_idx: Optional[int] = None, user=Depends(get_current_user)): if url_idx == None: models = await get_all_models() - if app.state.MODEL_FILTER_ENABLED: + if app.state.ENABLE_MODEL_FILTER: if user.role == "user": models["data"] = list( filter( diff --git a/backend/config.py b/backend/config.py index d73bedcc7..37433d518 100644 --- a/backend/config.py +++ b/backend/config.py @@ -375,8 +375,7 @@ USER_PERMISSIONS_CHAT_DELETION = ( USER_PERMISSIONS = {"chat": {"deletion": USER_PERMISSIONS_CHAT_DELETION}} - -MODEL_FILTER_ENABLED = os.environ.get("MODEL_FILTER_ENABLED", "False").lower() == "true" +ENABLE_MODEL_FILTER = os.environ.get("ENABLE_MODEL_FILTER", "False").lower() == "true" MODEL_FILTER_LIST = os.environ.get("MODEL_FILTER_LIST", "") MODEL_FILTER_LIST = [model.strip() for model in MODEL_FILTER_LIST.split(";")] @@ -528,6 +527,9 @@ AUDIO_OPENAI_API_KEY = os.getenv("AUDIO_OPENAI_API_KEY", OPENAI_API_KEY) # LiteLLM #################################### + +ENABLE_LITELLM = os.environ.get("ENABLE_LITELLM", "True").lower() == "true" + LITELLM_PROXY_PORT = int(os.getenv("LITELLM_PROXY_PORT", "14365")) if LITELLM_PROXY_PORT < 0 or LITELLM_PROXY_PORT > 65535: raise ValueError("Invalid port number for LITELLM_PROXY_PORT") diff --git a/backend/main.py b/backend/main.py index b0dc3a7fd..2ccc7a8f1 100644 --- a/backend/main.py +++ b/backend/main.py @@ -47,7 +47,7 @@ from config import ( FRONTEND_BUILD_DIR, CACHE_DIR, STATIC_DIR, - MODEL_FILTER_ENABLED, + ENABLE_MODEL_FILTER, MODEL_FILTER_LIST, GLOBAL_LOG_LEVEL, SRC_LOG_LEVELS, @@ -89,7 +89,7 @@ https://github.com/open-webui/open-webui app = FastAPI(docs_url="/docs" if ENV == "dev" else None, redoc_url=None) -app.state.MODEL_FILTER_ENABLED = MODEL_FILTER_ENABLED +app.state.ENABLE_MODEL_FILTER = ENABLE_MODEL_FILTER app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST app.state.WEBHOOK_URL = WEBHOOK_URL @@ -218,7 +218,7 @@ async def get_app_config(): @app.get("/api/config/model/filter") async def get_model_filter_config(user=Depends(get_admin_user)): return { - "enabled": app.state.MODEL_FILTER_ENABLED, + "enabled": app.state.ENABLE_MODEL_FILTER, "models": app.state.MODEL_FILTER_LIST, } @@ -232,20 +232,20 @@ class ModelFilterConfigForm(BaseModel): async def update_model_filter_config( form_data: ModelFilterConfigForm, user=Depends(get_admin_user) ): - app.state.MODEL_FILTER_ENABLED = form_data.enabled + app.state.ENABLE_MODEL_FILTER = form_data.enabled app.state.MODEL_FILTER_LIST = form_data.models - ollama_app.state.MODEL_FILTER_ENABLED = app.state.MODEL_FILTER_ENABLED + ollama_app.state.ENABLE_MODEL_FILTER = app.state.ENABLE_MODEL_FILTER ollama_app.state.MODEL_FILTER_LIST = app.state.MODEL_FILTER_LIST - openai_app.state.MODEL_FILTER_ENABLED = app.state.MODEL_FILTER_ENABLED + openai_app.state.ENABLE_MODEL_FILTER = app.state.ENABLE_MODEL_FILTER openai_app.state.MODEL_FILTER_LIST = app.state.MODEL_FILTER_LIST - litellm_app.state.MODEL_FILTER_ENABLED = app.state.MODEL_FILTER_ENABLED + litellm_app.state.ENABLE_MODEL_FILTER = app.state.ENABLE_MODEL_FILTER litellm_app.state.MODEL_FILTER_LIST = app.state.MODEL_FILTER_LIST return { - "enabled": app.state.MODEL_FILTER_ENABLED, + "enabled": app.state.ENABLE_MODEL_FILTER, "models": app.state.MODEL_FILTER_LIST, }