Skip to content

Commit 58ba55e

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add browse pre-built metrics button for Ipython environments when listing example metrics for Gen AI Evaluation
PiperOrigin-RevId: 698905517
1 parent 905c766 commit 58ba55e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

google/cloud/aiplatform/utils/_ipython_utils.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ def display_link(text: str, url: str, icon: Optional[str] = "open_in_new") -> No
110110
Dict of custom properties with keys mapped to column names
111111
"""
112112
CLOUD_UI_URL = "https://console.cloud.google.com"
113-
if not url.startswith(CLOUD_UI_URL):
114-
raise ValueError(f"Only urls starting with {CLOUD_UI_URL} are allowed.")
113+
CLOUD_DOCS_URL = "https://cloud.google.com"
114+
if not (url.startswith(CLOUD_UI_URL) or url.startswith(CLOUD_DOCS_URL)):
115+
raise ValueError(
116+
f"Only urls starting with {CLOUD_UI_URL} or {CLOUD_DOCS_URL} are allowed."
117+
)
115118

116119
button_id = f"view-vertex-resource-{str(uuid4())}"
117120

@@ -252,3 +255,14 @@ def display_model_tuning_button(tuning_job: "sft.SupervisedTuningJob") -> None:
252255
+ f"?project={project}"
253256
)
254257
display_link("View Tuning Job", uri, "tune")
258+
259+
260+
def display_browse_prebuilt_metrics_button() -> None:
261+
"""Function to generate a link to the Gen AI Evaluation pre-built metrics page."""
262+
if not is_ipython_available():
263+
return
264+
265+
uri = (
266+
"https://cloud.google.com/vertex-ai/generative-ai/docs/models/metrics-templates"
267+
)
268+
display_link("Browse pre-built metrics", uri, "list")

vertexai/evaluation/metrics/metric_prompt_template_examples.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from typing import List
2020

21+
from google.cloud.aiplatform.utils import _ipython_utils
2122
from vertexai.evaluation import constants
2223
from vertexai.evaluation.metrics import (
2324
_default_templates,
@@ -98,6 +99,7 @@ def get_prompt_template(cls, metric_name: str) -> str:
9899
@classmethod
99100
def list_example_metric_names(cls) -> List[str]:
100101
"""Returns a list of all metric prompt templates."""
102+
_ipython_utils.display_browse_prebuilt_metrics_button()
101103
return list(cls._PROMPT_TEMPLATE_MAP.keys())
102104

103105
class Pointwise:

0 commit comments

Comments
 (0)