הדרכה: ביצוע הערכה באמצעות GenAI Client ב-Agent Platform SDK

בדף הזה מוסבר איך להעריך את המודלים והאפליקציות שלכם ל-AI גנרטיבי במגוון תרחישים לדוגמה, באמצעות GenAI Client ב-Agent Platform SDK.

לפני שמתחילים

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

    Verify that billing is enabled for your Cloud de Confiance project.

  2. מתקינים את Agent Platform SDK:

    !pip install google-cloud-aiplatform[evaluation]
    
  3. מגדירים את פרטי הכניסה. אם אתם מריצים את המדריך הזה ב-Colaboratory, הריצו את הפקודה הבאה:

    from google.colab import auth
    auth.authenticate_user()
    

    בסביבות אחרות, אפשר לעיין במאמר אימות ב-Agent Platform.

הפעלת לקוח ה-AI הגנרטיבי

כדי לאתחל את לקוח GenAI, מריצים את הפקודה הבאה:

from vertexai import Client

client = Client(project="YOUR_PROJECT_ID", location="YOUR_LOCATION")

כאשר:

  • ‫YOUR_PROJECT_ID: מזהה הפרויקט ב- Cloud de Confiance by S3NS .
  • ‫YOUR_LOCATION: האזור בענן, לדוגמה us-central1.

יצירת תשובות

יוצרים תשובות של המודל למערך הנתונים באמצעות run_inference():

  1. מכינים את מערך הנתונים בתור Pandas DataFrame:

    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."
      ]
    })
    
  2. יוצרים תשובות של המודל באמצעות run_inference():

    eval_dataset = client.evals.run_inference(
      model="gemini-2.5-flash",
      src=eval_df,
    )
    
  3. הצגת תוצאות ההסקה: מפעילים את .show() באובייקט EvaluationDataset כדי לבדוק את הפלט של המודל לצד ההנחיות וההפניות המקוריות:

    eval_dataset.show()
    

בתמונה הבאה מוצגת קבוצת הנתונים להערכה עם הנחיות והתשובות שנוצרו בהתאם:

טבלה שמוצגת בה קבוצת נתונים להערכה עם עמודות של הנחיות ותשובות.

הרצת ההערכה

מריצים את evaluate() כדי להעריך את התשובות של המודל:

  1. מעריכים את התשובות של המודל באמצעות GENERAL_QUALITY מדד ברירת המחדל שמבוסס על רובריקה דינמית:

    eval_result = client.evals.evaluate(dataset=eval_dataset)
    
  2. הצגת תוצאות ההערכה: מפעילים את .show() באובייקט EvaluationResult כדי להציג מדדי סיכום ותוצאות מפורטות:

    eval_result.show()
    

בתמונה הבאה מוצג דוח הערכה, שכולל מדדי סיכום ותוצאות מפורטות לכל צמד של הנחיה ותשובה.

דוח הערכה שמוצגים בו מדדי סיכום לצד תוצאות מפורטות לכל צמד של הנחיה ותשובה.

הסרת המשאבים

במדריך הזה לא נוצרים משאבים של Gemini Enterprise Agent Platform.

המאמרים הבאים