אופטימיזציה של הנחיות ליצירת טקסט באמצעות Vertex AI

בדוגמה הזו נדגים איך להשתמש ב-Vertex AI Prompt Optimizer כדי לבצע אופטימיזציה של הנחיות למודל ליצירת טקסט.

דוגמת קוד

Python

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Pythonההוראות להגדרה במאמר Vertex AI quickstart using client libraries. מידע נוסף מופיע במאמרי העזרה של Vertex AI Python API.

כדי לבצע אימות ב-Vertex AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

from google.cloud import aiplatform

# Initialize Vertex AI platform
aiplatform.init(project=PROJECT_ID, location="us-central1")

# TODO(Developer): Check and update lines below
# cloud_bucket = "gs://cloud-samples-data"
# config_path = f"{cloud_bucket}/instructions/sample_configuration.json"
# output_path = "custom_job/output/"

custom_job = aiplatform.CustomJob(
    display_name="Prompt Optimizer example",
    worker_pool_specs=[
        {
            "replica_count": 1,
            "container_spec": {
                "image_uri": "us-docker.pkg.dev/vertex-ai-restricted/builtin-algorithm/apd:preview_v1_0",
                "args": [f"--config={cloud_bucket}/{config_path}"],
            },
            "machine_spec": {
                "machine_type": "n1-standard-4",
            },
        }
    ],
    staging_bucket=cloud_bucket,
    base_output_dir=f"{cloud_bucket}/{output_path}",
)

custom_job.submit()
print(f"Job resource name: {custom_job.resource_name}")
# Example response:
#    'projects/123412341234/locations/us-central1/customJobs/12341234123412341234'

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

כדי לחפש ולסנן דוגמאות קוד למוצרים אחרים של Google Cloud , אפשר להיעזר בGoogle Cloud דפדפן לדוגמה.