From c7a0e45bea3b6fb39567ae87efc030b02a186df5 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 30 Sep 2024 16:32:38 +0200 Subject: [PATCH] refac --- backend/open_webui/apps/ollama/main.py | 6 ++++-- backend/open_webui/apps/openai/main.py | 5 +++-- backend/open_webui/config.py | 10 ---------- backend/open_webui/env.py | 11 +++++++++++ backend/open_webui/main.py | 3 ++- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/backend/open_webui/apps/ollama/main.py b/backend/open_webui/apps/ollama/main.py index 2e02d069f..33d984655 100644 --- a/backend/open_webui/apps/ollama/main.py +++ b/backend/open_webui/apps/ollama/main.py @@ -12,7 +12,6 @@ import aiohttp import requests from open_webui.apps.webui.models.models import Models from open_webui.config import ( - AIOHTTP_CLIENT_TIMEOUT, CORS_ALLOW_ORIGIN, ENABLE_MODEL_FILTER, ENABLE_OLLAMA_API, @@ -21,6 +20,9 @@ from open_webui.config import ( UPLOAD_DIR, AppConfig, ) +from open_webui.env import AIOHTTP_CLIENT_TIMEOUT + + from open_webui.constants import ERROR_MESSAGES from open_webui.env import SRC_LOG_LEVELS from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile @@ -117,7 +119,7 @@ async def update_ollama_api_url(form_data: UrlUpdateForm, user=Depends(get_admin async def fetch_url(url): - timeout = aiohttp.ClientTimeout(total=5) + timeout = aiohttp.ClientTimeout(total=3) try: async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session: async with session.get(url) as response: diff --git a/backend/open_webui/apps/openai/main.py b/backend/open_webui/apps/openai/main.py index 9d62f32d2..70cefb29c 100644 --- a/backend/open_webui/apps/openai/main.py +++ b/backend/open_webui/apps/openai/main.py @@ -9,7 +9,6 @@ import aiohttp import requests from open_webui.apps.webui.models.models import Models from open_webui.config import ( - AIOHTTP_CLIENT_TIMEOUT, CACHE_DIR, CORS_ALLOW_ORIGIN, ENABLE_MODEL_FILTER, @@ -19,6 +18,8 @@ from open_webui.config import ( OPENAI_API_KEYS, AppConfig, ) +from open_webui.env import AIOHTTP_CLIENT_TIMEOUT + from open_webui.constants import ERROR_MESSAGES from open_webui.env import SRC_LOG_LEVELS from fastapi import Depends, FastAPI, HTTPException, Request @@ -178,7 +179,7 @@ async def speech(request: Request, user=Depends(get_verified_user)): async def fetch_url(url, key): - timeout = aiohttp.ClientTimeout(total=5) + timeout = aiohttp.ClientTimeout(total=3) try: headers = {"Authorization": f"Bearer {key}"} async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session: diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 2518599ca..3c28ab01f 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -561,16 +561,6 @@ OLLAMA_API_BASE_URL = os.environ.get( ) OLLAMA_BASE_URL = os.environ.get("OLLAMA_BASE_URL", "") -AIOHTTP_CLIENT_TIMEOUT = os.environ.get("AIOHTTP_CLIENT_TIMEOUT", "") - -if AIOHTTP_CLIENT_TIMEOUT == "": - AIOHTTP_CLIENT_TIMEOUT = None -else: - try: - AIOHTTP_CLIENT_TIMEOUT = int(AIOHTTP_CLIENT_TIMEOUT) - except Exception: - AIOHTTP_CLIENT_TIMEOUT = 300 - K8S_FLAG = os.environ.get("K8S_FLAG", "") USE_OLLAMA_DOCKER = os.environ.get("USE_OLLAMA_DOCKER", "false") diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 4f1403e97..5bb5c1238 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -305,3 +305,14 @@ ENABLE_WEBSOCKET_SUPPORT = ( WEBSOCKET_MANAGER = os.environ.get("WEBSOCKET_MANAGER", "") WEBSOCKET_REDIS_URL = os.environ.get("WEBSOCKET_REDIS_URL", "redis://localhost:6379/0") + + +AIOHTTP_CLIENT_TIMEOUT = os.environ.get("AIOHTTP_CLIENT_TIMEOUT", "") + +if AIOHTTP_CLIENT_TIMEOUT == "": + AIOHTTP_CLIENT_TIMEOUT = None +else: + try: + AIOHTTP_CLIENT_TIMEOUT = int(AIOHTTP_CLIENT_TIMEOUT) + except Exception: + AIOHTTP_CLIENT_TIMEOUT = 300 diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 5c964c597..8da4c6a48 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -2191,7 +2191,8 @@ async def get_app_latest_release_version(): latest_version = data["tag_name"] return {"current": VERSION, "latest": latest_version[1:]} - except aiohttp.ClientError: + except Exception as e: + log.debug(e) return {"current": VERSION, "latest": VERSION}