Skip to content

Commit e8baf65

Browse files
authored
feat: publish new GenAI Eval Service SDK for Google Observability public tutorial (#2383)
1 parent 89d460a commit e8baf65

File tree

1 file changed

+285
-0
lines changed

1 file changed

+285
-0
lines changed
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"id": "ur8xi4C7S06n"
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Copyright 2025 Google LLC\n",
12+
"#\n",
13+
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
14+
"# you may not use this file except in compliance with the License.\n",
15+
"# You may obtain a copy of the License at\n",
16+
"#\n",
17+
"# https://www.apache.org/licenses/LICENSE-2.0\n",
18+
"#\n",
19+
"# Unless required by applicable law or agreed to in writing, software\n",
20+
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
21+
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
22+
"# See the License for the specific language governing permissions and\n",
23+
"# limitations under the License."
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"metadata": {
29+
"id": "JAPoU8Sm5E6e"
30+
},
31+
"source": [
32+
"# Using Gen AI Evaluation SDK for Google Observability Gen AI multi-modal datasets\n",
33+
"\n",
34+
"<table align=\"left\">\n",
35+
" <td style=\"text-align: center\">\n",
36+
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/gemini/evaluation/evaluating_observability_datasets.ipynb\">\n",
37+
" <img width=\"32px\" src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Google Colaboratory logo\"><br> Open in Colab\n",
38+
" </a>\n",
39+
" </td>\n",
40+
" <td style=\"text-align: center\">\n",
41+
" <a href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fgemini%2Fevaluation%2Fevaluating_observability_datasets.ipynb\">\n",
42+
" <img width=\"32px\" src=\"https://lh3.googleusercontent.com/JmcxdQi-qOpctIvWKgPtrzZdJJK-J3sWE1RsfjZNwshCFgE_9fULcNpuXYTilIR2hjwN\" alt=\"Google Cloud Colab Enterprise logo\"><br> Open in Colab Enterprise\n",
43+
" </a>\n",
44+
" </td>\n",
45+
" <td style=\"text-align: center\">\n",
46+
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/gemini/evaluation/evaluating_observability_datasets.ipynb\">\n",
47+
" <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\"><br> Open in Vertex AI Workbench\n",
48+
" </a>\n",
49+
" </td>\n",
50+
" <td style=\"text-align: center\">\n",
51+
" <a href=\"https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/evaluation/evaluating_observability_datasets.ipynb\">\n",
52+
" <img width=\"32px\" src=\"https://storage.googleapis.com/github-repo/generative-ai/logos/GitHub_Invertocat_Dark.svg\" alt=\"GitHub logo\"><br> View on GitHub\n",
53+
" </a>\n",
54+
" </td>\n",
55+
"</table>\n",
56+
"\n",
57+
"<div style=\"clear: both;\"></div>\n",
58+
"\n",
59+
"<p>\n",
60+
"<b>Share to:</b>\n",
61+
"\n",
62+
"<a href=\"https://www.linkedin.com/sharing/share-offsite/?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/evaluation/evaluating_observability_datasets.ipynb\" target=\"_blank\">\n",
63+
" <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/8/81/LinkedIn_icon.svg\" alt=\"LinkedIn logo\">\n",
64+
"</a>\n",
65+
"\n",
66+
"<a href=\"https://bsky.app/intent/compose?text=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/evaluation/evaluating_observability_datasets.ipynb\" target=\"_blank\">\n",
67+
" <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/7/7a/Bluesky_Logo.svg\" alt=\"Bluesky logo\">\n",
68+
"</a>\n",
69+
"\n",
70+
"<a href=\"https://twitter.com/intent/tweet?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/evaluation/evaluating_observability_datasets.ipynb\" target=\"_blank\">\n",
71+
" <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/5/5a/X_icon_2.svg\" alt=\"X logo\">\n",
72+
"</a>\n",
73+
"\n",
74+
"<a href=\"https://reddit.com/submit?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/evaluation/evaluating_observability_datasets.ipynb\" target=\"_blank\">\n",
75+
" <img width=\"20px\" src=\"https://redditinc.com/hubfs/Reddit%20Inc/Brand/Reddit_Logo.png\" alt=\"Reddit logo\">\n",
76+
"</a>\n",
77+
"\n",
78+
"<a href=\"https://www.facebook.com/sharer/sharer.php?u=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/evaluation/evaluating_observability_datasets.ipynb\" target=\"_blank\">\n",
79+
" <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg\" alt=\"Facebook logo\">\n",
80+
"</a>\n",
81+
"</p>"
82+
]
83+
},
84+
{
85+
"cell_type": "markdown",
86+
"metadata": {
87+
"id": "84f0f73a0f76"
88+
},
89+
"source": [
90+
"| Author |\n",
91+
"| --- |\n",
92+
"| [Matthew Yun](https://github.com/matty3) |"
93+
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {
98+
"id": "tvgnzT1CKxrO"
99+
},
100+
"source": [
101+
"## Overview\n",
102+
"\n",
103+
"This notebook demonstrates how users can use the [Vertex AI SDK Gen AI evaluation service](https://github.com/googleapis/python-aiplatform) for evaluating your Gen AI multimodal content stored in [Google Observability](https://cloud.google.com/stackdriver/docs).\n",
104+
"\n",
105+
"The Vertex AI SDK allows users to run evaluations on their Gen AI models prompts and responses. This now includes the ability for users to run evaluations against the Gen AI data that has been stored in Google Cloud Storage (GCS) within Observability following [OpenTelemetry semantic conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/).\n",
106+
"\n",
107+
"Prompt, response, and system instruction data in Google Observability are stored in separate GCS references. This notebook gives an example for how users can read in their data from GCS and run an evaluation using the Vertex AI SDK."
108+
]
109+
},
110+
{
111+
"cell_type": "markdown",
112+
"metadata": {
113+
"id": "61RBz8LLbxCR"
114+
},
115+
"source": [
116+
"## Get started"
117+
]
118+
},
119+
{
120+
"cell_type": "markdown",
121+
"metadata": {
122+
"id": "No17Cw5hgx12"
123+
},
124+
"source": [
125+
"### Install Vertex AI SDK for Gen AI Evaluation Service\n"
126+
]
127+
},
128+
{
129+
"cell_type": "code",
130+
"execution_count": null,
131+
"metadata": {
132+
"id": "tFy3H3aPgx12"
133+
},
134+
"outputs": [],
135+
"source": [
136+
"%pip install --upgrade \"google-cloud-aiplatform[evaluation]>=1.111.0\" --force-reinstall --quiet --no-warn-conflicts"
137+
]
138+
},
139+
{
140+
"cell_type": "markdown",
141+
"metadata": {
142+
"id": "dmWOrTJ3gx13"
143+
},
144+
"source": [
145+
"### Authenticate your notebook environment (Colab only)\n",
146+
"\n",
147+
"If you're running this notebook on Google Colab, run the cell below to authenticate your environment."
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"metadata": {
154+
"id": "NyKGtVQjgx13"
155+
},
156+
"outputs": [],
157+
"source": [
158+
"import sys\n",
159+
"\n",
160+
"if \"google.colab\" in sys.modules:\n",
161+
" from google.colab import auth\n",
162+
"\n",
163+
" auth.authenticate_user()"
164+
]
165+
},
166+
{
167+
"cell_type": "markdown",
168+
"metadata": {
169+
"id": "DF4l8DTdWgPY"
170+
},
171+
"source": [
172+
"### Set Google Cloud project information\n",
173+
"\n",
174+
"To get started using Vertex AI, you must have an existing Google Cloud project and [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
175+
"\n",
176+
"Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)."
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": null,
182+
"metadata": {
183+
"id": "Nqwi-5ufWp_B"
184+
},
185+
"outputs": [],
186+
"source": [
187+
"# Use the environment variable if the user doesn't provide Project ID.\n",
188+
"import os\n",
189+
"\n",
190+
"# fmt: off\n",
191+
"PROJECT_ID = \"\" # @param {type: \"string\", placeholder: \"[your-project-id]\", isTemplate: true}\n",
192+
"if not PROJECT_ID or PROJECT_ID == \"[your-project-id]\":\n",
193+
" PROJECT_ID = str(os.environ.get(\"GOOGLE_CLOUD_PROJECT\"))\n",
194+
"LOCATION = \"us-central1\" # @param {type: \"string\", placeholder: \"us-central1\", isTemplate: true}\n",
195+
"# fmt: on\n",
196+
"LOCATION = os.environ.get(\"GOOGLE_CLOUD_REGION\", LOCATION)\n",
197+
"\n",
198+
"from vertexai import Client, types\n",
199+
"\n",
200+
"client = Client(project=PROJECT_ID, location=LOCATION)"
201+
]
202+
},
203+
{
204+
"cell_type": "markdown",
205+
"metadata": {
206+
"id": "EdvJRUWRNGHE"
207+
},
208+
"source": [
209+
"## Evaluation Dataset"
210+
]
211+
},
212+
{
213+
"cell_type": "markdown",
214+
"metadata": {
215+
"id": "e43229f3ad4f"
216+
},
217+
"source": [
218+
"### Load in Google Observability Gen AI dataset\n",
219+
"\n",
220+
"We will need to read in the data stored in Google Cloud Storage and prepare for evaluation."
221+
]
222+
},
223+
{
224+
"cell_type": "code",
225+
"execution_count": null,
226+
"metadata": {
227+
"id": "cf93d5f0ce00"
228+
},
229+
"outputs": [],
230+
"source": [
231+
"# fmt: off\n",
232+
"INPUT_SOURCE = \"\" # @param {type: \"string\", placeholder: \"[your-input-source]\", isTemplate: true}\n",
233+
"OUTPUT_SOURCE = \"\" # @param {type: \"string\", placeholder: \"[your-output-source]\", isTemplate: true}\n",
234+
"SYSTEM_INSTRUCTION_SOURCE = \"\" # @param {type: \"string\", placeholder: \"[your-system-instruction-source]\", isTemplate: true}\n",
235+
"# fmt: on\n",
236+
"\n",
237+
"eval_case = types.ObservabilityEvalCase(\n",
238+
" input_src=INPUT_SOURCE,\n",
239+
" output_src=OUTPUT_SOURCE,\n",
240+
" system_instruction_src=SYSTEM_INSTRUCTION_SOURCE,\n",
241+
" api_client=client,\n",
242+
")\n",
243+
"eval_dataset = types.EvaluationDataset.load_from_observability_eval_cases([eval_case])\n",
244+
"\n",
245+
"eval_dataset.show()"
246+
]
247+
},
248+
{
249+
"cell_type": "markdown",
250+
"metadata": {
251+
"id": "2a4e033321ad"
252+
},
253+
"source": [
254+
"### Run Evaluation\n",
255+
"\n",
256+
"Evaluate the responses using the `GENERAL_QUALITY` adaptive rubric-based metric by default."
257+
]
258+
},
259+
{
260+
"cell_type": "code",
261+
"execution_count": null,
262+
"metadata": {
263+
"id": "3SWzCOUt21t9"
264+
},
265+
"outputs": [],
266+
"source": [
267+
"eval_result = client.evals.evaluate(dataset=eval_dataset)\n",
268+
"\n",
269+
"eval_result.show()"
270+
]
271+
}
272+
],
273+
"metadata": {
274+
"colab": {
275+
"name": "evaluating_observability_datasets.ipynb",
276+
"toc_visible": true
277+
},
278+
"kernelspec": {
279+
"display_name": "Python 3",
280+
"name": "python3"
281+
}
282+
},
283+
"nbformat": 4,
284+
"nbformat_minor": 0
285+
}

0 commit comments

Comments
 (0)