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
40 changes: 40 additions & 0 deletions agentplatform/_genai/_evals_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

SUPPORTED_PREDEFINED_METRICS = frozenset(
{
# v1 metrics (kept for backward compatibility).
"general_quality_v1",
"text_quality_v1",
"instruction_following_v1",
Expand All @@ -33,9 +34,48 @@
"tool_use_quality_v1",
"gecko_text2image_v1",
"gecko_text2video_v1",
# v2/v3 metrics backed by Gemini 3.5 Flash.
"general_quality_v2",
"instruction_following_v2",
"text_quality_v2",
"grounding_v2",
"hallucination_v2",
"safety_v3",
"multi_turn_general_quality_v2",
"multi_turn_text_quality_v2",
"tool_use_quality_v2",
"final_response_quality_v2",
"final_response_match_v3",
"final_response_reference_free_v2",
"gecko_text2image_v2",
"gecko_text2video_v2",
}
)

# 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")
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",
}

SUPPORTED_VERTEX_MAAS_MODEL_PREFIXES = frozenset(
{
"meta/", # Meta/Llama
Expand Down
7 changes: 5 additions & 2 deletions agentplatform/_genai/_evals_metric_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _get_api_metric_spec_name(self) -> Optional[str]:
"""Constructs the metric_spec_name for API Predefined Metrics."""
base_name = self.name.lower()
if self.version:
# Explicit version provided
# Explicit version provided.
version = self.version.lower()
potential_name = f"{base_name}_{version}"
return (
Expand All @@ -63,7 +63,10 @@ def _get_api_metric_spec_name(self) -> Optional[str]:
else None
)
else:
# Default versioning: Try _v1, then base name
# No version specified: resolve to the latest available version,
# falling back to _v1, then the bare base name.
if base_name in _evals_constant.METRIC_LATEST_SPEC_NAME:
return _evals_constant.METRIC_LATEST_SPEC_NAME[base_name]
v1_name = f"{base_name}_v1"
if v1_name in _evals_constant.SUPPORTED_PREDEFINED_METRICS:
return v1_name
Expand Down
40 changes: 40 additions & 0 deletions vertexai/_genai/_evals_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

SUPPORTED_PREDEFINED_METRICS = frozenset(
{
# v1 metrics (kept for backward compatibility).
"general_quality_v1",
"text_quality_v1",
"instruction_following_v1",
Expand All @@ -33,9 +34,48 @@
"tool_use_quality_v1",
"gecko_text2image_v1",
"gecko_text2video_v1",
# v2/v3 metrics backed by Gemini 3.5 Flash.
"general_quality_v2",
"instruction_following_v2",
"text_quality_v2",
"grounding_v2",
"hallucination_v2",
"safety_v3",
"multi_turn_general_quality_v2",
"multi_turn_text_quality_v2",
"tool_use_quality_v2",
"final_response_quality_v2",
"final_response_match_v3",
"final_response_reference_free_v2",
"gecko_text2image_v2",
"gecko_text2video_v2",
}
)

# 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")
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",
}

SUPPORTED_VERTEX_MAAS_MODEL_PREFIXES = frozenset(
{
"meta/", # Meta/Llama
Expand Down
7 changes: 5 additions & 2 deletions vertexai/_genai/_evals_metric_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _get_api_metric_spec_name(self) -> Optional[str]:
"""Constructs the metric_spec_name for API Predefined Metrics."""
base_name = self.name.lower()
if self.version:
# Explicit version provided
# Explicit version provided.
version = self.version.lower()
potential_name = f"{base_name}_{version}"
return (
Expand All @@ -63,7 +63,10 @@ def _get_api_metric_spec_name(self) -> Optional[str]:
else None
)
else:
# Default versioning: Try _v1, then base name
# No version specified: resolve to the latest available version,
# falling back to _v1, then the bare base name.
if base_name in _evals_constant.METRIC_LATEST_SPEC_NAME:
return _evals_constant.METRIC_LATEST_SPEC_NAME[base_name]
v1_name = f"{base_name}_v1"
if v1_name in _evals_constant.SUPPORTED_PREDEFINED_METRICS:
return v1_name
Expand Down
Loading