Questa pagina mostra come valutare i modelli e le applicazioni di AI generativa in una serie di casi d'uso utilizzando il client GenAI nell'SDK Vertex AI.
Prima di iniziare
-
Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
Installa l'SDK Vertex AI Python:
!pip install google-cloud-aiplatform[evaluation]
Configura le tue credenziali. Se esegui questo tutorial in Colaboratory, esegui il seguente comando:
from google.colab import auth auth.authenticate_user()
Per altri ambienti, consulta Autenticazione in Vertex AI.
Prepara il set di dati come DataFrame Pandas:
import pandas as pd eval_df = pd.DataFrame({ "prompt": [ "Explain software 'technical debt' using a concise analogy of planting a garden.", "Write a Python function to find the nth Fibonacci number using recursion with memoization, but without using any imports.", "Write a four-line poem about a lonely robot, where every line must be a question and the word 'and' cannot be used.", "A drawer has 10 red socks and 10 blue socks. In complete darkness, what is the minimum number of socks you must pull out to guarantee you have a matching pair?", "An AI discovers a cure for a major disease, but the cure is based on private data it analyzed without consent. Should the cure be released? Justify your answer." ] })
Genera risposte del modello utilizzando
run_inference()
:eval_dataset = client.evals.run_inference( model="gemini-2.5-flash", src=eval_df, )
Visualizza i risultati dell'inferenza chiamando
.show()
sull'oggettoEvaluationDataset
per esaminare gli output del modello insieme ai prompt e ai riferimenti originali:eval_dataset.show()
Valuta le risposte del modello utilizzando la metrica adattiva basata su rubrica predefinita
GENERAL_QUALITY
:eval_result = client.evals.evaluate(dataset=eval_dataset)
Visualizza i risultati della valutazione chiamando
.show()
sull'oggettoEvaluationResult
per visualizzare le metriche di riepilogo e i risultati dettagliati:eval_result.show()
Generare risposte
Genera le risposte del modello per il tuo set di dati utilizzando run_inference()
:
La seguente immagine mostra il set di dati di valutazione con i prompt e le risposte generate corrispondenti:
Esegui la valutazione
Esegui evaluate()
per valutare le risposte del modello:
L'immagine seguente mostra un report di valutazione, che mostra le metriche di riepilogo e i risultati dettagliati per ogni coppia prompt-risposta.
Esegui la pulizia
Durante questo tutorial non vengono create risorse Vertex AI.