From 28f2965934f5b6fba0e0c38a15b2af6ee790819f Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 25 Aug 2026 15:26:45 -0400 Subject: [PATCH] refac --- backend/open_webui/utils/middleware.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 092c2dd3b8..a5ced21844 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -3836,7 +3836,8 @@ async def outlet_filter_handler(ctx): Replaces the separate POST /api/chat/completed round-trip. Persists outlet-modified content to DB and emits a chat:outlet event - so the frontend can sync its in-memory state. + so the frontend can sync its in-memory state. Returns immediately when + the model has no filters. For temp/API chats, messages are built from form_data plus ctx['assistant_message']. """ @@ -3858,6 +3859,17 @@ async def outlet_filter_handler(ctx): is_unsaved_chat = not is_saved_chat_id(chat_id) try: + filter_functions = ( + await get_filter_functions(request, model, metadata.get('filter_ids', [])) if ENABLE_PLUGINS else [] + ) + model_id = model.get('id') if isinstance(model, dict) else model + models = request.app.state.MODELS + has_pipeline_outlet_filters = bool( + (isinstance(model, dict) and 'pipeline' in model) or get_sorted_filters(model_id, models) + ) + if not filter_functions and not has_pipeline_outlet_filters: + return + messages_map = None if is_unsaved_chat: @@ -3892,8 +3904,6 @@ async def outlet_filter_handler(ctx): if not message_list: return - model_id = model.get('id') if isinstance(model, dict) else model - outlet_data = { 'model': model_id, 'messages': [ @@ -3917,7 +3927,6 @@ async def outlet_filter_handler(ctx): } # Pipeline outlet filters - models = request.app.state.MODELS try: outlet_data = await process_pipeline_outlet_filter(request, outlet_data, user, models) except Exception as e: @@ -3933,9 +3942,7 @@ async def outlet_filter_handler(ctx): '__model__': model, } - if ENABLE_PLUGINS: - filter_functions = await get_filter_functions(request, model, metadata.get('filter_ids', [])) - + if filter_functions: outlet_result, _ = await process_filter_functions( request=request, filter_context=None,