diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index cd0136a5c8..a4117c33ce 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -403,6 +403,16 @@ ENABLE_WEBSOCKET_SUPPORT = ( os.environ.get("ENABLE_WEBSOCKET_SUPPORT", "True").lower() == "true" ) +MODEL_LIST_CACHE_TTL = os.environ.get("MODEL_LIST_CACHE_TTL", "1") +if MODEL_LIST_CACHE_TTL == "": + MODEL_LIST_CACHE_TTL = None +else: + try: + MODEL_LIST_CACHE_TTL = int(MODEL_LIST_CACHE_TTL) + except Exception: + MODEL_LIST_CACHE_TTL = 1 + + WEBSOCKET_MANAGER = os.environ.get("WEBSOCKET_MANAGER", "") WEBSOCKET_REDIS_URL = os.environ.get("WEBSOCKET_REDIS_URL", REDIS_URL) diff --git a/backend/open_webui/routers/ollama.py b/backend/open_webui/routers/ollama.py index 9c1e1fdb00..44ba3d5774 100644 --- a/backend/open_webui/routers/ollama.py +++ b/backend/open_webui/routers/ollama.py @@ -59,6 +59,7 @@ from open_webui.config import ( from open_webui.env import ( ENV, SRC_LOG_LEVELS, + MODEL_LIST_CACHE_TTL, AIOHTTP_CLIENT_SESSION_SSL, AIOHTTP_CLIENT_TIMEOUT, AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST, @@ -330,7 +331,7 @@ def merge_ollama_models_lists(model_lists): return list(merged_models.values()) -@cached(ttl=1) +@cached(ttl=MODEL_LIST_CACHE_TTL) async def get_all_models(request: Request, user: UserModel = None): log.info("get_all_models()") if request.app.state.config.ENABLE_OLLAMA_API: diff --git a/backend/open_webui/routers/openai.py b/backend/open_webui/routers/openai.py index ab35a673fc..1f72f9fc57 100644 --- a/backend/open_webui/routers/openai.py +++ b/backend/open_webui/routers/openai.py @@ -21,6 +21,7 @@ from open_webui.config import ( CACHE_DIR, ) from open_webui.env import ( + MODEL_LIST_CACHE_TTL, AIOHTTP_CLIENT_SESSION_SSL, AIOHTTP_CLIENT_TIMEOUT, AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST, @@ -386,7 +387,7 @@ async def get_filtered_models(models, user): return filtered_models -@cached(ttl=1) +@cached(ttl=MODEL_LIST_CACHE_TTL) async def get_all_models(request: Request, user: UserModel) -> dict[str, list]: log.info("get_all_models()")