From 556c75e8761f3e810150dc2072aa3893692f62c2 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 21 Dec 2024 09:59:12 -0700 Subject: [PATCH] refac --- backend/open_webui/utils/chat.py | 10 ++++++---- backend/open_webui/utils/models.py | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/utils/chat.py b/backend/open_webui/utils/chat.py index c81e56afb..262e2b75d 100644 --- a/backend/open_webui/utils/chat.py +++ b/backend/open_webui/utils/chat.py @@ -89,7 +89,7 @@ async def generate_chat_completion( if model_ids and filter_mode == "exclude": model_ids = [ model["id"] - for model in await get_all_models(request) + for model in list(request.app.state.MODELS.values()) if model.get("owned_by") != "arena" and model["id"] not in model_ids ] @@ -99,7 +99,7 @@ async def generate_chat_completion( else: model_ids = [ model["id"] - for model in await get_all_models(request) + for model in list(request.app.state.MODELS.values()) if model.get("owned_by") != "arena" ] selected_model_id = random.choice(model_ids) @@ -154,7 +154,8 @@ async def generate_chat_completion( async def chat_completed(request: Request, form_data: dict, user: Any): - await get_all_models(request) + if not request.app.state.MODELS: + await get_all_models(request) models = request.app.state.MODELS data = form_data @@ -289,7 +290,8 @@ async def chat_action(request: Request, action_id: str, form_data: dict, user: A if not action: raise Exception(f"Action not found: {action_id}") - await get_all_models(request) + if not request.app.state.MODELS: + await get_all_models(request) models = request.app.state.MODELS data = form_data diff --git a/backend/open_webui/utils/models.py b/backend/open_webui/utils/models.py index b9a4f07a3..975f8cb09 100644 --- a/backend/open_webui/utils/models.py +++ b/backend/open_webui/utils/models.py @@ -58,7 +58,6 @@ async def get_all_base_models(request: Request): return models -@cached(ttl=3) async def get_all_models(request): models = await get_all_base_models(request)