This document guides you through setting up a Google Cloud Platform (GCP) environment, connecting to Vertex AI, and consuming a BISON model using the REST API.
Prerequisites:
- A Google account
- A new Google Cloud Platform (GCP) subscription (https://cloud.google.com/)
- A service account with the necessary permissions
Step 1: Create a Google Cloud Project
- Go to the Google Cloud Console.
- Click on “Create Project”.
- Enter a project name and click on “Create.”
Step 2: Enable the Vertex AI API
- Search for Vertex AI from the global search bar and activate the API if it’s your first time using it.
- GPTfy will use foundation models, so no custom model deployment is needed.
Step 3: View Details
- Navigate to the next option by clicking on View Details.
Step 4: Test Vertex AI on the Playground (Optional)
- Click on Open Prompt Design
- Ask a question on the next screen. If you receive answers, then the model setup is complete.
Step 5: Create a Service Account
- Go to the IAM & Admin page.
- Click on “Create Service Account”.
- Enter a service account name and click on “Create.”
- Grant the service account the following roles:
- Vertex AI Service Agent (roles/aiplatform.serviceAgent)
- Cloud Storage Object Creator (roles/storage.objectCreator)
Step 6: Download the Service Account Key
- Click on the service account you created.
- Click on the “Keys” tab.
- Click on “Add Key” and select “JSON”.
- Download the JSON key file. (KEEP IT SECURE)
Step 7: Consume the Model through REST API (Optional)
- Use the following cURL command to consume the model:
API_ENDPOINT="us-central1-aiplatform.googleapis.com"
PROJECT_ID="gptfy-ai-playground"
MODEL_ID="text-bison-32x"
LOCATION_ID="us-central1"
curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://${API_ENDPOINT}/v1/projects/${PROJECT_ID}/locations/${LOCATION_ID}/publishers/google/models/${MODEL_ID}:predict" \
-d @request.json
Replace {PROJECT_ID}, {LOCATION_ID}, {MODEL_ID}, and {API_ENDPOINT} with the appropriate values. Replace $(gcloud auth print-access-token) with the access token obtained from the service account key.
Additional Notes
- The service account key should be stored securely.
- The model URI must be a Google Cloud Storage URI.
- The model must be in the same region as the endpoint.
- The REST API endpoint URL may vary depending on the region.