diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 5544888813..d7f00959a5 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -57,6 +57,7 @@ from open_webui.routers.images import ( image_generations, ) from open_webui.routers.pipelines import ( + get_sorted_filters, process_pipeline_inlet_filter, process_pipeline_outlet_filter, ) @@ -5437,6 +5438,16 @@ async def streaming_chat_response_handler(response, ctx): return f'data: {item}\n\n' assistant_message = {} + has_api_outlet_filters = ENABLE_API_OUTLET_FILTERS and bool(filter_functions) + if ENABLE_API_OUTLET_FILTERS and not has_api_outlet_filters: + try: + model_id = model.get('id') if isinstance(model, dict) else model + has_api_outlet_filters = bool( + (isinstance(model, dict) and 'pipeline' in model) + or get_sorted_filters(model_id, request.app.state.MODELS) + ) + except Exception: + has_api_outlet_filters = True for event in events: event, _ = await process_filter_functions( @@ -5460,11 +5471,11 @@ async def streaming_chat_response_handler(response, ctx): ) if data: - if ENABLE_API_OUTLET_FILTERS: + if has_api_outlet_filters: update_assistant_message_from_stream(assistant_message, data) yield data - if ENABLE_API_OUTLET_FILTERS and assistant_message: + if has_api_outlet_filters and assistant_message: ctx['assistant_message'] = assistant_message await outlet_filter_handler(ctx)