knitr::opts_chunk$set(echo = TRUE)
library(googleAuthR)
library(googleCloudVertexAIR)

options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/cloud-platform")

gar_auth_service(json_file = Sys.getenv("GAR_SERVICE_JSON"))

Set global arguements

projectId <- Sys.getenv("GCVA_DEFAULT_PROJECT_ID")
gcva_region_set(region = "us-central1")
gcva_project_set(projectId = projectId)
# hard code model that we know has a state = completed for demonstration purposes.
(model <- Sys.getenv("GCVA_TEST_MODEL_NAME"))

Make the batch prediction request

set constants

(bq_source_uri <- sprintf("bq://%s.california_housing.batch_02", projectId))
(bq_destination_prefix <- sprintf("bq://%s.california_housing", projectId))

execute request

batch_prediction_job <- gcva_batch_predict(
  jobDisplayName = "california-housing-batch-02",
  model = model, 
  bigquerySource = bq_source_uri,
  instancesFormat = "bigquery",
  predictionsFormat = "bigquery",
  bigqueryDestinationPrefix = bq_destination_prefix
)

batch_prediction_job

Get a batch prediction job

To view more details and current state.

gcva_batch_prediction_job(
  batchPredictionJob = Sys.getenv("GCVA_BATCH_PREDICTION")
  )


justinjm/googleCloudVertexAIR documentation built on April 17, 2025, 5:04 p.m.