שיפור מודל ליצירת קוד

שיפור מודל ליצירת קוד שעבר אימון מראש.

דוגמת קוד

Python

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

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

from __future__ import annotations

import os

import vertexai
from vertexai.language_models import CodeGenerationModel

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")


def tune_code_generation_model() -> CodeGenerationModel:
    # Initialize Vertex AI
    vertexai.init(project=PROJECT_ID, location="us-central1")

    model = CodeGenerationModel.from_pretrained("code-bison@002")

    # TODO(developer): Update the training data path
    tuning_job = model.tune_model(
        training_data="gs://cloud-samples-data/ai-platform/generative_ai/headline_classification.jsonl",
        tuning_job_location="europe-west4",
        tuned_model_location="us-central1",
    )

    print(tuning_job._status)
    # Example response:
    # ...
    # pipeline_job = aiplatform.PipelineJob.get('projects/1234567890/locations/europe-west4/pipelineJobs/tune...
    # PipelineState.PIPELINE_STATE_PENDING
    return model

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

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