from functools import partial
from typing import List

from lm_eval.api.filter import FilterEnsemble
from lm_eval.api.registry import get_filter

from . import extraction, selection, transformation, custom


def build_filter_ensemble(
        filter_name: str, components: List[List[str]]
) -> FilterEnsemble:
    """
    Create a filtering pipeline.
    """
    filters = []
    for function, kwargs in components:
        if kwargs is None:
            kwargs = {}
        # create a filter given its name in the registry
        f = partial(get_filter(function), **kwargs)
        # add the filter as a pipeline step
        filters.append(f)

    return FilterEnsemble(name=filter_name, filters=filters)
