From b1502b815b2c06b6c9aef6b636b2ab9e46794d04 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Tue, 24 Nov 2026 17:37:46 +0000 Subject: [PATCH] chore(aiplatform): decommission batch prediction samples --- .../aiplatform/BatchCodePredictionSample.java | 110 ----------------- .../aiplatform/BatchTextPredictionSample.java | 115 ------------------ .../PredictCodeCompletionCommentSample.java | 96 --------------- .../BatchCodePredictionSampleTest.java | 86 ------------- .../BatchTextPredictionSampleTest.java | 85 ------------- ...redictCodeCompletionCommentSampleTest.java | 90 -------------- 6 files changed, 582 deletions(-) delete mode 100644 aiplatform/src/main/java/aiplatform/BatchCodePredictionSample.java delete mode 100644 aiplatform/src/main/java/aiplatform/BatchTextPredictionSample.java delete mode 100644 aiplatform/src/main/java/aiplatform/PredictCodeCompletionCommentSample.java delete mode 100644 aiplatform/src/test/java/aiplatform/BatchCodePredictionSampleTest.java delete mode 100644 aiplatform/src/test/java/aiplatform/BatchTextPredictionSampleTest.java delete mode 100644 aiplatform/src/test/java/aiplatform/PredictCodeCompletionCommentSampleTest.java diff --git a/aiplatform/src/main/java/aiplatform/BatchCodePredictionSample.java b/aiplatform/src/main/java/aiplatform/BatchCodePredictionSample.java deleted file mode 100644 index 293ec211aa1..00000000000 --- a/aiplatform/src/main/java/aiplatform/BatchCodePredictionSample.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package aiplatform; - -// [START generativeaionvertexai_batch_code_predict] - -import com.google.cloud.aiplatform.v1.BatchPredictionJob; -import com.google.cloud.aiplatform.v1.GcsDestination; -import com.google.cloud.aiplatform.v1.GcsSource; -import com.google.cloud.aiplatform.v1.JobServiceClient; -import com.google.cloud.aiplatform.v1.JobServiceSettings; -import com.google.cloud.aiplatform.v1.LocationName; -import com.google.gson.Gson; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.Value; -import com.google.protobuf.util.JsonFormat; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -public class BatchCodePredictionSample { - - public static void main(String[] args) throws IOException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String project = "YOUR_PROJECT_ID"; - String location = "us-central1"; - // inputUri: URI of the input dataset. - // Could be a BigQuery table or a Google Cloud Storage file. - // E.g. "gs://[BUCKET]/[DATASET].jsonl" OR "bq://[PROJECT].[DATASET].[TABLE]" - String inputUri = "gs://cloud-samples-data/batch/prompt_for_batch_code_predict.jsonl"; - // outputUri: URI where the output will be stored. - // Could be a BigQuery table or a Google Cloud Storage file. - // E.g. "gs://[BUCKET]/[OUTPUT].jsonl" OR "bq://[PROJECT].[DATASET].[TABLE]" - String outputUri = "gs://YOUR_BUCKET/batch_code_predict_output"; - String codeModel = "code-bison"; - - batchCodePredictionSample(project, location, inputUri, outputUri, codeModel); - } - - // Perform batch code prediction using a pre-trained code generation model. - // Example of using Google Cloud Storage bucket as the input and output data source - public static BatchPredictionJob batchCodePredictionSample( - String project, String location, String inputUri, String outputUri, String codeModel) - throws IOException { - BatchPredictionJob response; - JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder() - .setEndpoint("us-central1-aiplatform.googleapis.com:443").build(); - LocationName parent = LocationName.of(project, location); - String modelName = String.format( - "projects/%s/locations/%s/publishers/google/models/%s", project, location, codeModel); - // Construct your modelParameters - Map modelParameters = new HashMap<>(); - modelParameters.put("maxOutputTokens", "200"); - modelParameters.put("temperature", "0.2"); - modelParameters.put("topP", "0.95"); - modelParameters.put("topK", "40"); - Value parameterValue = mapToValue(modelParameters); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. - try (JobServiceClient client = JobServiceClient.create(jobServiceSettings)) { - BatchPredictionJob batchPredictionJob = - BatchPredictionJob.newBuilder() - .setDisplayName("my batch code prediction job " + System.currentTimeMillis()) - .setModel(modelName) - .setInputConfig( - BatchPredictionJob.InputConfig.newBuilder() - .setGcsSource(GcsSource.newBuilder().addUris(inputUri).build()) - .setInstancesFormat("jsonl") - .build()) - .setOutputConfig( - BatchPredictionJob.OutputConfig.newBuilder() - .setGcsDestination(GcsDestination.newBuilder() - .setOutputUriPrefix(outputUri).build()) - .setPredictionsFormat("jsonl") - .build()) - .setModelParameters(parameterValue) - .build(); - - response = client.createBatchPredictionJob(parent, batchPredictionJob); - - System.out.format("response: %s\n", response); - System.out.format("\tName: %s\n", response.getName()); - } - return response; - } - - private static Value mapToValue(Map map) throws InvalidProtocolBufferException { - Gson gson = new Gson(); - String json = gson.toJson(map); - Value.Builder builder = Value.newBuilder(); - JsonFormat.parser().merge(json, builder); - return builder.build(); - } -} -// [END generativeaionvertexai_batch_code_predict] diff --git a/aiplatform/src/main/java/aiplatform/BatchTextPredictionSample.java b/aiplatform/src/main/java/aiplatform/BatchTextPredictionSample.java deleted file mode 100644 index 695b7fd460c..00000000000 --- a/aiplatform/src/main/java/aiplatform/BatchTextPredictionSample.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package aiplatform; - -// [START generativeaionvertexai_batch_text_predict] - -import com.google.cloud.aiplatform.v1.BatchPredictionJob; -import com.google.cloud.aiplatform.v1.GcsDestination; -import com.google.cloud.aiplatform.v1.GcsSource; -import com.google.cloud.aiplatform.v1.JobServiceClient; -import com.google.cloud.aiplatform.v1.JobServiceSettings; -import com.google.gson.Gson; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.Value; -import com.google.protobuf.util.JsonFormat; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -public class BatchTextPredictionSample { - - public static void main(String[] args) - throws IOException, InterruptedException, ExecutionException, TimeoutException { - // TODO(developer): Replace these variables before running the sample. - String project = "YOUR_PROJECT_ID"; - String location = "us-central1"; - // inputUri: URI of the input dataset. - // Could be a BigQuery table or a Google Cloud Storage file. - // E.g. "gs://[BUCKET]/[DATASET].jsonl" OR "bq://[PROJECT].[DATASET].[TABLE]" - String inputUri = "gs://cloud-samples-data/batch/prompt_for_batch_text_predict.jsonl"; - // outputUri: URI where the output will be stored. - // Could be a BigQuery table or a Google Cloud Storage file. - // E.g. "gs://[BUCKET]/[OUTPUT].jsonl" OR "bq://[PROJECT].[DATASET].[TABLE]" - String outputUri = "gs://YOUR_BUCKET/batch_text_predict_output"; - String textModel = "text-bison"; - - batchTextPrediction(project, inputUri, outputUri, textModel, location); - } - - // Perform batch text prediction using a pre-trained text generation model. - // Example of using Google Cloud Storage bucket as the input and output data source - static BatchPredictionJob batchTextPrediction( - String projectId, String inputUri, String outputUri, String textModel, String location) - throws IOException { - BatchPredictionJob response; - JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder() - .setEndpoint("us-central1-aiplatform.googleapis.com:443").build(); - String parent = String.format("projects/%s/locations/%s", projectId, location); - String modelName = String.format( - "projects/%s/locations/%s/publishers/google/models/%s", projectId, location, textModel); - // Construct model parameters - Map modelParameters = new HashMap<>(); - modelParameters.put("maxOutputTokens", "200"); - modelParameters.put("temperature", "0.2"); - modelParameters.put("topP", "0.95"); - modelParameters.put("topK", "40"); - Value parameterValue = mapToValue(modelParameters); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. - try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) { - - BatchPredictionJob batchPredictionJob = - BatchPredictionJob.newBuilder() - .setDisplayName("my batch text prediction job " + System.currentTimeMillis()) - .setModel(modelName) - .setInputConfig( - BatchPredictionJob.InputConfig.newBuilder() - .setGcsSource(GcsSource.newBuilder().addUris(inputUri).build()) - .setInstancesFormat("jsonl") - .build()) - .setOutputConfig( - BatchPredictionJob.OutputConfig.newBuilder() - .setGcsDestination(GcsDestination.newBuilder() - .setOutputUriPrefix(outputUri).build()) - .setPredictionsFormat("jsonl") - .build()) - .setModelParameters(parameterValue) - .build(); - - // Create the batch prediction job - response = - jobServiceClient.createBatchPredictionJob(parent, batchPredictionJob); - - System.out.format("response: %s\n", response); - System.out.format("\tName: %s\n", response.getName()); - } - return response; - } - - private static Value mapToValue(Map map) throws InvalidProtocolBufferException { - Gson gson = new Gson(); - String json = gson.toJson(map); - Value.Builder builder = Value.newBuilder(); - JsonFormat.parser().merge(json, builder); - return builder.build(); - } -} -// [END generativeaionvertexai_batch_text_predict] diff --git a/aiplatform/src/main/java/aiplatform/PredictCodeCompletionCommentSample.java b/aiplatform/src/main/java/aiplatform/PredictCodeCompletionCommentSample.java deleted file mode 100644 index e4f60d93091..00000000000 --- a/aiplatform/src/main/java/aiplatform/PredictCodeCompletionCommentSample.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package aiplatform; - -// [START aiplatform_sdk_code_completion_comment] -// [START generativeaionvertexai_sdk_code_completion_comment] - -import com.google.cloud.aiplatform.v1.EndpointName; -import com.google.cloud.aiplatform.v1.PredictResponse; -import com.google.cloud.aiplatform.v1.PredictionServiceClient; -import com.google.cloud.aiplatform.v1.PredictionServiceSettings; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.Value; -import com.google.protobuf.util.JsonFormat; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class PredictCodeCompletionCommentSample { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace this variable before running the sample. - String project = "YOUR_PROJECT_ID"; - - // Learn how to create prompts to work with a code model to create code completion suggestions: - // https://cloud.google.com/vertex-ai/docs/generative-ai/code/code-completion-prompts - String instance = - "{ \"prefix\": \"" - + "def reverse_string(s):\n" - + " return s[::-1]\n" - + "#This function" - + "\"}"; - String parameters = "{\n" + " \"temperature\": 0.2,\n" + " \"maxOutputTokens\": 64,\n" + "}"; - String location = "us-central1"; - String publisher = "google"; - String model = "code-gecko@001"; - - predictComment(instance, parameters, project, location, publisher, model); - } - - // Use Codey for Code Completion to complete a code comment - public static void predictComment( - String instance, - String parameters, - String project, - String location, - String publisher, - String model) - throws IOException { - final String endpoint = String.format("%s-aiplatform.googleapis.com:443", location); - PredictionServiceSettings predictionServiceSettings = - PredictionServiceSettings.newBuilder().setEndpoint(endpoint).build(); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. - try (PredictionServiceClient predictionServiceClient = - PredictionServiceClient.create(predictionServiceSettings)) { - final EndpointName endpointName = - EndpointName.ofProjectLocationPublisherModelName(project, location, publisher, model); - - Value instanceValue = stringToValue(instance); - List instances = new ArrayList<>(); - instances.add(instanceValue); - - Value parameterValue = stringToValue(parameters); - - PredictResponse predictResponse = - predictionServiceClient.predict(endpointName, instances, parameterValue); - System.out.println("Predict Response"); - System.out.println(predictResponse); - } - } - - // Convert a Json string to a protobuf.Value - static Value stringToValue(String value) throws InvalidProtocolBufferException { - Value.Builder builder = Value.newBuilder(); - JsonFormat.parser().merge(value, builder); - return builder.build(); - } -} -// [END aiplatform_sdk_code_completion_comment] -// [END generativeaionvertexai_sdk_code_completion_comment] diff --git a/aiplatform/src/test/java/aiplatform/BatchCodePredictionSampleTest.java b/aiplatform/src/test/java/aiplatform/BatchCodePredictionSampleTest.java deleted file mode 100644 index f33d8327797..00000000000 --- a/aiplatform/src/test/java/aiplatform/BatchCodePredictionSampleTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package aiplatform; - -import static junit.framework.TestCase.assertNotNull; -import static org.junit.Assert.assertTrue; - -import com.google.cloud.aiplatform.v1.BatchPredictionJob; -import com.google.cloud.storage.Bucket; -import com.google.cloud.storage.BucketInfo; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageOptions; -import java.io.IOException; -import java.util.UUID; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class BatchCodePredictionSampleTest { - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String LOCATION = "us-central1"; - private static String BUCKET_NAME; - private static final String GCS_SOURCE_URI = - "gs://cloud-samples-data/batch/prompt_for_batch_code_predict.jsonl"; - private static final String GCS_DESTINATION_OUTPUT_PREFIX = - String.format("gs://%s/batch-code-predict", BUCKET_NAME); - private static final String MODEL_ID = "code-bison"; - static Storage storage; - static Bucket bucket; - - private static void requireEnvVar(String varName) { - String errorMessage = - String.format("Environment variable '%s' is required to perform these tests.", varName); - assertNotNull(errorMessage, System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() throws IOException { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - BUCKET_NAME = "my-new-test-bucket" + UUID.randomUUID(); - - // Create a Google Cloud Storage bucket for UsageReports - storage = StorageOptions.newBuilder().setProjectId(PROJECT_ID).build().getService(); - storage.create(BucketInfo.of(BUCKET_NAME)); - } - - @AfterClass - public static void afterClass() { - // Delete the Google Cloud Storage bucket created for usage reports. - storage = StorageOptions.newBuilder().setProjectId(PROJECT_ID).build().getService(); - bucket = storage.get(BUCKET_NAME); - bucket.delete(); - } - - @Test - public void testBatchCodePredictionSample() throws IOException { - - BatchPredictionJob batchPredictionJob = - BatchCodePredictionSample.batchCodePredictionSample(PROJECT_ID, LOCATION, GCS_SOURCE_URI, - GCS_DESTINATION_OUTPUT_PREFIX, MODEL_ID); - - Assertions.assertNotNull(batchPredictionJob); - assertTrue(batchPredictionJob.getDisplayName().contains("my batch code prediction job")); - assertTrue(batchPredictionJob.getModel().contains("publishers/google/models/code-bison")); - } -} diff --git a/aiplatform/src/test/java/aiplatform/BatchTextPredictionSampleTest.java b/aiplatform/src/test/java/aiplatform/BatchTextPredictionSampleTest.java deleted file mode 100644 index bc1e47be589..00000000000 --- a/aiplatform/src/test/java/aiplatform/BatchTextPredictionSampleTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package aiplatform; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import com.google.cloud.aiplatform.v1.BatchPredictionJob; -import com.google.cloud.storage.Bucket; -import com.google.cloud.storage.BucketInfo; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageOptions; -import java.io.IOException; -import java.util.UUID; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class BatchTextPredictionSampleTest { - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String LOCATION = "us-central1"; - private static String BUCKET_NAME; - private static final String GCS_SOURCE_URI = - "gs://cloud-samples-data/batch/prompt_for_batch_code_predict.jsonl"; - private static final String GCS_DESTINATION_OUTPUT_PREFIX = - String.format("gs://%s/batch-text-predict", BUCKET_NAME); - private static final String MODEL_ID = "text-bison"; - static Storage storage; - static Bucket bucket; - - private static void requireEnvVar(String varName) { - String errorMessage = - String.format("Environment variable '%s' is required to perform these tests.", varName); - assertNotNull(errorMessage, System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() throws IOException { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - BUCKET_NAME = "my-new-test-bucket" + UUID.randomUUID(); - - // Create a Google Cloud Storage bucket for UsageReports - storage = StorageOptions.newBuilder().setProjectId(PROJECT_ID).build().getService(); - storage.create(BucketInfo.of(BUCKET_NAME)); - } - - @AfterClass - public static void afterClass() { - // Delete the Google Cloud Storage bucket created for usage reports. - storage = StorageOptions.newBuilder().setProjectId(PROJECT_ID).build().getService(); - bucket = storage.get(BUCKET_NAME); - bucket.delete(); - } - - @Test - public void testBatchTextPredictionSample() throws IOException { - BatchPredictionJob batchPredictionJob = - BatchTextPredictionSample.batchTextPrediction(PROJECT_ID, GCS_SOURCE_URI, - GCS_DESTINATION_OUTPUT_PREFIX, MODEL_ID, LOCATION); - - Assertions.assertNotNull(batchPredictionJob); - assertTrue(batchPredictionJob.getDisplayName().contains("my batch text prediction job")); - assertTrue(batchPredictionJob.getModel().contains("publishers/google/models/text-bison")); - } -} diff --git a/aiplatform/src/test/java/aiplatform/PredictCodeCompletionCommentSampleTest.java b/aiplatform/src/test/java/aiplatform/PredictCodeCompletionCommentSampleTest.java deleted file mode 100644 index 680a2e08ce0..00000000000 --- a/aiplatform/src/test/java/aiplatform/PredictCodeCompletionCommentSampleTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package aiplatform; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; - -public class PredictCodeCompletionCommentSampleTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - - private static final String PROJECT = System.getenv("UCAIP_PROJECT_ID"); - - private static final String INSTANCE = - "{ \"prefix\": \"" - + "def reverse_string(s):\n" - + " return s[::-1]\n" - + "#This function" - + "\"}"; - private static final String PARAMETERS = - "{\n" + " \"temperature\": 0.2,\n" + " \"maxOutputTokens\": 64\n" + "}"; - private static final String PUBLISHER = "google"; - private static final String LOCATION = "us-central1"; - private static final String MODEL = "code-gecko@001"; - - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - String errorMessage = - String.format("Environment variable '%s' is required to perform these tests.", varName); - assertNotNull(errorMessage, System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("UCAIP_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testPredictComment() throws IOException { - // Act - PredictCodeCompletionCommentSample.predictComment( - INSTANCE, PARAMETERS, PROJECT, LOCATION, PUBLISHER, MODEL); - - // Assert - String got = bout.toString(); - assertThat(got).contains("Predict Response"); - } -}