Base Metric Decorator¶
- class ibm_watsonx_gov.metrics.base_metric_decorator.BaseMetricDecorator(api_client: APIClient = None, configuration: AgenticAIConfiguration = None, compute_real_time: bool = True, metric_results: list[AgentMetricResult] = [], execution_counts: dict[str, dict[str, int]] = {}, nodes_being_run: dict[str, Set[str]] = {}, lock: allocate_lock = None)¶
Bases:
object
Base class for all metric decorators
- compute_helper(*, func: Callable, args: tuple, kwargs: dict[str, Any], configuration: AgenticAIConfiguration, metrics: list[GenAIMetric], metric_inputs: list[EvaluatorFields], metric_outputs: list[EvaluatorFields], metric_references: list[EvaluatorFields] = [], metric_groups: list[MetricGroup] = []) dict ¶
Helper method for computing metrics.
- Does the following:
Computes node latency metric, and appends the result to the
AgenticEvaluation.metric_results
attribute.Calls the original node.
Computes the list of metrics given, and appends the result to the
AgenticEvaluation.metric_results
attribute.Returns the result of the original node without any changes.
- Parameters:
func (Callable) – The node on which the metric is to be computed
args (tuple) – The tuple of positional arguments passed to the node
kwargs (dict[str, Any]) – The dictionary of keyword arguments passed to the node
configuration (AgenticAIConfiguration) – The node specific configuration
metrics (list[GenAIMetric]) – The list of metrics to compute.
metric_inputs (list[EvaluatorFields]) – The list of inputs for the metric.
metric_outputs (list[EvaluatorFields]) – The list of outputs for the metric.
metric_references (list[EvaluatorFields], optional) – The optional list of references for the metric. Defaults to [].
- Raises:
ValueError – If the record id field is missing from the node inputs.
- Returns:
The result of the wrapped node.
- Return type:
dict
- validate(*, func: Callable, metrics: list[GenAIMetric], valid_metric_types: tuple[Any])¶