Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions agentplatform/_genai/_evals_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,52 @@
"final_response_reference_free_v2",
"gecko_text2image_v2",
"gecko_text2video_v2",
# Latest predefined metrics. Judge calls stay in the request's data
# residency jurisdiction.
"general_quality_v3",
"instruction_following_v3",
"text_quality_v3",
"grounding_v3",
"hallucination_v3",
"safety_v4",
"multi_turn_general_quality_v3",
"multi_turn_text_quality_v3",
"multi_turn_task_success_v2",
"multi_turn_tool_use_quality_v2",
"multi_turn_trajectory_quality_v3",
"tool_use_quality_v3",
"final_response_quality_v3",
"final_response_match_v4",
"final_response_reference_free_v3",
"gecko_text2image_v3",
"gecko_text2video_v3",
}
)

# Maps the SDK-facing base metric name to the latest API spec name.
# When a user creates a metric without specifying a version, this resolves to
# the latest available version (backed by Gemini 3.5 Flash).
# Note: v2/v3 specs require Gemini 3.5 Flash, which is not available in all
# regions (e.g. us-central1). To use v1 explicitly for full regional
# availability:
# types.RubricMetric.GENERAL_QUALITY(version="v1")
# the latest available version, whose judge calls stay in the request's data
# residency jurisdiction (us-* -> us, EU regions -> eu). To pin an earlier
# version:
# types.RubricMetric.GENERAL_QUALITY(version="v2")
METRIC_LATEST_SPEC_NAME: dict[str, str] = {
"general_quality": "general_quality_v2",
"instruction_following": "instruction_following_v2",
"text_quality": "text_quality_v2",
"grounding": "grounding_v2",
"hallucination": "hallucination_v2",
"safety": "safety_v3",
"multi_turn_general_quality": "multi_turn_general_quality_v2",
"multi_turn_text_quality": "multi_turn_text_quality_v2",
"tool_use_quality": "tool_use_quality_v2",
"final_response_quality": "final_response_quality_v2",
"final_response_match": "final_response_match_v3",
"final_response_reference_free": "final_response_reference_free_v2",
"gecko_text2image": "gecko_text2image_v2",
"gecko_text2video": "gecko_text2video_v2",
"general_quality": "general_quality_v3",
"instruction_following": "instruction_following_v3",
"text_quality": "text_quality_v3",
"grounding": "grounding_v3",
"hallucination": "hallucination_v3",
"safety": "safety_v4",
"multi_turn_general_quality": "multi_turn_general_quality_v3",
"multi_turn_text_quality": "multi_turn_text_quality_v3",
"multi_turn_task_success": "multi_turn_task_success_v2",
"multi_turn_tool_use_quality": "multi_turn_tool_use_quality_v2",
"multi_turn_trajectory_quality": "multi_turn_trajectory_quality_v3",
"tool_use_quality": "tool_use_quality_v3",
"final_response_quality": "final_response_quality_v3",
"final_response_match": "final_response_match_v4",
"final_response_reference_free": "final_response_reference_free_v3",
"gecko_text2image": "gecko_text2image_v3",
"gecko_text2video": "gecko_text2video_v3",
}

SUPPORTED_VERTEX_MAAS_MODEL_PREFIXES = frozenset(
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/agentplatform/genai/test_evals.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from google.cloud.aiplatform import initializer as aiplatform_initializer
from agentplatform import _genai
from agentplatform._genai import _evals_builtin_tools
from agentplatform._genai import _evals_constant
from agentplatform._genai import _evals_data_converters
from agentplatform._genai import _evals_metric_handlers
from agentplatform._genai import _evals_visualization
Expand Down Expand Up @@ -7662,6 +7663,52 @@ def test_gcs_backed_property_pins_to_v1(self, prop_name):
assert lazy_metric._get_api_metric_spec_name() is None


class TestPrebuiltMetricLatestVersion:
"""Verifies that metrics without a version resolve to the latest specs."""

@pytest.mark.parametrize(
"name,expected_spec",
[
("GENERAL_QUALITY", "general_quality_v3"),
("INSTRUCTION_FOLLOWING", "instruction_following_v3"),
("TEXT_QUALITY", "text_quality_v3"),
("GROUNDING", "grounding_v3"),
("HALLUCINATION", "hallucination_v3"),
("SAFETY", "safety_v4"),
("MULTI_TURN_GENERAL_QUALITY", "multi_turn_general_quality_v3"),
("MULTI_TURN_TEXT_QUALITY", "multi_turn_text_quality_v3"),
("MULTI_TURN_TASK_SUCCESS", "multi_turn_task_success_v2"),
("MULTI_TURN_TOOL_USE_QUALITY", "multi_turn_tool_use_quality_v2"),
("MULTI_TURN_TRAJECTORY_QUALITY", "multi_turn_trajectory_quality_v3"),
("TOOL_USE_QUALITY", "tool_use_quality_v3"),
("FINAL_RESPONSE_QUALITY", "final_response_quality_v3"),
("FINAL_RESPONSE_MATCH", "final_response_match_v4"),
("FINAL_RESPONSE_REFERENCE_FREE", "final_response_reference_free_v3"),
("GECKO_TEXT2IMAGE", "gecko_text2image_v3"),
("GECKO_TEXT2VIDEO", "gecko_text2video_v3"),
],
)
def test_unversioned_metric_resolves_to_latest(self, name, expected_spec):
lazy_metric = _evals_metric_loaders.LazyLoadedPrebuiltMetric(name=name)
assert lazy_metric._get_api_metric_spec_name() == expected_spec
assert expected_spec in _evals_constant.SUPPORTED_PREDEFINED_METRICS

@pytest.mark.parametrize(
"name,version,expected_spec",
[
("GENERAL_QUALITY", "v2", "general_quality_v2"),
("SAFETY", "v3", "safety_v3"),
("FINAL_RESPONSE_MATCH", "v3", "final_response_match_v3"),
("MULTI_TURN_TASK_SUCCESS", "v1", "multi_turn_task_success_v1"),
],
)
def test_earlier_version_can_be_pinned(self, name, version, expected_spec):
lazy_metric = _evals_metric_loaders.LazyLoadedPrebuiltMetric(
name=name, version=version
)
assert lazy_metric._get_api_metric_spec_name() == expected_spec


class TestMergeResponseDatasets:
"""Unit tests for the merge_response_datasets_into_canonical_format function."""

Expand Down
Loading