From bfb12a7851d4cd3c1828661db68bbed53c15dcc8 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 6 Sep 2024 04:59:20 +0200 Subject: [PATCH] refac --- backend/.gitignore | 6 +----- backend/open_webui/__init__.py | 2 ++ backend/open_webui/env.py | 20 ++++---------------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/backend/.gitignore b/backend/.gitignore index ea83b34f4..614a5f746 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -8,9 +8,5 @@ _test Pipfile !/data /data/* -!/data/litellm -/data/litellm/* -!data/litellm/config.yaml - -!data/config.json +/open_webui/data/* .webui_secret_key \ No newline at end of file diff --git a/backend/open_webui/__init__.py b/backend/open_webui/__init__.py index c6578c214..bb1db0dea 100644 --- a/backend/open_webui/__init__.py +++ b/backend/open_webui/__init__.py @@ -10,6 +10,8 @@ app = typer.Typer() KEY_FILE = Path.cwd() / ".webui_secret_key" +os.environ["RUNNING_FROM_INIT_PY"] = "true" + @app.command() def serve( diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index b0585db90..865d61003 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -88,21 +88,9 @@ WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png" ENV = os.environ.get("ENV", "dev") -PIP_INSTALL = False -try: - importlib.metadata.version("open-webui") - PIP_INSTALL = True -except importlib.metadata.PackageNotFoundError: - pass +FROM_INIT_PY = os.environ.get("FROM_INIT_PY", "False").lower() == "true" - -PIP_INSTALL = ( - os.environ.get("PIP_INSTALL", "False").lower() == "true" - if os.environ.get("PIP_INSTALL") - else PIP_INSTALL -) - -if PIP_INSTALL: +if FROM_INIT_PY: PACKAGE_DATA = {"version": importlib.metadata.version("open-webui")} else: try: @@ -193,7 +181,7 @@ WEBUI_BUILD_HASH = os.environ.get("WEBUI_BUILD_HASH", "dev-build") DATA_DIR = Path(os.getenv("DATA_DIR", BACKEND_DIR / "data")).resolve() -if PIP_INSTALL: +if FROM_INIT_PY: NEW_DATA_DIR = Path(os.getenv("DATA_DIR", OPEN_WEBUI_DIR / "data")).resolve() NEW_DATA_DIR.mkdir(parents=True, exist_ok=True) @@ -212,7 +200,7 @@ if PIP_INSTALL: FRONTEND_BUILD_DIR = Path(os.getenv("FRONTEND_BUILD_DIR", BASE_DIR / "build")).resolve() -if PIP_INSTALL: +if FROM_INIT_PY: FRONTEND_BUILD_DIR = Path( os.getenv("FRONTEND_BUILD_DIR", OPEN_WEBUI_DIR / "frontend") ).resolve()