Skip to content

Commit

Permalink
always call the default metric_params_validator
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-risch committed Feb 15, 2024
1 parent 6677d06 commit dca5127
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .metrics import (
METRIC_DESCRIPTORS,
InputConverters,
MetricParamsValidator,
OutputConverters,
RagasMetric,
)
Expand Down Expand Up @@ -61,7 +62,9 @@ def _init_backend(self):
self._backend_callable = RagasEvaluator._invoke_evaluate

def _init_metric(self):
self.descriptor.metric_params_validator(self.metric, self.descriptor.init_parameters, self.metric_params)
MetricParamsValidator.validate_metric_parameters(
self.metric, self.descriptor.init_parameters, self.metric_params
)
self._backend_metric = self.descriptor.backend(**self.metric_params)

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ class MetricDescriptor:
The metric.
:param backend:
The associated Ragas metric class.
:param metric_params_validator:
Callable that validates metric parameters.
:param input_parameters:
Parameters accepted by the metric. This is used
to set the input types of the evaluator component.
Expand All @@ -133,7 +131,6 @@ class MetricDescriptor:
input_parameters: Dict[str, Type]
input_converter: Callable[[Any], Iterable[Dict[str, str]]]
output_converter: Callable[[Result, RagasMetric, Dict[str, Any]], List[MetricResult]]
metric_params_validator: Callable[[RagasMetric, List[str], Dict[str, Any]], None]
init_parameters: Optional[List[str]] = None

@classmethod
Expand All @@ -143,7 +140,6 @@ def new(
backend: Type[Metric],
input_converter: Callable[[Any], Iterable[Dict[str, str]]],
output_converter: Optional[Callable[[Result, RagasMetric, Dict[str, Any]], List[MetricResult]]] = None,
metric_params_validator: Optional[Callable[[RagasMetric, List[str], Dict[str, Any]], None]] = None,
*,
init_parameters: Optional[List[str]] = None,
) -> "MetricDescriptor":
Expand All @@ -162,16 +158,11 @@ def new(
input_parameters=input_parameters,
input_converter=input_converter,
output_converter=output_converter if output_converter is not None else OutputConverters.default,
metric_params_validator=(
metric_params_validator
if metric_params_validator is not None
else MetricParamsValidators.validate_metric_parameters
),
init_parameters=init_parameters,
)


class MetricParamsValidators:
class MetricParamsValidator:
"""
Validates metric parameters.
Expand Down

0 comments on commit dca5127

Please sign in to comment.