BaseMetric¶
- class opik.evaluation.metrics.BaseMetric(name: str)¶
Bases:
ABC
Abstract base class for all metrics. When creating a new metric, you should inherit from this class and implement the abstract methods.
- Parameters:
name – The name of the metric.
Example
>>> from opik.evaluation.metrics import base_metric, score_result >>> >>> class MyCustomMetric(base_metric.BaseMetric): >>> def __init__(self, name: str): >>> self.name = name >>> >>> def score(self, input: str, output: str, **ignored_kwargs: Any): >>> # Add you logic here >>> >>> return score_result.ScoreResult( >>> value=0, >>> name=self.name, >>> reason="Optional reason for the score" >>> )
- abstract score(*args: Any, **kwargs: Any) ScoreResult | List[ScoreResult] ¶
Public method that can be called independently.
- async ascore(*args: Any, **kwargs: Any) ScoreResult | List[ScoreResult] ¶
Async public method that can be called independently.