From 96c865404d36637eafadb6d2dd2365c85d452648 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 9 Nov 2024 18:01:23 -0800 Subject: [PATCH] refac: disable openapi.json --- backend/open_webui/apps/audio/main.py | 5 +++-- backend/open_webui/apps/images/main.py | 5 +++-- backend/open_webui/apps/ollama/main.py | 6 ++++-- backend/open_webui/apps/openai/main.py | 7 +++++-- backend/open_webui/apps/retrieval/main.py | 2 +- backend/open_webui/apps/webui/main.py | 3 ++- backend/open_webui/main.py | 2 +- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/backend/open_webui/apps/audio/main.py b/backend/open_webui/apps/audio/main.py index b138f82de..50ffad12b 100644 --- a/backend/open_webui/apps/audio/main.py +++ b/backend/open_webui/apps/audio/main.py @@ -32,7 +32,7 @@ from open_webui.config import ( ) from open_webui.constants import ERROR_MESSAGES -from open_webui.env import SRC_LOG_LEVELS, DEVICE_TYPE +from open_webui.env import ENV, SRC_LOG_LEVELS, DEVICE_TYPE from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile, status from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import FileResponse @@ -47,7 +47,8 @@ MAX_FILE_SIZE = MAX_FILE_SIZE_MB * 1024 * 1024 # Convert MB to bytes log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["AUDIO"]) -app = FastAPI() +app = FastAPI(docs_url="/docs" if ENV == "dev" else None, openapi_url="/openapi.json" if ENV == "dev" else None, redoc_url=None) + app.add_middleware( CORSMiddleware, allow_origins=CORS_ALLOW_ORIGIN, diff --git a/backend/open_webui/apps/images/main.py b/backend/open_webui/apps/images/main.py index d3cbd4d91..56b251ef6 100644 --- a/backend/open_webui/apps/images/main.py +++ b/backend/open_webui/apps/images/main.py @@ -35,7 +35,7 @@ from open_webui.config import ( AppConfig, ) from open_webui.constants import ERROR_MESSAGES -from open_webui.env import SRC_LOG_LEVELS +from open_webui.env import ENV, SRC_LOG_LEVELS from fastapi import Depends, FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel @@ -47,7 +47,8 @@ log.setLevel(SRC_LOG_LEVELS["IMAGES"]) IMAGE_CACHE_DIR = Path(CACHE_DIR).joinpath("./image/generations/") IMAGE_CACHE_DIR.mkdir(parents=True, exist_ok=True) -app = FastAPI() +app = FastAPI(docs_url="/docs" if ENV == "dev" else None, openapi_url="/openapi.json" if ENV == "dev" else None, redoc_url=None) + app.add_middleware( CORSMiddleware, allow_origins=CORS_ALLOW_ORIGIN, diff --git a/backend/open_webui/apps/ollama/main.py b/backend/open_webui/apps/ollama/main.py index 9db96493e..8976d55b4 100644 --- a/backend/open_webui/apps/ollama/main.py +++ b/backend/open_webui/apps/ollama/main.py @@ -24,7 +24,7 @@ from open_webui.env import AIOHTTP_CLIENT_TIMEOUT from open_webui.constants import ERROR_MESSAGES -from open_webui.env import SRC_LOG_LEVELS +from open_webui.env import ENV, SRC_LOG_LEVELS from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import StreamingResponse @@ -45,7 +45,9 @@ from open_webui.utils.utils import get_admin_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["OLLAMA"]) -app = FastAPI() + +app = FastAPI(docs_url="/docs" if ENV == "dev" else None, openapi_url="/openapi.json" if ENV == "dev" else None, redoc_url=None) + app.add_middleware( CORSMiddleware, allow_origins=CORS_ALLOW_ORIGIN, diff --git a/backend/open_webui/apps/openai/main.py b/backend/open_webui/apps/openai/main.py index 3647977ca..f7e1c7bf8 100644 --- a/backend/open_webui/apps/openai/main.py +++ b/backend/open_webui/apps/openai/main.py @@ -24,7 +24,7 @@ from open_webui.env import ( ) from open_webui.constants import ERROR_MESSAGES -from open_webui.env import SRC_LOG_LEVELS +from open_webui.env import ENV, SRC_LOG_LEVELS from fastapi import Depends, FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import FileResponse, StreamingResponse @@ -41,7 +41,10 @@ from open_webui.utils.utils import get_admin_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["OPENAI"]) -app = FastAPI() + +app = FastAPI(docs_url="/docs" if ENV == "dev" else None, openapi_url="/openapi.json" if ENV == "dev" else None, redoc_url=None) + + app.add_middleware( CORSMiddleware, allow_origins=CORS_ALLOW_ORIGIN, diff --git a/backend/open_webui/apps/retrieval/main.py b/backend/open_webui/apps/retrieval/main.py index e67d1df23..85472485d 100644 --- a/backend/open_webui/apps/retrieval/main.py +++ b/backend/open_webui/apps/retrieval/main.py @@ -118,7 +118,7 @@ from langchain_core.documents import Document log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) -app = FastAPI() +app = FastAPI(docs_url="/docs" if ENV == "dev" else None, openapi_url="/openapi.json" if ENV == "dev" else None, redoc_url=None) app.state.config = AppConfig() diff --git a/backend/open_webui/apps/webui/main.py b/backend/open_webui/apps/webui/main.py index 5a0a83961..b32c83f88 100644 --- a/backend/open_webui/apps/webui/main.py +++ b/backend/open_webui/apps/webui/main.py @@ -53,6 +53,7 @@ from open_webui.config import ( AppConfig, ) from open_webui.env import ( + ENV, WEBUI_AUTH_TRUSTED_EMAIL_HEADER, WEBUI_AUTH_TRUSTED_NAME_HEADER, ) @@ -72,7 +73,7 @@ from open_webui.utils.payload import ( from open_webui.utils.tools import get_tools -app = FastAPI() +app = FastAPI(docs_url="/docs" if ENV == "dev" else None, openapi_url="/openapi.json" if ENV == "dev" else None, redoc_url=None) log = logging.getLogger(__name__) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 35f707328..7b37e37b1 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -182,7 +182,7 @@ async def lifespan(app: FastAPI): app = FastAPI( - docs_url="/docs" if ENV == "dev" else None, redoc_url=None, lifespan=lifespan + docs_url="/docs" if ENV == "dev" else None, openapi_url="/openapi.json" if ENV == "dev" else None, redoc_url=None, lifespan=lifespan ) app.state.config = AppConfig()