feat: Added an Fast API new endpoint to serve eval metric info

This endpoint could be used by ADK Web to dynamically know:
- What are the available eval metrics in an App
- A description of those metrics
- A value range supported by those metrics

We also update the metric registry to make it mandatory to supply these details. The goal is to improve usability and interpretability of the eval metrics.

PiperOrigin-RevId: 787277695
This commit is contained in:
Ankur Sharma
2025-07-25 16:25:20 -07:00
committed by Copybara-Service
parent ec7d9b0ff6
commit c69dcf8779
16 changed files with 394 additions and 54 deletions
@@ -16,6 +16,7 @@
from unittest.mock import patch
from google.adk.evaluation.eval_case import Invocation
from google.adk.evaluation.eval_metrics import PrebuiltMetrics
from google.adk.evaluation.evaluator import EvalStatus
from google.adk.evaluation.response_evaluator import ResponseEvaluator
from google.genai import types as genai_types
@@ -113,3 +114,29 @@ class TestResponseEvaluator:
assert [m.name for m in mock_kwargs["metrics"]] == [
vertexai_types.PrebuiltMetric.COHERENCE.name
]
def test_get_metric_info_response_evaluation_score(self, mock_perform_eval):
"""Test get_metric_info function for response evaluation metric."""
metric_info = ResponseEvaluator.get_metric_info(
PrebuiltMetrics.RESPONSE_EVALUATION_SCORE.value
)
assert (
metric_info.metric_name
== PrebuiltMetrics.RESPONSE_EVALUATION_SCORE.value
)
assert metric_info.metric_value_info.interval.min_value == 1.0
assert metric_info.metric_value_info.interval.max_value == 5.0
def test_get_metric_info_response_match_score(self, mock_perform_eval):
"""Test get_metric_info function for response match metric."""
metric_info = ResponseEvaluator.get_metric_info(
PrebuiltMetrics.RESPONSE_MATCH_SCORE.value
)
assert metric_info.metric_name == PrebuiltMetrics.RESPONSE_MATCH_SCORE.value
assert metric_info.metric_value_info.interval.min_value == 0.0
assert metric_info.metric_value_info.interval.max_value == 1.0
def test_get_metric_info_invalid(self, mock_perform_eval):
"""Test get_metric_info function for invalid metric."""
with pytest.raises(ValueError):
ResponseEvaluator.get_metric_info("invalid_metric")