From ee8b8220f091cfb7ea206de791a550ef9c87853b Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 13 Oct 2024 22:56:33 -0700 Subject: [PATCH] refac: OPENAI_MODEL_LIST_TIMEOUT -> AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST --- backend/open_webui/apps/openai/main.py | 7 +++++-- backend/open_webui/env.py | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/open_webui/apps/openai/main.py b/backend/open_webui/apps/openai/main.py index fc3b01ab2..dbdf9911d 100644 --- a/backend/open_webui/apps/openai/main.py +++ b/backend/open_webui/apps/openai/main.py @@ -18,7 +18,10 @@ from open_webui.config import ( OPENAI_API_KEYS, AppConfig, ) -from open_webui.env import AIOHTTP_CLIENT_TIMEOUT, OPENAI_MODEL_LIST_TIMEOUT +from open_webui.env import ( + AIOHTTP_CLIENT_TIMEOUT, + AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST, +) from open_webui.constants import ERROR_MESSAGES from open_webui.env import SRC_LOG_LEVELS @@ -179,7 +182,7 @@ async def speech(request: Request, user=Depends(get_verified_user)): async def fetch_url(url, key): - timeout = aiohttp.ClientTimeout(total=OPENAI_MODEL_LIST_TIMEOUT) + timeout = aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST) try: headers = {"Authorization": f"Bearer {key}"} async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session: diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 34b67e9de..15c8cd7cc 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -363,15 +363,19 @@ else: except Exception: AIOHTTP_CLIENT_TIMEOUT = 300 -OPENAI_MODEL_LIST_TIMEOUT = os.environ.get("OPENAI_MODEL_LIST_TIMEOUT", "") +AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST = os.environ.get( + "AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST", "3" +) -if OPENAI_MODEL_LIST_TIMEOUT == "": - OPENAI_MODEL_LIST_TIMEOUT = None +if AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST == "": + AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST = None else: try: - OPENAI_MODEL_LIST_TIMEOUT = int(OPENAI_MODEL_LIST_TIMEOUT) + AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST = int( + AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST + ) except Exception: - OPENAI_MODEL_LIST_TIMEOUT = 3 + AIOHTTP_CLIENT_TIMEOUT_OPENAI_MODEL_LIST = None #################################### # OFFLINE_MODE