Browse Source

add: OPENAI_MODEL_LIST_TIMEOUT

LuoChen 6 months ago
parent
commit
ebec6cd426
2 changed files with 12 additions and 2 deletions
  1. 2 2
      backend/open_webui/apps/openai/main.py
  2. 10 0
      backend/open_webui/env.py

+ 2 - 2
backend/open_webui/apps/openai/main.py

@@ -18,7 +18,7 @@ from open_webui.config import (
     OPENAI_API_KEYS,
     AppConfig,
 )
-from open_webui.env import AIOHTTP_CLIENT_TIMEOUT
+from open_webui.env import AIOHTTP_CLIENT_TIMEOUT, OPENAI_MODEL_LIST_TIMEOUT
 
 from open_webui.constants import ERROR_MESSAGES
 from open_webui.env import SRC_LOG_LEVELS
@@ -179,7 +179,7 @@ async def speech(request: Request, user=Depends(get_verified_user)):
 
 
 async def fetch_url(url, key):
-    timeout = aiohttp.ClientTimeout(total=3)
+    timeout = aiohttp.ClientTimeout(total=OPENAI_MODEL_LIST_TIMEOUT)
     try:
         headers = {"Authorization": f"Bearer {key}"}
         async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session:

+ 10 - 0
backend/open_webui/env.py

@@ -363,6 +363,16 @@ else:
     except Exception:
         AIOHTTP_CLIENT_TIMEOUT = 300
 
+OPENAI_MODEL_LIST_TIMEOUT = os.environ.get("OPENAI_MODEL_LIST_TIMEOUT", "")
+
+if OPENAI_MODEL_LIST_TIMEOUT == "":
+    OPENAI_MODEL_LIST_TIMEOUT = None
+else:
+    try:
+        OPENAI_MODEL_LIST_TIMEOUT = int(OPENAI_MODEL_LIST_TIMEOUT)
+    except Exception:
+        OPENAI_MODEL_LIST_TIMEOUT = 3
+
 ####################################
 # OFFLINE_MODE
 ####################################