[docs]defautorag_metric(fields_to_check:List[str]):defdecorator_autorag_metric(func):@functools.wraps(func)@convert_inputs_to_listdefwrapper(metric_inputs:List[MetricInput],**kwargs)->List[float]:""" Use 'for loop' to run each metric input. Put the single metric input into the metric function. :param metric_inputs: A list MetricInput schema for AutoRAG metric. :param kwargs: The additional arguments for metric function. :return: A list of computed metric scores. """results=[]formetric_inputinmetric_inputs:ifmetric_input.is_fields_notnone(fields_to_check=fields_to_check):results.append(func(metric_input,**kwargs))else:results.append(None)returnresultsreturnwrapperreturndecorator_autorag_metric
[docs]defautorag_metric_loop(fields_to_check:List[str]):defdecorator_autorag_generation_metric(func):@functools.wraps(func)@convert_inputs_to_listdefwrapper(metric_inputs:List[MetricInput],**kwargs)->List[float]:""" Put the list of metric inputs into the metric function. :param metric_inputs: A list MetricInput schema for AutoRAG metric. :param kwargs: The additional arguments for metric function. :return: A list of computed metric scores. """bool_list=[metric_input.is_fields_notnone(fields_to_check=fields_to_check)formetric_inputinmetric_inputs]valid_inputs=[metric_inputformetric_input,is_validinzip(metric_inputs,bool_list)ifis_valid]results=[None]*len(metric_inputs)ifvalid_inputs:processed_valid=func(valid_inputs,**kwargs)valid_index=0fori,is_validinenumerate(bool_list):ifis_valid:results[i]=processed_valid[valid_index]valid_index+=1returnresultsreturnwrapperreturndecorator_autorag_generation_metric