diff --git a/ai-platform/snippets/batch-code-predict.js b/ai-platform/snippets/batch-code-predict.js deleted file mode 100644 index 1c25ac84d3..0000000000 --- a/ai-platform/snippets/batch-code-predict.js +++ /dev/null @@ -1,113 +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 - * - * https://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. - */ - -'use strict'; - -async function main(projectId, inputUri, outputUri, jobDisplayName) { - // [START generativeaionvertexai_batch_code_predict] - // Imports the aiplatform library - const aiplatformLib = require('@google-cloud/aiplatform'); - const aiplatform = aiplatformLib.protos.google.cloud.aiplatform.v1; - - /** - * TODO(developer): Uncomment/update these variables before running the sample. - */ - // projectId = 'YOUR_PROJECT_ID'; - - // Optional: 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]" - // inputUri = - // 'gs://cloud-samples-data/batch/prompt_for_batch_code_predict.jsonl'; - - // Optional: 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]" - // outputUri = 'gs://batch-bucket-testing/batch_code_predict_output'; - - // The name of batch prediction job - // jobDisplayName = `Batch code prediction job: ${new Date().getMilliseconds()}`; - - // The name of pre-trained model - const codeModel = 'code-bison'; - const location = 'us-central1'; - - // Construct your modelParameters - const parameters = { - maxOutputTokens: '200', - temperature: '0.2', - }; - const parametersValue = aiplatformLib.helpers.toValue(parameters); - // Configure the parent resource - const parent = `projects/${projectId}/locations/${location}`; - const modelName = `projects/${projectId}/locations/${location}/publishers/google/models/${codeModel}`; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const jobServiceClient = new aiplatformLib.JobServiceClient(clientOptions); - - // 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 - async function callBatchCodePredicton() { - const gcsSource = new aiplatform.GcsSource({ - uris: [inputUri], - }); - - const inputConfig = new aiplatform.BatchPredictionJob.InputConfig({ - gcsSource, - instancesFormat: 'jsonl', - }); - - const gcsDestination = new aiplatform.GcsDestination({ - outputUriPrefix: outputUri, - }); - - const outputConfig = new aiplatform.BatchPredictionJob.OutputConfig({ - gcsDestination, - predictionsFormat: 'jsonl', - }); - - const batchPredictionJob = new aiplatform.BatchPredictionJob({ - displayName: jobDisplayName, - model: modelName, - inputConfig, - outputConfig, - modelParameters: parametersValue, - }); - - const request = { - parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - - console.log('Raw response: ', JSON.stringify(response, null, 2)); - } - - await callBatchCodePredicton(); - // [END generativeaionvertexai_batch_code_predict] -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/ai-platform/snippets/batch-prediction/batch-predict-bq.js b/ai-platform/snippets/batch-prediction/batch-predict-bq.js index 175442cbdd..63ab8d3300 100644 --- a/ai-platform/snippets/batch-prediction/batch-predict-bq.js +++ b/ai-platform/snippets/batch-prediction/batch-predict-bq.js @@ -36,7 +36,7 @@ async function main(projectId, outputUri) { 'bq://storage-samples.generative_ai.batch_requests_for_multimodal_input'; const location = 'us-central1'; const parent = `projects/${projectId}/locations/${location}`; - const modelName = `${parent}/publishers/google/models/gemini-1.5-flash-002`; + const modelName = `${parent}/publishers/google/models/gemini-2.0-flash-001`; // Specify the location of the api endpoint. const clientOptions = { diff --git a/ai-platform/snippets/batch-prediction/batch-predict-gcs.js b/ai-platform/snippets/batch-prediction/batch-predict-gcs.js index 9ed5e1f707..b923350327 100644 --- a/ai-platform/snippets/batch-prediction/batch-predict-gcs.js +++ b/ai-platform/snippets/batch-prediction/batch-predict-gcs.js @@ -39,7 +39,7 @@ async function main(projectId, outputUri) { 'gs://cloud-samples-data/generative-ai/batch/batch_requests_for_multimodal_input.jsonl'; const location = 'us-central1'; const parent = `projects/${projectId}/locations/${location}`; - const modelName = `${parent}/publishers/google/models/gemini-1.5-flash-002`; + const modelName = `${parent}/publishers/google/models/gemini-2.0-flash-001`; // Specify the location of the api endpoint. const clientOptions = { diff --git a/ai-platform/snippets/batch-text-predict.js b/ai-platform/snippets/batch-text-predict.js deleted file mode 100644 index a2e59eca2f..0000000000 --- a/ai-platform/snippets/batch-text-predict.js +++ /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 - * - * https://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. - */ - -'use strict'; - -async function main(projectId, inputUri, outputUri, jobDisplayName) { - // [START generativeaionvertexai_batch_text_predict] - // Imports the aiplatform library - const aiplatformLib = require('@google-cloud/aiplatform'); - const aiplatform = aiplatformLib.protos.google.cloud.aiplatform.v1; - - /** - * TODO(developer): Uncomment/update these variables before running the sample. - */ - // projectId = 'YOUR_PROJECT_ID'; - - // Optional: 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]" - // inputUri = - // 'gs://cloud-samples-data/batch/prompt_for_batch_text_predict.jsonl'; - - // Optional: 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]" - // outputUri = 'gs://batch-bucket-testing/batch_text_predict_output'; - - // The name of batch prediction job - // jobDisplayName = `Batch text prediction job: ${new Date().getMilliseconds()}`; - - // The name of pre-trained model - const textModel = 'text-bison'; - const location = 'us-central1'; - - // Construct your modelParameters - const parameters = { - maxOutputTokens: '200', - temperature: '0.2', - topP: '0.95', - topK: '40', - }; - const parametersValue = aiplatformLib.helpers.toValue(parameters); - // Configure the parent resource - const parent = `projects/${projectId}/locations/${location}`; - const modelName = `projects/${projectId}/locations/${location}/publishers/google/models/${textModel}`; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const jobServiceClient = new aiplatformLib.JobServiceClient(clientOptions); - - // 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 - async function callBatchTextPredicton() { - const gcsSource = new aiplatform.GcsSource({ - uris: [inputUri], - }); - - const inputConfig = new aiplatform.BatchPredictionJob.InputConfig({ - gcsSource, - instancesFormat: 'jsonl', - }); - - const gcsDestination = new aiplatform.GcsDestination({ - outputUriPrefix: outputUri, - }); - - const outputConfig = new aiplatform.BatchPredictionJob.OutputConfig({ - gcsDestination, - predictionsFormat: 'jsonl', - }); - - const batchPredictionJob = new aiplatform.BatchPredictionJob({ - displayName: jobDisplayName, - model: modelName, - inputConfig, - outputConfig, - modelParameters: parametersValue, - }); - - const request = { - parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - - console.log('Raw response: ', JSON.stringify(response, null, 2)); - } - - await callBatchTextPredicton(); - // [END generativeaionvertexai_batch_text_predict] -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/ai-platform/snippets/cancel-batch-prediction-job.js b/ai-platform/snippets/cancel-batch-prediction-job.js deleted file mode 100644 index c9c8c8e4b7..0000000000 --- a/ai-platform/snippets/cancel-batch-prediction-job.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -async function main(batchPredictionJobId, project, location = 'us-central1') { - // [START aiplatform_cancel_batch_prediction_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const batchPredictionJobId = 'YOUR_BATCH_PREDICTION_JOB_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Job Service Client library - const {JobServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const jobServiceClient = new JobServiceClient(clientOptions); - - async function cancelBatchPredictionJob() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/batchPredictionJobs/${batchPredictionJobId}`; - const request = { - name, - }; - - // Cancel batch prediction job request - await jobServiceClient.cancelBatchPredictionJob(request); - console.log('Cancel batch prediction job response :'); - } - - cancelBatchPredictionJob(); - // [END aiplatform_cancel_batch_prediction_job_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/code-model-tuning.js b/ai-platform/snippets/code-model-tuning.js deleted file mode 100644 index fee4b19d87..0000000000 --- a/ai-platform/snippets/code-model-tuning.js +++ /dev/null @@ -1,98 +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 - * - * https://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. - */ - -'use strict'; - -async function main( - project, - pipelineJobId, - modelDisplayName, - gcsOutputDirectory, - location = 'europe-west4', - datasetUri = 'gs://cloud-samples-data/ai-platform/generative_ai/sql_create_context.jsonl', - trainSteps = 300 -) { - // [START aiplatform_genai_code_model_tuning] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {PipelineServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }; - const model = 'code-bison@001'; - - const pipelineClient = new PipelineServiceClient(clientOptions); - - async function tuneLLM() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const parameters = { - train_steps: helpers.toValue(trainSteps), - project: helpers.toValue(project), - location: helpers.toValue('us-central1'), - dataset_uri: helpers.toValue(datasetUri), - large_model_reference: helpers.toValue(model), - model_display_name: helpers.toValue(modelDisplayName), - }; - - const runtimeConfig = { - gcsOutputDirectory, - parameterValues: parameters, - }; - - const pipelineJob = { - templateUri: - 'https://us-kfp.pkg.dev/ml-pipeline/large-language-model-pipelines/tune-large-model/v3.0.0', - displayName: 'my-tuning-job', - runtimeConfig, - }; - - const createPipelineRequest = { - parent, - pipelineJob, - pipelineJobId, - }; - - const [response] = await pipelineClient.createPipelineJob( - createPipelineRequest - ); - - console.log('Tuning pipeline job:'); - console.log(`\tName: ${response.name}`); - console.log( - `\tCreate time: ${new Date(1970, 0, 1) - .setSeconds(response.createTime.seconds) - .toLocaleString()}` - ); - console.log(`\tStatus: ${response.status}`); - } - - await tuneLLM(); - // [END aiplatform_genai_code_model_tuning] -} - -exports.tuneModel = main; diff --git a/ai-platform/snippets/create-batch-embedding.js b/ai-platform/snippets/create-batch-embedding.js deleted file mode 100644 index 0fa42d6acf..0000000000 --- a/ai-platform/snippets/create-batch-embedding.js +++ /dev/null @@ -1,105 +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 - * - * https://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. - */ - -'use strict'; - -async function main(projectId, inputUri, outputUri, jobName) { - // [START generativeaionvertexai_embedding_batch] - // Imports the aiplatform library - const aiplatformLib = require('@google-cloud/aiplatform'); - const aiplatform = aiplatformLib.protos.google.cloud.aiplatform.v1; - - /** - * TODO(developer): Uncomment/update these variables before running the sample. - */ - // projectId = 'YOUR_PROJECT_ID'; - - // Optional: 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]" - // inputUri = - // 'gs://cloud-samples-data/generative-ai/embeddings/embeddings_input.jsonl'; - - // Optional: 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]" - // outputUri = 'gs://your_bucket/embedding_batch_output'; - - // The name of the job - // jobName = `Batch embedding job: ${new Date().getMilliseconds()}`; - - const textEmbeddingModel = 'text-embedding-005'; - const location = 'us-central1'; - - // Configure the parent resource - const parent = `projects/${projectId}/locations/${location}`; - const modelName = `projects/${projectId}/locations/${location}/publishers/google/models/${textEmbeddingModel}`; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const jobServiceClient = new aiplatformLib.JobServiceClient(clientOptions); - - // Generates embeddings from text using batch processing. - // Read more: https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/batch-prediction-genai-embeddings - async function callBatchEmbedding() { - const gcsSource = new aiplatform.GcsSource({ - uris: [inputUri], - }); - - const inputConfig = new aiplatform.BatchPredictionJob.InputConfig({ - gcsSource, - instancesFormat: 'jsonl', - }); - - const gcsDestination = new aiplatform.GcsDestination({ - outputUriPrefix: outputUri, - }); - - const outputConfig = new aiplatform.BatchPredictionJob.OutputConfig({ - gcsDestination, - predictionsFormat: 'jsonl', - }); - - const batchPredictionJob = new aiplatform.BatchPredictionJob({ - displayName: jobName, - model: modelName, - inputConfig, - outputConfig, - }); - - const request = { - parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - - console.log('Raw response: ', JSON.stringify(response, null, 2)); - } - - await callBatchEmbedding(); - // [END generativeaionvertexai_embedding_batch] -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/ai-platform/snippets/create-batch-prediction-job-video-action-recognition.js b/ai-platform/snippets/create-batch-prediction-job-video-action-recognition.js deleted file mode 100644 index 37d5a50f00..0000000000 --- a/ai-platform/snippets/create-batch-prediction-job-video-action-recognition.js +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -function main( - batchPredictionDisplayName, - modelId, - gcsSourceUri, - gcsDestinationOutputUriPrefix, - project, - location = 'us-central1' -) { - // [START aiplatform_create_batch_prediction_job_video_action_recognition_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const batchPredictionDisplayName = 'YOUR_BATCH_PREDICTION_DISPLAY_NAME'; - // const modelId = 'YOUR_MODEL_ID'; - // const gcsSourceUri = 'YOUR_GCS_SOURCE_URI'; - // const gcsDestinationOutputUriPrefix = 'YOUR_GCS_DEST_OUTPUT_URI_PREFIX'; - // eg. "gs://<your-gcs-bucket>/destination_path" - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {params} = aiplatform.protos.google.cloud.aiplatform.v1.schema.predict; - - // Imports the Google Cloud Job Service Client library - const {JobServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const jobServiceClient = new JobServiceClient(clientOptions); - - async function createBatchPredictionJobVideoActionRecognition() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const modelName = `projects/${project}/locations/${location}/models/${modelId}`; - - // For more information on how to configure the model parameters object, see - // https://cloud.google.com/ai-platform-unified/docs/predictions/batch-predictions - const modelParamsObj = new params.VideoActionRecognitionPredictionParams({ - confidenceThreshold: 0.5, - }); - - const modelParameters = modelParamsObj.toValue(); - - const inputConfig = { - instancesFormat: 'jsonl', - gcsSource: {uris: [gcsSourceUri]}, - }; - const outputConfig = { - predictionsFormat: 'jsonl', - gcsDestination: {outputUriPrefix: gcsDestinationOutputUriPrefix}, - }; - const batchPredictionJob = { - displayName: batchPredictionDisplayName, - model: modelName, - modelParameters, - inputConfig, - outputConfig, - }; - const request = { - parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - - console.log( - 'Create batch prediction job video action recognition response' - ); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createBatchPredictionJobVideoActionRecognition(); - // [END aiplatform_create_batch_prediction_job_video_action_recognition_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-custom-job.js b/ai-platform/snippets/create-custom-job.js index cae369024e..deca24f916 100644 --- a/ai-platform/snippets/create-custom-job.js +++ b/ai-platform/snippets/create-custom-job.js @@ -54,7 +54,7 @@ async function main( { machineSpec: { machineType: 'n1-standard-4', - acceleratorType: 'NVIDIA_TESLA_K80', + acceleratorType: 'NVIDIA_TESLA_T4', acceleratorCount: 1, }, replicaCount: 1, diff --git a/ai-platform/snippets/create-hyperparameter-tuning-job.js b/ai-platform/snippets/create-hyperparameter-tuning-job.js index d6803a57e9..184313035c 100644 --- a/ai-platform/snippets/create-hyperparameter-tuning-job.js +++ b/ai-platform/snippets/create-hyperparameter-tuning-job.js @@ -76,7 +76,7 @@ function main( { machineSpec: { machineType: 'n1-standard-4', - acceleratorType: 'NVIDIA_TESLA_K80', + acceleratorType: 'NVIDIA_TESLA_T4', acceleratorCount: 1, }, replicaCount: 1, diff --git a/ai-platform/snippets/delete-batch-prediction-job.js b/ai-platform/snippets/delete-batch-prediction-job.js deleted file mode 100644 index 1616485c72..0000000000 --- a/ai-platform/snippets/delete-batch-prediction-job.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -async function main(batchPredictionJobId, project, location = 'us-central1') { - // [START aiplatform_delete_batch_prediction_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const batchPredictionJobId = 'YOUR_BATCH_PREDICTION_JOB_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Job Service Client library - const {JobServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const jobServiceClient = new JobServiceClient(clientOptions); - - async function deleteBatchPredictionJob() { - // Configure the parent resource - const name = `projects/${project}/locations/${location}/batchPredictionJobs/${batchPredictionJobId}`; - const request = { - name, - }; - - // Get and print out a list of all the endpoints for this resource - await jobServiceClient.deleteBatchPredictionJob(request); - - console.log('Delete batch prediction job response :'); - } - deleteBatchPredictionJob(); - // [END aiplatform_delete_batch_prediction_job_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/delete-custom-job.js b/ai-platform/snippets/delete-custom-job.js deleted file mode 100644 index c3a0cf6eef..0000000000 --- a/ai-platform/snippets/delete-custom-job.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -async function main(customJobId, project, location = 'us-central1') { - // [START aiplatform_delete_custom_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const customJobId = 'YOUR_CUSTOM_JOB_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Job Service Client library - const {JobServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const jobServiceClient = new JobServiceClient(clientOptions); - - async function deleteCustomJob() { - // Configure the name resource - const name = jobServiceClient.customJobPath(project, location, customJobId); - const request = { - name, - }; - - // Delete custom job request - const [response] = await jobServiceClient.deleteCustomJob(request); - - console.log('Delete custom job response:\n', response); - } - setTimeout(deleteCustomJob, 60000); - // [END aiplatform_delete_custom_job_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/delete-export-model.js b/ai-platform/snippets/delete-export-model.js deleted file mode 100644 index 8ecb80fdda..0000000000 --- a/ai-platform/snippets/delete-export-model.js +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -async function main(bucketName, uriPrefix) { - // [START aiplatform_delete_export_model_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const bucketName = 'YOUR_BUCKET_NAME'; - // const uriPrefix = 'YOUR_GCS_URI_PREFIX' - - // Imports the Google Cloud Storage Client library - const {Storage} = require('@google-cloud/storage'); - - // Instantiates a client - const storageClient = new Storage(); - - async function deleteExportModel() { - const options = { - prefix: uriPrefix, - }; - const [files] = await storageClient - .bucket(`gs://${bucketName}`) - .getFiles(options); - for (const file of files) { - await storageClient.bucket(`gs://${bucketName}`).file(file.name).delete(); - } - console.log('Export model deleted'); - } - deleteExportModel(); - // [END aiplatform_delete_export_model_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/deploy-model-custom-trained-model.js b/ai-platform/snippets/deploy-model-custom-trained-model.js deleted file mode 100644 index 40956cf494..0000000000 --- a/ai-platform/snippets/deploy-model-custom-trained-model.js +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2021 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 - * - * https://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. - */ - -'use strict'; - -function main( - modelId, - deployedModelDisplayName, - endpointId, - project, - location = 'us-central1' -) { - // [START aiplatform_deploy_model_custom_trained_model_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const modelId = "YOUR_MODEL_ID"; - // const endpointId = 'YOUR_ENDPOINT_ID'; - // const deployedModelDisplayName = 'YOUR_DEPLOYED_MODEL_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - const modelName = `projects/${project}/locations/${location}/models/${modelId}`; - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - // Imports the Google Cloud Endpoint Service Client library - const {EndpointServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint: - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const endpointServiceClient = new EndpointServiceClient(clientOptions); - - async function deployModelCustomTrainedModel() { - // Configure the parent resource - // key '0' assigns traffic for the newly deployed model - // Traffic percentage values must add up to 100 - // Leave dictionary empty if endpoint should not accept any traffic - const trafficSplit = {0: 100}; - const deployedModel = { - // format: 'projects/{project}/locations/{location}/models/{model}' - model: modelName, - displayName: deployedModelDisplayName, - // `dedicatedResources` must be used for non-AutoML models - dedicatedResources: { - minReplicaCount: 1, - machineSpec: { - machineType: 'n1-standard-2', - // Accelerators can be used only if the model specifies a GPU image. - // acceleratorType: 'NVIDIA_TESLA_K80', - // acceleratorCount: 1, - }, - }, - }; - const request = { - endpoint, - deployedModel, - trafficSplit, - }; - - // Get and print out a list of all the endpoints for this resource - const [response] = await endpointServiceClient.deployModel(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Deploy model response'); - const modelDeployed = result.deployedModel; - console.log(`\t\tId : ${modelDeployed.id}`); - console.log(modelDeployed); - } - deployModelCustomTrainedModel(); - // [END aiplatform_deploy_model_custom_trained_model_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/expensive-test/create-data-labeling-job-video.test.js b/ai-platform/snippets/expensive-test/create-data-labeling-job-video.test.js index 33800c8ea1..d230d2427f 100644 --- a/ai-platform/snippets/expensive-test/create-data-labeling-job-video.test.js +++ b/ai-platform/snippets/expensive-test/create-data-labeling-job-video.test.js @@ -31,7 +31,7 @@ const instructionUri = 'gs://ucaip-sample-resources/images/datalabeling_instructions.pdf'; const annotationSpec = 'cartwheel'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let dataLabelingJobId; diff --git a/ai-platform/snippets/expensive-test/create-data-labeling-job.test.js b/ai-platform/snippets/expensive-test/create-data-labeling-job.test.js index 342c54a554..12074b3377 100644 --- a/ai-platform/snippets/expensive-test/create-data-labeling-job.test.js +++ b/ai-platform/snippets/expensive-test/create-data-labeling-job.test.js @@ -33,7 +33,7 @@ const inputsSchemaUri = 'gs://google-cloud-aiplatform/schema/datalabelingjob/inputs/image_classification.yaml'; const annotationSpec = 'daisy'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let dataLabelingJobId; diff --git a/ai-platform/snippets/expensive-test/get-training-pipeline.test.js b/ai-platform/snippets/expensive-test/get-training-pipeline.test.js index 1f553f8438..46855ebdbf 100644 --- a/ai-platform/snippets/expensive-test/get-training-pipeline.test.js +++ b/ai-platform/snippets/expensive-test/get-training-pipeline.test.js @@ -26,7 +26,7 @@ const cwd = path.join(__dirname, '..'); const trainingPipelineId = '1419759782528548864'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get training pipeline', () => { it('should get the training pipeline', async () => { diff --git a/ai-platform/snippets/expensive-test/import-data-text-entity-extraction.test.js b/ai-platform/snippets/expensive-test/import-data-text-entity-extraction.test.js index bb6ca67862..d6a28d0981 100644 --- a/ai-platform/snippets/expensive-test/import-data-text-entity-extraction.test.js +++ b/ai-platform/snippets/expensive-test/import-data-text-entity-extraction.test.js @@ -28,7 +28,7 @@ const datasetId = '6203215905493614592'; const gcsSourceUri = 'gs://cloud-ml-data/NL-entity/AIPlatform-unified/entity_extraction_dataset.jsonl'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform import data text entity extraction', () => { it('should import data to text entity extraction dataset', async () => { diff --git a/ai-platform/snippets/expensive-test/import-data-text-sentiment-analysis.test.js b/ai-platform/snippets/expensive-test/import-data-text-sentiment-analysis.test.js index 8449d211f1..ad11e1cccd 100644 --- a/ai-platform/snippets/expensive-test/import-data-text-sentiment-analysis.test.js +++ b/ai-platform/snippets/expensive-test/import-data-text-sentiment-analysis.test.js @@ -28,9 +28,10 @@ const datasetId = '5148529167758786560'; const gcsSourceUri = 'gs://cloud-ml-data/NL-sentiment/crowdflower-twitter-claritin-80-10-10.csv'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; -describe('AI platform import data text sentiment analysis', () => { +// Training text objective TEXT_SENTIMENT is no longer supported. +describe.skip('AI platform import data text sentiment analysis', () => { it('should import data text sentiment analysis to dataset', async () => { const stdout = execSync( `node ./import-data-text-sentiment-analysis.js ${datasetId} \ diff --git a/ai-platform/snippets/expensive-test/import-data-video-object-tracking.test.js b/ai-platform/snippets/expensive-test/import-data-video-object-tracking.test.js index 592390e924..e99a588fbc 100644 --- a/ai-platform/snippets/expensive-test/import-data-video-object-tracking.test.js +++ b/ai-platform/snippets/expensive-test/import-data-video-object-tracking.test.js @@ -28,7 +28,7 @@ const datasetId = '1138566280794603520'; const gcsSourceUri = 'gs://ucaip-sample-resources/youtube_8m_videos_animal_full.jsonl'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform import data video object tracking', () => { it('should import video object tracking data to dataset', async () => { diff --git a/ai-platform/snippets/get-batch-prediction-job.js b/ai-platform/snippets/get-batch-prediction-job.js deleted file mode 100644 index a263b9e139..0000000000 --- a/ai-platform/snippets/get-batch-prediction-job.js +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ -'use strict'; - -async function main(batchPredictionJobId, project, location = 'us-central1') { - // [START aiplatform_get_batch_prediction_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const batchPredictionJobId = 'YOUR_BATCH_PREDICTION_JOB_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Job Service Client library - const {JobServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const jobServiceClient = new JobServiceClient(clientOptions); - - async function getBatchPredictionJob() { - // Configure the parent resource - const name = `projects/${project}/locations/${location}/batchPredictionJobs/${batchPredictionJobId}`; - const request = { - name, - }; - - // Get batch prediction request - const [response] = await jobServiceClient.getBatchPredictionJob(request); - - console.log('Get batch prediction job response'); - console.log(`\tName : ${response.name}`); - console.log(`\tDisplayName : ${response.displayName}`); - console.log(`\tModel : ${response.model}`); - console.log(`\tModel parameters : ${response.modelParameters}`); - console.log(`\tGenerate explanation : ${response.generateExplanation}`); - console.log(`\tState : ${response.state}`); - console.log(`\tCreate Time : ${JSON.stringify(response.createTime)}`); - console.log(`\tStart Time : ${JSON.stringify(response.startTime)}`); - console.log(`\tEnd Time : ${JSON.stringify(response.endTime)}`); - console.log(`\tUpdate Time : ${JSON.stringify(response.updateTime)}`); - console.log(`\tLabels : ${JSON.stringify(response.labels)}`); - - const inputConfig = response.inputConfig; - console.log('\tInput config'); - console.log(`\t\tInstances format : ${inputConfig.instancesFormat}`); - - const gcsSource = inputConfig.gcsSource; - console.log('\t\tGcs source'); - console.log(`\t\t\tUris : ${gcsSource.uris}`); - - const bigquerySource = inputConfig.bigquerySource; - console.log('\t\tBigQuery Source'); - if (!bigquerySource) { - console.log('\t\t\tInput Uri : {}'); - } else { - console.log(`\t\t\tInput Uri : ${bigquerySource.inputUri}`); - } - - const outputConfig = response.outputConfig; - console.log('\t\tOutput config'); - console.log(`\t\tPredictions format : ${outputConfig.predictionsFormat}`); - - const gcsDestination = outputConfig.gcsDestination; - console.log('\t\tGcs Destination'); - console.log(`\t\t\tOutput uri prefix : ${gcsDestination.outputUriPrefix}`); - - const bigqueryDestination = outputConfig.bigqueryDestination; - if (!bigqueryDestination) { - console.log('\t\tBigquery Destination'); - console.log('\t\t\tOutput uri : {}'); - } else { - console.log('\t\tBigquery Destination'); - console.log(`\t\t\tOutput uri : ${bigqueryDestination.outputUri}`); - } - - const outputInfo = response.outputInfo; - if (!outputInfo) { - console.log('\tOutput info'); - console.log('\t\tGcs output directory : {}'); - console.log('\t\tBigquery_output_dataset : {}'); - } else { - console.log('\tOutput info'); - console.log( - `\t\tGcs output directory : ${outputInfo.gcsOutputDirectory}` - ); - console.log(`\t\tBigquery_output_dataset : - ${outputInfo.bigqueryOutputDataset}`); - } - - const error = response.error; - console.log('\tError'); - console.log(`\t\tCode : ${error.code}`); - console.log(`\t\tMessage : ${error.message}`); - - const details = error.details; - console.log(`\t\tDetails : ${details}`); - - const partialFailures = response.partialFailures; - console.log('\tPartial failure'); - console.log(partialFailures); - - const resourcesConsumed = response.resourcesConsumed; - console.log('\tResource consumed'); - if (!resourcesConsumed) { - console.log('\t\tReplica Hours: {}'); - } else { - console.log(`\t\tReplica Hours: ${resourcesConsumed.replicaHours}`); - } - - const completionStats = response.completionStats; - console.log('\tCompletion status'); - if (!completionStats) { - console.log('\t\tSuccessful count: {}'); - console.log('\t\tFailed count: {}'); - console.log('\t\tIncomplete count: {}'); - } else { - console.log(`\t\tSuccessful count: ${completionStats.successfulCount}`); - console.log(`\t\tFailed count: ${completionStats.failedCount}`); - console.log(`\t\tIncomplete count: ${completionStats.incompleteCount}`); - } - } - getBatchPredictionJob(); - // [END aiplatform_get_batch_prediction_job_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/get-model-evaluation.js b/ai-platform/snippets/get-model-evaluation.js deleted file mode 100644 index c8a4a8f48d..0000000000 --- a/ai-platform/snippets/get-model-evaluation.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -async function main(modelId, evaluationId, project, location = 'us-central1') { - // [START aiplatform_get_model_evaluation_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - (Not necessary if passing values as arguments) - */ - - // const modelId = 'YOUR_MODEL_ID'; - // const evaluationId = 'YOUR_EVALUATION_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Model Service Client library - const {ModelServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const modelServiceClient = new ModelServiceClient(clientOptions); - - async function getModelEvaluation() { - // Configure the parent resources - const name = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}`; - const request = { - name, - }; - - // Create get model evaluation request - const [response] = await modelServiceClient.getModelEvaluation(request); - - console.log('Get model evaluation response'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - console.log(`\tSlice dimensions : ${response.sliceDimensions}`); - } - getModelEvaluation(); - // [END aiplatform_get_model_evaluation_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/import-data-video-action-recognition.js b/ai-platform/snippets/import-data-video-action-recognition.js deleted file mode 100644 index 6c44cdc22e..0000000000 --- a/ai-platform/snippets/import-data-video-action-recognition.js +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -async function main( - datasetId, - gcsSourceUri, - project, - location = 'us-central1' -) { - // [START aiplatform_import_data_video_action_recognition_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const gcsSourceUri = 'YOUR_GCS_SOURCE_URI'; - // eg. 'gs://<your-gcs-bucket>/<import_source_path>/[file.csv/file.jsonl]' - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Dataset Service Client library - const {DatasetServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function importDataVideoActionRecognition() { - const name = datasetServiceClient.datasetPath(project, location, datasetId); - // Here we use only one import config with one source - const importConfigs = [ - { - gcsSource: {uris: [gcsSourceUri]}, - importSchemaUri: - 'gs://google-cloud-aiplatform/schema/dataset/ioformat/video_action_recognition_io_format_1.0.0.yaml', - }, - ]; - const request = { - name, - importConfigs, - }; - - // Create Import Data Request - const [response] = await datasetServiceClient.importData(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - - console.log( - `Import data video action recognition response : \ - ${JSON.stringify(response.result)}` - ); - } - importDataVideoActionRecognition(); - // [END aiplatform_import_data_video_action_recognition_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/import-data.js b/ai-platform/snippets/import-data.js deleted file mode 100644 index 4b9f46b090..0000000000 --- a/ai-platform/snippets/import-data.js +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -async function main( - datasetId, - gcsSourceUri, - importSchemaUri, - project, - location = 'us-central1' -) { - // [START aiplatform_import_data_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - */ - - // const datasetId = "YOUR_DATASET_ID"; - // const gcsSourceUri = "YOUR_GCS_SOURCE_URI"; - // eg. "gs://<your-gcs-bucket>/<import_source_path>/[file.csv/file.jsonl]" - // const importSchemaUri = "YOUR_IMPORT_SCHEMA_URI"; - // const project = "YOUR_PROJECT_ID"; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Dataset Service Client library - const {DatasetServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function importData() { - const name = datasetServiceClient.datasetPath(project, location, datasetId); - // Here we use only one import config with one source - const importConfigs = [ - { - gcsSource: {uris: [gcsSourceUri]}, - importSchemaUri: importSchemaUri, - }, - ]; - const request = { - name, - importConfigs, - }; - - // Create Import Data Request - const [response] = await datasetServiceClient.importData(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - - console.log(`Import data response : ${JSON.stringify(response.result)}`); - } - importData(); - // [END aiplatform_import_data_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-tuned-models.js b/ai-platform/snippets/list-tuned-models.js deleted file mode 100644 index 1d24e915f8..0000000000 --- a/ai-platform/snippets/list-tuned-models.js +++ /dev/null @@ -1,58 +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 - * - * https://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. - */ -'use strict'; - -async function main(project, location, model = 'text-bison-001') { - // [START aiplatform_list_tuned_models] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const model = 'text-bison@001'; - const aiplatform = require('@google-cloud/aiplatform'); - - const {ModelServiceClient} = aiplatform.v1; - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiate the service client. - const modelServiceClient = new ModelServiceClient(clientOptions); - - async function listTunedModels() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const filter = `labels.google-vertex-llm-tuning-base-model-id=${model}`; - - const request = { - parent, - filter, - }; - - const [response] = await modelServiceClient.listModels(request); - console.log('List Tuned Models response'); - for (const model of response) { - console.log(`\tModel name: ${model.name}`); - console.log(`\tDisplay name: ${model.displayName}`); - } - } - await listTunedModels(); - // [END aiplatform_list_tuned_models] -} - -exports.listTunedModels = main; diff --git a/ai-platform/snippets/predict-chat-prompt.js b/ai-platform/snippets/predict-chat-prompt.js deleted file mode 100644 index 6120e0c4bd..0000000000 --- a/ai-platform/snippets/predict-chat-prompt.js +++ /dev/null @@ -1,105 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1') { - // [START aiplatform_sdk_chat] - // [START generativeaionvertexai_sdk_chat] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - const publisher = 'google'; - const model = 'chat-bison@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const prompt = { - context: - 'My name is Miles. You are an astronomer, knowledgeable about the solar system.', - examples: [ - { - input: {content: 'How many moons does Mars have?'}, - output: { - content: 'The planet Mars has two moons, Phobos and Deimos.', - }, - }, - ], - messages: [ - { - author: 'user', - content: 'How many planets are there in the solar system?', - }, - ], - }; - const instanceValue = helpers.toValue(prompt); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.2, - maxOutputTokens: 256, - topP: 0.95, - topK: 40, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get chat prompt response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_chat] - // [END generativeaionvertexai_sdk_chat] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-code-chat.js b/ai-platform/snippets/predict-code-chat.js deleted file mode 100644 index 8db5b3a6d7..0000000000 --- a/ai-platform/snippets/predict-code-chat.js +++ /dev/null @@ -1,104 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1') { - // [START aiplatform_sdk_code_chat] - // [START generativeaionvertexai_sdk_code_chat] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - const publisher = 'google'; - const model = 'codechat-bison@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - // Learn more about creating prompts to work with a code chat model at: - // https://cloud.google.com/vertex-ai/docs/generative-ai/code/code-chat-prompts - const prompt = { - messages: [ - { - author: 'user', - content: 'Hi, how are you?', - }, - { - author: 'system', - content: 'I am doing good. What can I help you in the coding world?', - }, - { - author: 'user', - content: - 'Please help write a function to calculate the min of two numbers', - }, - ], - }; - const instanceValue = helpers.toValue(prompt); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.5, - maxOutputTokens: 1024, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get code chat response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_code_chat] - // [END generativeaionvertexai_sdk_code_chat] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-code-completion-comment.js b/ai-platform/snippets/predict-code-completion-comment.js deleted file mode 100644 index 2610100130..0000000000 --- a/ai-platform/snippets/predict-code-completion-comment.js +++ /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 - * - * https://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. - */ - -'use strict'; - -async function main() { - // [START aiplatform_sdk_code_completion_comment] - // [START generativeaionvertexai_sdk_code_completion_comment] - /** - * TODO(developer): Update these variables before running the sample. - */ - const PROJECT_ID = process.env.CAIP_PROJECT_ID; - const LOCATION = 'us-central1'; - const PUBLISHER = 'google'; - const MODEL = 'code-gecko@001'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${PROJECT_ID}/locations/${LOCATION}/publishers/${PUBLISHER}/models/${MODEL}`; - - const prompt = { - prefix: - 'def reverse_string(s): \ - return s[::-1] \ - #This function', - }; - const instanceValue = helpers.toValue(prompt); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.2, - maxOutputTokens: 64, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get code completion response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_code_completion_comment] - // [END generativeaionvertexai_sdk_code_completion_comment] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(); diff --git a/ai-platform/snippets/predict-code-completion-test-function.js b/ai-platform/snippets/predict-code-completion-test-function.js deleted file mode 100644 index afddf4290e..0000000000 --- a/ai-platform/snippets/predict-code-completion-test-function.js +++ /dev/null @@ -1,88 +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 - * - * https://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. - */ - -'use strict'; - -async function main() { - // [START aiplatform_sdk_code_completion_test_function] - /** - * TODO(developer): Update these variables before running the sample. - */ - const PROJECT_ID = process.env.CAIP_PROJECT_ID; - const LOCATION = 'us-central1'; - const PUBLISHER = 'google'; - const MODEL = 'code-gecko@001'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${PROJECT_ID}/locations/${LOCATION}/publishers/${PUBLISHER}/models/${MODEL}`; - - const prompt = { - prefix: - 'def reverse_string(s): \ - return s[::-1] \ - def test_empty_input_string()', - }; - const instanceValue = helpers.toValue(prompt); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.2, - maxOutputTokens: 64, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get code completion response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_code_completion_test_function] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(); diff --git a/ai-platform/snippets/predict-code-generation-function.js b/ai-platform/snippets/predict-code-generation-function.js deleted file mode 100644 index 8a6967c65e..0000000000 --- a/ai-platform/snippets/predict-code-generation-function.js +++ /dev/null @@ -1,88 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1') { - // [START aiplatform_sdk_code_generation_function] - // [START generativeaionvertexai_sdk_code_generation_function] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - const publisher = 'google'; - const model = 'code-bison@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const prompt = { - prefix: 'Write a function that checks if a year is a leap year.', - }; - const instanceValue = helpers.toValue(prompt); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.5, - maxOutputTokens: 256, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get code generation response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_code_generation_function] - // [END generativeaionvertexai_sdk_code_generation_function] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-code-generation-unittest.js b/ai-platform/snippets/predict-code-generation-unittest.js deleted file mode 100644 index 9a431f7d39..0000000000 --- a/ai-platform/snippets/predict-code-generation-unittest.js +++ /dev/null @@ -1,98 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1') { - // [START aiplatform_sdk_code_generation_unittest] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - const publisher = 'google'; - const model = 'code-bison@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const prompt = { - prefix: - 'Write a unit test for this function: \ - def is_leap_year(year): \ - if year % 4 == 0: \ - if year % 100 == 0: \ - if year % 400 == 0: \ - return True \ - else: \ - return False \ - else: \ - return True \ - else: \ - return False', - }; - const instanceValue = helpers.toValue(prompt); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.5, - maxOutputTokens: 256, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get code generation response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_code_generation_unittest] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-image-from-text.js b/ai-platform/snippets/predict-image-from-text.js deleted file mode 100644 index c12c97399e..0000000000 --- a/ai-platform/snippets/predict-image-from-text.js +++ /dev/null @@ -1,81 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1', textPrompt) { - // [START aiplatform_sdk_text_embedding] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const textPrompt = 'YOUR_TEXT_PROMPT'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - const publisher = 'google'; - const model = 'multimodalembedding@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function predictImageFromText() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const prompt = { - text: textPrompt, - }; - const instanceValue = helpers.toValue(prompt); - const instances = [instanceValue]; - - const parameter = { - sampleCount: 1, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get image embedding response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - await predictImageFromText(); - // [END aiplatform_sdk_text_embedding] -} - -exports.predictImageFromText = main; diff --git a/ai-platform/snippets/predict-text-extraction.js b/ai-platform/snippets/predict-text-extraction.js deleted file mode 100644 index 0e5063ee6a..0000000000 --- a/ai-platform/snippets/predict-text-extraction.js +++ /dev/null @@ -1,124 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1') { - // [START aiplatform_sdk_extraction] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - const publisher = 'google'; - const model = 'text-bison@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const instance = { - content: `Background: There is evidence that there have been significant changes \ - in Amazon rainforest vegetation over the last 21,000 years through the Last \ - Glacial Maximum (LGM) and subsequent deglaciation. Analyses of sediment \ - deposits from Amazon basin paleo lakes and from the Amazon Fan indicate that \ - rainfall in the basin during the LGM was lower than for the present, and this \ - was almost certainly associated with reduced moist tropical vegetation cover \ - in the basin. There is debate, however, over how extensive this reduction \ - was. Some scientists argue that the rainforest was reduced to small, isolated \ - refugia separated by open forest and grassland; other scientists argue that \ - the rainforest remained largely intact but extended less far to the north, \ - south, and east than is seen today. This debate has proved difficult to \ - resolve because the practical limitations of working in the rainforest mean \ - that data sampling is biased away from the center of the Amazon basin, and \ - both explanations are reasonably well supported by the available data. - - Q: What does LGM stands for? - A: Last Glacial Maximum. - - Q: What did the analysis from the sediment deposits indicate? - A: Rainfall in the basin during the LGM was lower than for the present. - - Q: What are some of scientists arguments? - A: The rainforest was reduced to small, isolated refugia separated by open forest and grassland. - - Q: There have been major changes in Amazon rainforest vegetation over the last how many years? - A: 21,000. - - Q: What caused changes in the Amazon rainforest vegetation? - A: The Last Glacial Maximum (LGM) and subsequent deglaciation - - Q: What has been analyzed to compare Amazon rainfall in the past and present? - A: Sediment deposits. - - Q: What has the lower rainfall in the Amazon during the LGM been attributed to? - A: - `, - }; - const instanceValue = helpers.toValue(instance); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.2, - maxOutputTokens: 256, - topP: 0, - topK: 1, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get text extraction response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_extraction] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-text-news-classification.js b/ai-platform/snippets/predict-text-news-classification.js deleted file mode 100644 index da79917a0d..0000000000 --- a/ai-platform/snippets/predict-text-news-classification.js +++ /dev/null @@ -1,113 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1') { - // [START aiplatform_sdk_classify_news_items] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - const publisher = 'google'; - const model = 'text-bison@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const instance = { - content: `What is the topic for a given news headline? - - business - - entertainment - - health - - sports - - technology - - Text: Pixel 7 Pro Expert Hands On Review, the Most Helpful Google Phones. - The answer is: technology - - Text: Quit smoking? - The answer is: health - - Text: Best soccer game of the season? - The answer is: sports - - Text: This stock continues to soar. - The answer is: business - - Text: What movie should I watch this week? - The answer is: entertainment - - Text: Airlines expect to make $10 billion this year despite economic slowdown - The answer is: - `, - }; - const instanceValue = helpers.toValue(instance); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.2, - maxOutputTokens: 5, - topP: 0, - topK: 1, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get text classification response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_classify_news_items] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-text-prompt.js b/ai-platform/snippets/predict-text-prompt.js deleted file mode 100644 index 5a0655daf3..0000000000 --- a/ai-platform/snippets/predict-text-prompt.js +++ /dev/null @@ -1,86 +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 - * - * https://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. - */ - -'use strict'; - -async function main() { - // [START aiplatform_sdk_ideation] - // [START generativeaionvertexai_sdk_ideation] - /** - * TODO(developer): Update these variables before running the sample. - */ - const PROJECT_ID = process.env.CAIP_PROJECT_ID; - const LOCATION = 'us-central1'; - const PUBLISHER = 'google'; - const MODEL = 'text-bison@001'; - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${PROJECT_ID}/locations/${LOCATION}/publishers/${PUBLISHER}/models/${MODEL}`; - - const prompt = { - prompt: - 'Give me ten interview questions for the role of program manager.', - }; - const instanceValue = helpers.toValue(prompt); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.2, - maxOutputTokens: 256, - topP: 0.95, - topK: 40, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const response = await predictionServiceClient.predict(request); - console.log('Get text prompt response'); - console.log(response); - } - - callPredict(); - // [END aiplatform_sdk_ideation] - // [END generativeaionvertexai_sdk_ideation] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(); diff --git a/ai-platform/snippets/predict-text-sentiment.js b/ai-platform/snippets/predict-text-sentiment.js deleted file mode 100644 index b9ac1a3a2c..0000000000 --- a/ai-platform/snippets/predict-text-sentiment.js +++ /dev/null @@ -1,121 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1') { - // [START aiplatform_sdk_sentiment_analysis] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - const publisher = 'google'; - const model = 'text-bison@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const instance = { - content: `I had to compare two versions of Hamlet for my Shakespeare class and \ - unfortunately I picked this version. Everything from the acting (the actors \ - deliver most of their lines directly to the camera) to the camera shots (all \ - medium or close up shots...no scenery shots and very little back ground in the \ - shots) were absolutely terrible. I watched this over my spring break and it is \ - very safe to say that I feel that I was gypped out of 114 minutes of my \ - vacation. Not recommended by any stretch of the imagination. - Classify the sentiment of the message: negative - - Something surprised me about this movie - it was actually original. It was not \ - the same old recycled crap that comes out of Hollywood every month. I saw this \ - movie on video because I did not even know about it before I saw it at my \ - local video store. If you see this movie available - rent it - you will not \ - regret it. - Classify the sentiment of the message: positive - - My family has watched Arthur Bach stumble and stammer since the movie first \ - came out. We have most lines memorized. I watched it two weeks ago and still \ - get tickled at the simple humor and view-at-life. \ - This movie makes me just enjoy watching movies. My favorite scene \ - is when Arthur is visiting his fiancée's house. His conversation with the \ - butler and Susan's father is side-spitting. The line from the butler, \ - "Would you care to wait in the Library" followed by Arthur's reply, \ - "Yes I would, the bathroom is out of the question", is my NEWMAIL \ - notification on my computer. - Classify the sentiment of the message: positive - - - Tweet: The Pixel 7 Pro, is too big to fit in my jeans pocket, so I bought \ - new jeans. - Classify the sentiment of the message: - `, - }; - const instanceValue = helpers.toValue(instance); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.2, - maxOutputTokens: 5, - topP: 0, - topK: 1, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get text sentiment response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_sentiment_analysis] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-text-summarization.js b/ai-platform/snippets/predict-text-summarization.js deleted file mode 100644 index b0919b66a9..0000000000 --- a/ai-platform/snippets/predict-text-summarization.js +++ /dev/null @@ -1,120 +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 - * - * https://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. - */ - -'use strict'; - -async function main(project, location = 'us-central1') { - // [START aiplatform_sdk_summarization] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction service client - const {PredictionServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - const publisher = 'google'; - const model = 'text-bison@001'; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function callPredict() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const instance = { - content: `Provide a summary with about two sentences for the following article: - The efficient-market hypothesis (EMH) is a hypothesis in financial \ - economics that states that asset prices reflect all available \ - information. A direct implication is that it is impossible to \ - "beat the market" consistently on a risk-adjusted basis since market \ - prices should only react to new information. Because the EMH is \ - formulated in terms of risk adjustment, it only makes testable \ - predictions when coupled with a particular model of risk. As a \ - result, research in financial economics since at least the 1990s has \ - focused on market anomalies, that is, deviations from specific \ - models of risk. The idea that financial market returns are difficult \ - to predict goes back to Bachelier, Mandelbrot, and Samuelson, but \ - is closely associated with Eugene Fama, in part due to his \ - influential 1970 review of the theoretical and empirical research. \ - The EMH provides the basic logic for modern risk-based theories of \ - asset prices, and frameworks such as consumption-based asset pricing \ - and intermediary asset pricing can be thought of as the combination \ - of a model of risk with the EMH. Many decades of empirical research \ - on return predictability has found mixed evidence. Research in the \ - 1950s and 1960s often found a lack of predictability (e.g. Ball and \ - Brown 1968; Fama, Fisher, Jensen, and Roll 1969), yet the \ - 1980s-2000s saw an explosion of discovered return predictors (e.g. \ - Rosenberg, Reid, and Lanstein 1985; Campbell and Shiller 1988; \ - Jegadeesh and Titman 1993). Since the 2010s, studies have often \ - found that return predictability has become more elusive, as \ - predictability fails to work out-of-sample (Goyal and Welch 2008), \ - or has been weakened by advances in trading technology and investor \ - learning (Chordia, Subrahmanyam, and Tong 2014; McLean and Pontiff \ - 2016; Martineau 2021). - Summary: - `, - }; - const instanceValue = helpers.toValue(instance); - const instances = [instanceValue]; - - const parameter = { - temperature: 0.2, - maxOutputTokens: 256, - topP: 0.95, - topK: 40, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - console.log('Get text summarization response'); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - - callPredict(); - // [END aiplatform_sdk_summarization] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/quickstart.js b/ai-platform/snippets/quickstart.js deleted file mode 100644 index 4f59d857ec..0000000000 --- a/ai-platform/snippets/quickstart.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2019 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. - -'use strict'; - -/** - * TODO: add an actual quickstart example. - */ -async function main() { - // [START aiplatform_quickstart_sample] - const {DatasetServiceClient} = require('@google-cloud/aiplatform'); - const client = new DatasetServiceClient(); - - // Do something with DatasetServiceClient. - console.info(client); - - // [END aiplatform_quickstart_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/test/batch-code-predict.test.js b/ai-platform/snippets/test/batch-code-predict.test.js deleted file mode 100644 index 3cc27712be..0000000000 --- a/ai-platform/snippets/test/batch-code-predict.test.js +++ /dev/null @@ -1,70 +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 - * - * https://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. - */ - -'use strict'; - -const {assert} = require('chai'); -const {after, describe, it} = require('mocha'); -const uuid = require('uuid').v4; -const cp = require('child_process'); -const {JobServiceClient} = require('@google-cloud/aiplatform'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -describe('Batch code predict', async () => { - const displayName = `batch-code-predict-job-${uuid()}`; - const location = 'us-central1'; - const inputUri = - 'gs://ucaip-samples-test-output/inputs/batch_predict_TCN/tcn_inputs.jsonl'; - const outputUri = 'gs://ucaip-samples-test-output/'; - const jobServiceClient = new JobServiceClient({ - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }); - const projectId = process.env.CAIP_PROJECT_ID; - let batchPredictionJobId; - - after(async () => { - const name = jobServiceClient.batchPredictionJobPath( - projectId, - location, - batchPredictionJobId - ); - - const cancelRequest = { - name, - }; - - jobServiceClient.cancelBatchPredictionJob(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return jobServiceClient.deleteBatchPredictionJob(deleteRequest); - }); - }); - - it('should create job with code prediction', async () => { - const response = execSync( - `node ./batch-code-predict.js ${projectId} ${inputUri} ${outputUri} ${displayName}` - ); - - assert.match(response, new RegExp(displayName)); - - batchPredictionJobId = response - .split('/locations/us-central1/batchPredictionJobs/')[1] - .split('\n')[0]; - }); -}); diff --git a/ai-platform/snippets/test/batch-prediction-gemini.test.js b/ai-platform/snippets/test/batch-prediction-gemini.test.js index 737da7add0..87d58dd618 100644 --- a/ai-platform/snippets/test/batch-prediction-gemini.test.js +++ b/ai-platform/snippets/test/batch-prediction-gemini.test.js @@ -74,7 +74,7 @@ describe('Batch predict with Gemini', async () => { batchPredictionGcsJobId = response .split('/locations/us-central1/batchPredictionJobs/')[1] .split('\n')[0]; - }).timeout(10000); + }).timeout(100000); it('should create Batch prediction Gemini job with BigQuery', async () => { const response = execSync( @@ -85,5 +85,5 @@ describe('Batch predict with Gemini', async () => { batchPredictionBqJobId = response .split('/locations/us-central1/batchPredictionJobs/')[1] .split('\n')[0]; - }).timeout(10000); + }).timeout(100000); }); diff --git a/ai-platform/snippets/test/batch-text-predict.test.js b/ai-platform/snippets/test/batch-text-predict.test.js deleted file mode 100644 index 005bea4a88..0000000000 --- a/ai-platform/snippets/test/batch-text-predict.test.js +++ /dev/null @@ -1,69 +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 - * - * https://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. - */ - -'use strict'; - -const {assert} = require('chai'); -const {after, describe, it} = require('mocha'); -const uuid = require('uuid').v4; -const cp = require('child_process'); -const {JobServiceClient} = require('@google-cloud/aiplatform'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -describe('Batch text predict', async () => { - const displayName = `batch-text-predict-job-${uuid()}`; - const location = 'us-central1'; - const inputUri = - 'gs://ucaip-samples-test-output/inputs/batch_predict_TCN/tcn_inputs.jsonl'; - const outputUri = 'gs://ucaip-samples-test-output/'; - const jobServiceClient = new JobServiceClient({ - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }); - const projectId = process.env.CAIP_PROJECT_ID; - let batchPredictionJobId; - - after(async () => { - const name = jobServiceClient.batchPredictionJobPath( - projectId, - location, - batchPredictionJobId - ); - - const cancelRequest = { - name, - }; - - jobServiceClient.cancelBatchPredictionJob(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return jobServiceClient.deleteBatchPredictionJob(deleteRequest); - }); - }); - - it('should create job with text prediction', async () => { - const response = execSync( - `node ./batch-text-predict.js ${projectId} ${inputUri} ${outputUri} ${displayName}` - ); - - assert.match(response, new RegExp(displayName)); - batchPredictionJobId = response - .split('/locations/us-central1/batchPredictionJobs/')[1] - .split('\n')[0]; - }); -}); diff --git a/ai-platform/snippets/test/code-model-tuning.test.js b/ai-platform/snippets/test/code-model-tuning.test.js deleted file mode 100644 index bdfee631f1..0000000000 --- a/ai-platform/snippets/test/code-model-tuning.test.js +++ /dev/null @@ -1,86 +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. - -/* eslint-disable */ - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const uuid = require('uuid'); -const sinon = require('sinon'); - -const projectId = process.env.CAIP_PROJECT_ID; -const location = 'europe-west4'; - -const aiplatform = require('@google-cloud/aiplatform'); -const clientOptions = { - apiEndpoint: `${location}-aiplatform.googleapis.com`, -}; -const pipelineClient = new aiplatform.v1.PipelineServiceClient(clientOptions); - -const {tuneModel} = require('../code-model-tuning'); - -const timestampId = `${new Date() - .toISOString() - .replace(/(:|\.)/g, '-') - .toLowerCase()}`; -const pipelineJobName = `my-tuning-pipeline-${timestampId}`; -const modelDisplayName = `my-tuned-model-${timestampId}`; -const bucketName = 'ucaip-samples-europe-west4/training_pipeline_output'; -const bucketUri = `gs://${bucketName}/tune-model-nodejs`; - -describe('Tune a code model', () => { - const stubConsole = function () { - sinon.stub(console, 'error'); - sinon.stub(console, 'log'); - }; - - const restoreConsole = function () { - console.log.restore(); - console.error.restore(); - }; - - beforeEach(stubConsole); - afterEach(restoreConsole); - - it('should prompt-tune an existing code model', async () => { - // Act - await tuneModel(projectId, pipelineJobName, modelDisplayName, bucketUri); - - // Assert - assert.include(console.log.firstCall.args, 'Tuning pipeline job:'); - }); - - after(async () => { - // Cancel and delete the pipeline job - const name = pipelineClient.pipelineJobPath( - projectId, - location, - pipelineJobName - ); - - const cancelRequest = { - name, - }; - - pipelineClient.cancelPipelineJob(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return pipelineClient.deletePipeline(deleteRequest); - }); - }); -}); diff --git a/ai-platform/snippets/test/create-batch-embedding.test.js b/ai-platform/snippets/test/create-batch-embedding.test.js deleted file mode 100644 index 970a641276..0000000000 --- a/ai-platform/snippets/test/create-batch-embedding.test.js +++ /dev/null @@ -1,84 +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 - * - * https://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. - */ - -'use strict'; - -const {assert} = require('chai'); -const {after, before, describe, it} = require('mocha'); -const uuid = require('uuid').v4; -const cp = require('child_process'); -const {JobServiceClient} = require('@google-cloud/aiplatform'); -const {Storage} = require('@google-cloud/storage'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -describe('Batch embedding', async () => { - const displayName = `batch-embedding-job-${uuid()}`; - const location = 'us-central1'; - const inputUri = - 'gs://cloud-samples-data/generative-ai/embeddings/embeddings_input.jsonl'; - let outputUri = 'gs://ucaip-samples-test-output/'; - const jobServiceClient = new JobServiceClient({ - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }); - const projectId = process.env.CAIP_PROJECT_ID; - const storage = new Storage({ - projectId, - }); - let batchPredictionJobId; - let bucket; - - before(async () => { - const bucketName = `test-bucket-${uuid()}`; - // Create a Google Cloud Storage bucket for embedding output - [bucket] = await storage.createBucket(bucketName); - outputUri = `gs://${bucketName}/embedding_batch_output`; - }); - - after(async () => { - // Delete job - const name = jobServiceClient.batchPredictionJobPath( - projectId, - location, - batchPredictionJobId - ); - - const cancelRequest = { - name, - }; - - jobServiceClient.cancelBatchPredictionJob(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return jobServiceClient.deleteBatchPredictionJob(deleteRequest); - }); - // Delete the Google Cloud Storage bucket created for embedding output. - await bucket.delete(); - }); - - it('should create batch prediction job', async () => { - const response = execSync( - `node ./create-batch-embedding.js ${projectId} ${inputUri} ${outputUri} ${displayName}` - ); - - assert.match(response, new RegExp(displayName)); - batchPredictionJobId = response - .split(`/locations/${location}/batchPredictionJobs/`)[1] - .split('\n')[0]; - }); -}); diff --git a/ai-platform/snippets/test/create-batch-prediction-job-text-sentiment-analysis.test.js b/ai-platform/snippets/test/create-batch-prediction-job-text-sentiment-analysis.test.js index c9d1832615..05f91804de 100644 --- a/ai-platform/snippets/test/create-batch-prediction-job-text-sentiment-analysis.test.js +++ b/ai-platform/snippets/test/create-batch-prediction-job-text-sentiment-analysis.test.js @@ -39,7 +39,8 @@ const project = process.env.CAIP_PROJECT_ID; let batchPredictionJobId; -describe('AI platform create batch prediction job text sentiment analysis', () => { +// Training text objective TEXT_SENTIMENT is no longer supported. +describe.skip('AI platform create batch prediction job text sentiment analysis', () => { it('should create a text sentiment analysis batch prediction job', async () => { const stdout = execSync( `node ./create-batch-prediction-job-text-sentiment-analysis.js ${batchPredictionDisplayName} ${modelId} ${gcsSourceUri} ${gcsDestinationOutputUriPrefix} ${project} ${location}` diff --git a/ai-platform/snippets/test/create-batch-prediction-job-video-action-recognition.test.js b/ai-platform/snippets/test/create-batch-prediction-job-video-action-recognition.test.js deleted file mode 100644 index db44780785..0000000000 --- a/ai-platform/snippets/test/create-batch-prediction-job-video-action-recognition.test.js +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2021 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 - * - * https://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. - */ - -'use strict'; - -const {assert} = require('chai'); -const {after, describe, it} = require('mocha'); -const uuid = require('uuid').v4; -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const aiplatform = require('@google-cloud/aiplatform'); -const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', -}; - -const jobServiceClient = new aiplatform.v1.JobServiceClient(clientOptions); - -const batchPredictionDisplayName = `temp_create_batch_prediction_video_action_recognition_test${uuid()}`; -const modelId = '3530998029718913024'; -const gcsSourceUri = 'gs://automl-video-demo-data/ucaip-var/swimrun_bp.jsonl'; -const gcsDestinationOutputUriPrefix = 'gs://ucaip-samples-test-output/'; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let batchPredictionJobId; - -describe('AI platform create batch prediction job video action recognition', () => { - it('should create a video action recognition batch prediction job', async () => { - const stdout = execSync( - `node ./create-batch-prediction-job-video-action-recognition.js \ - ${batchPredictionDisplayName} \ - ${modelId} ${gcsSourceUri} \ - ${gcsDestinationOutputUriPrefix} \ - ${project} ${location}` - ); - assert.match( - stdout, - /Create batch prediction job video action recognition response/ - ); - batchPredictionJobId = stdout - .split('/locations/us-central1/batchPredictionJobs/')[1] - .split('\n')[0]; - }); - after('should cancel delete the batch prediction job', async () => { - const name = jobServiceClient.batchPredictionJobPath( - project, - location, - batchPredictionJobId - ); - - const cancelRequest = { - name, - }; - - jobServiceClient.cancelBatchPredictionJob(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return jobServiceClient.deleteBatchPredictionJob(deleteRequest); - }); - }); -}); diff --git a/ai-platform/snippets/test/create-custom-job.test.js b/ai-platform/snippets/test/create-custom-job.test.js index ac87d2e9bd..69df6b18c0 100644 --- a/ai-platform/snippets/test/create-custom-job.test.js +++ b/ai-platform/snippets/test/create-custom-job.test.js @@ -28,7 +28,7 @@ const customJobDisplayName = `temp_create_custom_job_test${uuid()}`; const containerImageUri = 'gcr.io/ucaip-sample-tests/ucaip-training-test:latest'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; function parseResponse(stdout) { let res = {}; @@ -43,7 +43,8 @@ function parseResponse(stdout) { let customJobId; -describe('AI platform create custom job', async function () { +// Image gcr.io/ucaip-sample-tests/ucaip-training-test:latest no longer exists +describe.skip('AI platform create custom job', async function () { this.retries(2); it('should create a new custom job', async () => { const stdout = execSync( diff --git a/ai-platform/snippets/test/create-dataset-image.test.js b/ai-platform/snippets/test/create-dataset-image.test.js index bd9ea481b7..e6b35770ee 100644 --- a/ai-platform/snippets/test/create-dataset-image.test.js +++ b/ai-platform/snippets/test/create-dataset-image.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const datasetDisplayName = `temp_create_dataset_image_test_${uuid()}`; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let datasetId; diff --git a/ai-platform/snippets/test/create-dataset-tabular-bigquery.test.js b/ai-platform/snippets/test/create-dataset-tabular-bigquery.test.js index 829da9dd43..a7ad1c3b0e 100644 --- a/ai-platform/snippets/test/create-dataset-tabular-bigquery.test.js +++ b/ai-platform/snippets/test/create-dataset-tabular-bigquery.test.js @@ -28,7 +28,7 @@ const cwd = path.join(__dirname, '..'); const datasetDisplayName = `temp_create_dataset_tables_bigquery_test_${uuid()}`; const bigquerySourceUri = 'bq://ucaip-sample-tests.table_test.all_bq_types'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let datasetId; diff --git a/ai-platform/snippets/test/create-dataset-tabular-gcs.test.js b/ai-platform/snippets/test/create-dataset-tabular-gcs.test.js index 08ab73a8c2..0cb5265890 100644 --- a/ai-platform/snippets/test/create-dataset-tabular-gcs.test.js +++ b/ai-platform/snippets/test/create-dataset-tabular-gcs.test.js @@ -28,7 +28,7 @@ const cwd = path.join(__dirname, '..'); const datasetDisplayName = `temp_create_dataset_tables_gcs_test_${uuid()}`; const gcsSourceUri = 'gs://cloud-ml-tables-data/bank-marketing.csv'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let datasetId; diff --git a/ai-platform/snippets/test/create-dataset-text.test.js b/ai-platform/snippets/test/create-dataset-text.test.js index 43e84656cc..daf53f52d2 100644 --- a/ai-platform/snippets/test/create-dataset-text.test.js +++ b/ai-platform/snippets/test/create-dataset-text.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const displayName = `temp_create_dataset_text_test_${uuid()}`; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let datasetId; diff --git a/ai-platform/snippets/test/create-dataset-video.test.js b/ai-platform/snippets/test/create-dataset-video.test.js index cae62a2aff..81222ea68e 100644 --- a/ai-platform/snippets/test/create-dataset-video.test.js +++ b/ai-platform/snippets/test/create-dataset-video.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const datasetDisplayName = `temp_create_dataset_video_test_${uuid()}`; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let datasetId; diff --git a/ai-platform/snippets/test/create-dataset.test.js b/ai-platform/snippets/test/create-dataset.test.js index 99075b54db..710827685f 100644 --- a/ai-platform/snippets/test/create-dataset.test.js +++ b/ai-platform/snippets/test/create-dataset.test.js @@ -29,7 +29,7 @@ const datasetDisplayName = `temp_create_dataset_test_${uuid()}`; const metadataSchemaUri = 'gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let datasetId; diff --git a/ai-platform/snippets/test/create-endpoint.test.js b/ai-platform/snippets/test/create-endpoint.test.js index b989d96a8a..78bec699a1 100644 --- a/ai-platform/snippets/test/create-endpoint.test.js +++ b/ai-platform/snippets/test/create-endpoint.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const endpointDisplayName = `temp_create_endpoint_test_${uuid()}`; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let endpointId; describe('AI platform create endpoint', () => { diff --git a/ai-platform/snippets/test/create-hyperparameter-tuning-job.test.js b/ai-platform/snippets/test/create-hyperparameter-tuning-job.test.js index 5d37625504..f356bc1ad2 100644 --- a/ai-platform/snippets/test/create-hyperparameter-tuning-job.test.js +++ b/ai-platform/snippets/test/create-hyperparameter-tuning-job.test.js @@ -38,7 +38,8 @@ const project = process.env.CAIP_PROJECT_ID; let tuningJobId; -describe('AI platform create hyperparameter tuning job', async function () { +// Image gcr.io/ucaip-sample-tests/ucaip-training-test:latest no longer exists +describe.skip('AI platform create hyperparameter tuning job', async function () { this.retries(2); it('should create a new hyperparameter tuning job', async () => { const stdout = execSync( diff --git a/ai-platform/snippets/test/create-training-pipeline-tabular-regression.test.js b/ai-platform/snippets/test/create-training-pipeline-tabular-regression.test.js index 4ded88a2ee..aa47910242 100644 --- a/ai-platform/snippets/test/create-training-pipeline-tabular-regression.test.js +++ b/ai-platform/snippets/test/create-training-pipeline-tabular-regression.test.js @@ -43,7 +43,8 @@ const project = process.env.CAIP_PROJECT_ID; let trainingPipelineId; -describe('AI platform create training pipeline tabular regression', async function () { +// Error: No valid transformation selected as default +describe.skip('AI platform create training pipeline tabular regression', async function () { this.retries(2); it('should create a new tabular regression training pipeline', async () => { const stdout = execSync( diff --git a/ai-platform/snippets/test/create-training-pipeline-text-classification.test.js b/ai-platform/snippets/test/create-training-pipeline-text-classification.test.js deleted file mode 100644 index 0e32c2f5fb..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-text-classification.test.js +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {after, describe, it} = require('mocha'); - -const uuid = require('uuid').v4; -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const aiplatform = require('@google-cloud/aiplatform'); -const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', -}; - -const pipelineServiceClient = new aiplatform.v1.PipelineServiceClient( - clientOptions -); - -const datasetId = '7051300010322821120'; -const modelDisplayName = `temp_create_training_pipeline_text_classification_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_text_classification_test_${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('AI platform create training pipeline text classification', async function () { - this.retries(2); - it('should create a new text classification training pipeline', async () => { - const stdout = execSync( - `node ./create-training-pipeline-text-classification.js \ - ${datasetId} \ - ${modelDisplayName} \ - ${trainingPipelineDisplayName} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create training pipeline text classification response/ - ); - trainingPipelineId = stdout - .split('/locations/us-central1/trainingPipelines/')[1] - .split('\n')[0]; - }); - after('should cancel the training pipeline and delete it', async () => { - const name = pipelineServiceClient.trainingPipelinePath( - project, - location, - trainingPipelineId - ); - - const cancelRequest = { - name, - }; - - pipelineServiceClient.cancelTrainingPipeline(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return pipelineServiceClient.deleteTrainingPipeline(deleteRequest); - }); - }); -}); diff --git a/ai-platform/snippets/test/create-training-pipeline-text-entity-extraction.test.js b/ai-platform/snippets/test/create-training-pipeline-text-entity-extraction.test.js index 01080bb0d4..6ba0d0239c 100644 --- a/ai-platform/snippets/test/create-training-pipeline-text-entity-extraction.test.js +++ b/ai-platform/snippets/test/create-training-pipeline-text-entity-extraction.test.js @@ -42,7 +42,8 @@ const project = process.env.CAIP_PROJECT_ID; let trainingPipelineId; -describe('AI platform create training pipeline text entity extraction', async function () { +// Training text objective TEXT_EXTRACTION is no longer supported +describe.skip('AI platform create training pipeline text entity extraction', async function () { this.retries(2); it('should create a new text entity extraction training pipeline', async () => { const stdout = execSync( diff --git a/ai-platform/snippets/test/create-training-pipeline-text-sentiment-analysis.test.js b/ai-platform/snippets/test/create-training-pipeline-text-sentiment-analysis.test.js index e8492fa19c..85fca42a0a 100644 --- a/ai-platform/snippets/test/create-training-pipeline-text-sentiment-analysis.test.js +++ b/ai-platform/snippets/test/create-training-pipeline-text-sentiment-analysis.test.js @@ -42,7 +42,8 @@ const project = process.env.CAIP_PROJECT_ID; let trainingPipelineId; -describe('AI platform create training pipeline text sentiment analysis', async function () { +// Training text objective TEXT_SENTIMENT is no longer supported. +describe.skip('AI platform create training pipeline text sentiment analysis', async function () { this.retries(2); it('should create a new text sentiment analysis training pipeline', async () => { const stdout = execSync( diff --git a/ai-platform/snippets/test/deploy-model-custom-trained-model.test.js b/ai-platform/snippets/test/deploy-model-custom-trained-model.test.js deleted file mode 100644 index e54518718a..0000000000 --- a/ai-platform/snippets/test/deploy-model-custom-trained-model.test.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2021 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 - * - * https://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. - */ - -'use strict'; - -const {assert} = require('chai'); -const {after, describe, it} = require('mocha'); - -const uuid = require('uuid').v4; -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const endpointDisplayName = `temp_create_endpoint_test_${uuid()}`; - -const modelId = '6430031960164270080'; -const deployedModelDisplayName = `temp_deploy_model_custom_model_test_${uuid()}`; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; -let deployedModelId; -let endpointId; - -describe('AI platform deploy model custom model', () => { - it('should deploy the custom model in the specified endpoint', async () => { - const endOut = execSync( - `node ./create-endpoint.js ${endpointDisplayName} ${project} \ - ${location}` - ); - endpointId = endOut - .split('/locations/us-central1/endpoints/')[1] - .split('\n')[0] - .split('/')[0]; - const stdout = execSync( - `node ./deploy-model-custom-trained-model.js ${modelId} \ - ${deployedModelDisplayName} \ - ${endpointId} \ - ${project} ${location}` - ); - assert.match(stdout, /Deploy model response/); - deployedModelId = stdout.split('Id : ')[1].split('\n')[0]; - }); - - after('should undeploy the deployed custom model', async () => { - execSync( - `node ./undeploy-model.js ${deployedModelId} ${endpointId} ${project} \ - ${location}` - ); - execSync(`node ./delete-endpoint.js ${endpointId} ${project} ${location}`); - }); -}); diff --git a/ai-platform/snippets/test/deploy-model.test.js b/ai-platform/snippets/test/deploy-model.test.js index dcd84b9184..ddd96c38c7 100644 --- a/ai-platform/snippets/test/deploy-model.test.js +++ b/ai-platform/snippets/test/deploy-model.test.js @@ -28,11 +28,12 @@ const endpointDisplayName = `temp_create_endpoint_test_${uuid()}`; const modelId = '4190810559500779520'; const deployedModelDisplayName = `temp_deploy_model_test_${uuid()}`; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let deployedModelId; let endpointId; -describe('AI platform deploy model', () => { +// Skip as model server exited unexpectedly +describe.skip('AI platform deploy model', () => { it('should deploy the model in the specified endpoint', async () => { const endOut = execSync(`node ./create-endpoint.js ${endpointDisplayName} ${project} \ diff --git a/ai-platform/snippets/test/export-model-tabular-classification.test.js b/ai-platform/snippets/test/export-model-tabular-classification.test.js index c929b4d2d6..c043b349f1 100644 --- a/ai-platform/snippets/test/export-model-tabular-classification.test.js +++ b/ai-platform/snippets/test/export-model-tabular-classification.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const gcsDestinationOutputUriPrefix = 'gs://ucaip-samples-test-output'; const modelId = '6036688272397172736'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform export data tabular classification', () => { it('should export model', async () => { diff --git a/ai-platform/snippets/test/get-custom-job.test.js b/ai-platform/snippets/test/get-custom-job.test.js index f51fa2f9a2..025c8bdcc6 100644 --- a/ai-platform/snippets/test/get-custom-job.test.js +++ b/ai-platform/snippets/test/get-custom-job.test.js @@ -26,7 +26,7 @@ const cwd = path.join(__dirname, '..'); const customJobId = '7980906305281851392'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get custom job', () => { it('should get the specified custom job', async () => { diff --git a/ai-platform/snippets/test/get-hyperparameter-tuning-job.test.js b/ai-platform/snippets/test/get-hyperparameter-tuning-job.test.js index a334a8e02c..a96045e3c9 100644 --- a/ai-platform/snippets/test/get-hyperparameter-tuning-job.test.js +++ b/ai-platform/snippets/test/get-hyperparameter-tuning-job.test.js @@ -24,7 +24,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const tuningJobId = '2216298782247616512'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get hyperparameter tuning job', () => { it('should get the specified hyperparameter tuning job', async () => { diff --git a/ai-platform/snippets/test/get-model-evaluation-slice.test.js b/ai-platform/snippets/test/get-model-evaluation-slice.test.js index 85033539c3..8588fac80a 100644 --- a/ai-platform/snippets/test/get-model-evaluation-slice.test.js +++ b/ai-platform/snippets/test/get-model-evaluation-slice.test.js @@ -28,7 +28,7 @@ const modelId = '3512561418744365056'; const evaluationId = '9035588644970168320'; const sliceId = '6481571820677004173'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get model evaluation slice', () => { it('should get the evaluation slice from the specified model', async () => { diff --git a/ai-platform/snippets/test/get-model-evaluation-tabular-classification.test.js b/ai-platform/snippets/test/get-model-evaluation-tabular-classification.test.js index b4ea49e905..c1e703ab89 100644 --- a/ai-platform/snippets/test/get-model-evaluation-tabular-classification.test.js +++ b/ai-platform/snippets/test/get-model-evaluation-tabular-classification.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const modelId = '6036688272397172736'; const evaluationId = '1866113044163962838'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get tabular classification model evaluation', () => { it('should get the evaluation from the specified model', async () => { diff --git a/ai-platform/snippets/test/get-model-evaluation-tabular-regression.test.js b/ai-platform/snippets/test/get-model-evaluation-tabular-regression.test.js index 8bed83613c..4800be5ee5 100644 --- a/ai-platform/snippets/test/get-model-evaluation-tabular-regression.test.js +++ b/ai-platform/snippets/test/get-model-evaluation-tabular-regression.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const modelId = '8842430840248991744'; const evaluationId = '4944816689650806017'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get tabular regression model evaluation', () => { it('should get the evaluation from the specified model', async () => { diff --git a/ai-platform/snippets/test/get-model-evaluation-video-action-recognition.test.js b/ai-platform/snippets/test/get-model-evaluation-video-action-recognition.test.js index e2c6699595..a52568aae4 100644 --- a/ai-platform/snippets/test/get-model-evaluation-video-action-recognition.test.js +++ b/ai-platform/snippets/test/get-model-evaluation-video-action-recognition.test.js @@ -25,7 +25,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const modelId = '3530998029718913024'; const evaluationId = '305008923591573504'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get video action recognition model evaluation', () => { it('should get the evaluation from the specified model', async () => { diff --git a/ai-platform/snippets/test/get-model-evaluation-video-classification.test.js b/ai-platform/snippets/test/get-model-evaluation-video-classification.test.js index 8f0cc4f1ed..347a190ddf 100644 --- a/ai-platform/snippets/test/get-model-evaluation-video-classification.test.js +++ b/ai-platform/snippets/test/get-model-evaluation-video-classification.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const modelId = '8596984660557299712'; const evaluationId = '7092045712224944128'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get video classification model evaluation', () => { it('should get the evaluation from the specified model', async () => { diff --git a/ai-platform/snippets/test/get-model-evaluation-video-object-tracking.test.js b/ai-platform/snippets/test/get-model-evaluation-video-object-tracking.test.js index 01e3cdedb9..9d62f53563 100644 --- a/ai-platform/snippets/test/get-model-evaluation-video-object-tracking.test.js +++ b/ai-platform/snippets/test/get-model-evaluation-video-object-tracking.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const modelId = '8609932509485989888'; const evaluationId = '6016811301190238208'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get video object tracking model evaluation', () => { it('should get the evaluation from the specified model', async () => { diff --git a/ai-platform/snippets/test/get-model.test.js b/ai-platform/snippets/test/get-model.test.js index f2fd901df8..e4f93b1071 100644 --- a/ai-platform/snippets/test/get-model.test.js +++ b/ai-platform/snippets/test/get-model.test.js @@ -26,7 +26,7 @@ const cwd = path.join(__dirname, '..'); const modelId = '3512561418744365056'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get model', () => { it('should get the specified model', async () => { diff --git a/ai-platform/snippets/test/get-training-pipeline.test.js b/ai-platform/snippets/test/get-training-pipeline.test.js index b7455d90c1..0c569cdd59 100644 --- a/ai-platform/snippets/test/get-training-pipeline.test.js +++ b/ai-platform/snippets/test/get-training-pipeline.test.js @@ -24,7 +24,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const trainingPipelineId = '1419759782528548864'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform get training pipeline', () => { it('should get the specified training pipeline', async () => { diff --git a/ai-platform/snippets/test/import-data-video-action-recognition.test.js b/ai-platform/snippets/test/import-data-video-action-recognition.test.js deleted file mode 100644 index ad72270ed4..0000000000 --- a/ai-platform/snippets/test/import-data-video-action-recognition.test.js +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -const {assert} = require('chai'); -const {after, before, describe, it} = require('mocha'); - -const uuid = require('uuid').v4; -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const aiplatform = require('@google-cloud/aiplatform'); -const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', -}; - -const datasetServiceClient = new aiplatform.v1.DatasetServiceClient( - clientOptions -); - -let datasetId = ''; -const datasetDisplayName = `temp_import_data_node_var_${uuid()}`; -const gcsSourceUri = 'gs://automl-video-demo-data/ucaip-var/swimrun.jsonl'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform import data video action recognition', () => { - before('should create the new dataset', async () => { - const parent = `projects/${project}/locations/${location}`; - const [operation] = await datasetServiceClient.createDataset({ - parent, - dataset: { - displayName: datasetDisplayName, - metadataSchemaUri: - 'gs://google-cloud-aiplatform/schema/dataset/metadata/video_1.0.0.yaml', - }, - }); - const [response] = await operation.promise(); - const datasetName = response.name; - datasetId = datasetName.split('datasets/')[1]; - }); - - it('should import video action recognition data to dataset', async () => { - const stdout = execSync( - `node ./import-data-video-action-recognition.js ${datasetId} ${gcsSourceUri} ${project} ${location}` - ); - assert.match(stdout, /Import data video action recognition response/); - }); - - after('should cancel the import job and delete the dataset', async () => { - const datasetName = datasetServiceClient.datasetPath( - project, - location, - datasetId - ); - const [operation] = await datasetServiceClient.deleteDataset({ - name: datasetName, - }); - await operation.promise(); - }); -}); diff --git a/ai-platform/snippets/test/import-data-video-classification.test.js b/ai-platform/snippets/test/import-data-video-classification.test.js index 9c4334f130..5b7aa825d1 100644 --- a/ai-platform/snippets/test/import-data-video-classification.test.js +++ b/ai-platform/snippets/test/import-data-video-classification.test.js @@ -28,7 +28,7 @@ const datasetId = '3757409464110546944'; const gcsSourceUri = 'gs://ucaip-sample-resources/hmdb_split1_5classes_train.jsonl'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform import data video classification', () => { it('should import video classification data to dataset', async () => { diff --git a/ai-platform/snippets/test/list-model-evaluation-slices.test.js b/ai-platform/snippets/test/list-model-evaluation-slices.test.js index 10e0ad3af3..37567bba15 100644 --- a/ai-platform/snippets/test/list-model-evaluation-slices.test.js +++ b/ai-platform/snippets/test/list-model-evaluation-slices.test.js @@ -27,7 +27,7 @@ const cwd = path.join(__dirname, '..'); const modelId = '3512561418744365056'; const evaluationId = '9035588644970168320'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; describe('AI platform list model evaluation slices', () => { it('should list all the evaluation slices from the \ diff --git a/ai-platform/snippets/test/list-tuned-models.test.js b/ai-platform/snippets/test/list-tuned-models.test.js deleted file mode 100644 index c8ea36f638..0000000000 --- a/ai-platform/snippets/test/list-tuned-models.test.js +++ /dev/null @@ -1,46 +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 - * - * https://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. - */ - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const sinon = require('sinon'); - -const LOCATION = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -const {listTunedModels} = require('../list-tuned-models'); - -describe('List tuned models', async () => { - const stubConsole = function () { - sinon.stub(console, 'error'); - sinon.stub(console, 'log'); - }; - - const restoreConsole = function () { - console.log.restore(); - console.error.restore(); - }; - - beforeEach(stubConsole); - afterEach(restoreConsole); - - it('should list all tuned LLM models', async () => { - await listTunedModels(project, LOCATION); - assert.include(console.log.firstCall.args, 'List Tuned Models response'); - }); -}); diff --git a/ai-platform/snippets/test/predict-chat-prompt.test.js b/ai-platform/snippets/test/predict-chat-prompt.test.js deleted file mode 100644 index c8361f9b23..0000000000 --- a/ai-platform/snippets/test/predict-chat-prompt.test.js +++ /dev/null @@ -1,40 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict chat prompt', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync( - `node ./predict-chat-prompt.js ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get chat prompt response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-code-chat.test.js b/ai-platform/snippets/test/predict-code-chat.test.js deleted file mode 100644 index fb58e4458c..0000000000 --- a/ai-platform/snippets/test/predict-code-chat.test.js +++ /dev/null @@ -1,40 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict code chat', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync( - `node ./predict-code-chat.js ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get code chat response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-code-completion-comment.test.js b/ai-platform/snippets/test/predict-code-completion-comment.test.js deleted file mode 100644 index 24676c6718..0000000000 --- a/ai-platform/snippets/test/predict-code-completion-comment.test.js +++ /dev/null @@ -1,31 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); -describe('AI platform predict code completion', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync('node ./predict-code-completion-comment.js', {cwd}); - assert.match(stdout, /Get code completion response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-code-completion-test-function.test.js b/ai-platform/snippets/test/predict-code-completion-test-function.test.js deleted file mode 100644 index 8d02cec468..0000000000 --- a/ai-platform/snippets/test/predict-code-completion-test-function.test.js +++ /dev/null @@ -1,34 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -describe('AI platform predict code completion', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync('node ./predict-code-completion-test-function.js', { - cwd, - }); - assert.match(stdout, /Get code completion response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-code-generation-function.test.js b/ai-platform/snippets/test/predict-code-generation-function.test.js deleted file mode 100644 index 85b6a983cf..0000000000 --- a/ai-platform/snippets/test/predict-code-generation-function.test.js +++ /dev/null @@ -1,40 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict code generation', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync( - `node ./predict-code-generation-function.js ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get code generation response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-code-generation-unittest.test.js b/ai-platform/snippets/test/predict-code-generation-unittest.test.js deleted file mode 100644 index f16c9f3c77..0000000000 --- a/ai-platform/snippets/test/predict-code-generation-unittest.test.js +++ /dev/null @@ -1,40 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict code generation', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync( - `node ./predict-code-generation-unittest.js ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get code generation response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-image-classification.test.js b/ai-platform/snippets/test/predict-image-classification.test.js deleted file mode 100644 index 4947dbd97a..0000000000 --- a/ai-platform/snippets/test/predict-image-classification.test.js +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); -const filename = 'resources/daisy.jpg'; -const endpointId = '71213169107795968'; -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict image classification', async function () { - this.retries(2); - it('should make predictions using the image classification model', async () => { - const stdout = execSync( - `node ./predict-image-classification.js ${filename} \ - ${endpointId} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Predict image classification response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-image-from-text.test.js b/ai-platform/snippets/test/predict-image-from-text.test.js deleted file mode 100644 index 4cc161447f..0000000000 --- a/ai-platform/snippets/test/predict-image-from-text.test.js +++ /dev/null @@ -1,48 +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 - * - * https://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. - */ - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const sinon = require('sinon'); - -const {predictImageFromText} = require('../predict-image-from-text'); - -const project = process.env.CAIP_PROJECT_ID; -const LOCATION = 'us-central1'; -const textPrompt = - 'small red boat on water in the morning watercolor illustration muted colors'; - -describe('AI platform generates image from text', async () => { - const stubConsole = function () { - sinon.stub(console, 'error'); - sinon.stub(console, 'log'); - }; - - const restoreConsole = function () { - console.log.restore(); - console.error.restore(); - }; - - beforeEach(stubConsole); - afterEach(restoreConsole); - - it('should make predictions using a large language model', async () => { - await predictImageFromText(project, LOCATION, textPrompt); - assert.include(console.log.firstCall.args, 'Get image embedding response'); - }); -}); diff --git a/ai-platform/snippets/test/predict-text-extraction.test.js b/ai-platform/snippets/test/predict-text-extraction.test.js deleted file mode 100644 index eabd0d3b46..0000000000 --- a/ai-platform/snippets/test/predict-text-extraction.test.js +++ /dev/null @@ -1,40 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict text extraction', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync( - `node ./predict-text-extraction.js ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get text extraction response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-text-news-classification.test.js b/ai-platform/snippets/test/predict-text-news-classification.test.js deleted file mode 100644 index b5deaf4cac..0000000000 --- a/ai-platform/snippets/test/predict-text-news-classification.test.js +++ /dev/null @@ -1,40 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict text classification', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync( - `node ./predict-text-news-classification.js ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get text classification response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-text-prompt.test.js b/ai-platform/snippets/test/predict-text-prompt.test.js deleted file mode 100644 index 18620adc01..0000000000 --- a/ai-platform/snippets/test/predict-text-prompt.test.js +++ /dev/null @@ -1,34 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -describe('AI platform predict text prompt', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync('node ./predict-text-prompt.js', { - cwd, - }); - assert.match(stdout, /Get text prompt response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-text-sentiment-analysis.test.js b/ai-platform/snippets/test/predict-text-sentiment-analysis.test.js deleted file mode 100644 index 4665941622..0000000000 --- a/ai-platform/snippets/test/predict-text-sentiment-analysis.test.js +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2020 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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const textInput = - 'Economic downturns can be very scary for normal workers.' + - " I dislike how the stock market's fluctuations affect my retirement."; -const endpointId = '7811563922418302976'; -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict text sentiment analysis', () => { - it('should make predictions using the text sentiment model', async () => { - const stdout = execSync( - `node ./predict-text-sentiment-analysis.js "${textInput}" ${endpointId} ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Predict text sentiment analysis response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-text-sentiment.test.js b/ai-platform/snippets/test/predict-text-sentiment.test.js deleted file mode 100644 index db7021d733..0000000000 --- a/ai-platform/snippets/test/predict-text-sentiment.test.js +++ /dev/null @@ -1,40 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict text sentiment', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync( - `node ./predict-text-sentiment.js ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get text sentiment response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-text-summarization.test.js b/ai-platform/snippets/test/predict-text-summarization.test.js deleted file mode 100644 index 10ec273907..0000000000 --- a/ai-platform/snippets/test/predict-text-summarization.test.js +++ /dev/null @@ -1,40 +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 - * - * https://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. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict text summarization', () => { - it('should make predictions using a large language model', async () => { - const stdout = execSync( - `node ./predict-text-summarization.js ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get text summarization response/); - }); -}); diff --git a/ai-platform/snippets/test/quickstart.test.js b/ai-platform/snippets/test/quickstart.test.js deleted file mode 100644 index 25e3bce29c..0000000000 --- a/ai-platform/snippets/test/quickstart.test.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * 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. - */ - -'use strict'; - -const assert = require('assert'); -const cp = require('child_process'); -const {describe, it} = require('mocha'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -describe('quickstart', () => { - it('should have functional quickstart', async () => { - const stdout = execSync('node quickstart.js'); - assert(stdout.match(/DatasetServiceClient/)); - }); -}); diff --git a/ai-platform/snippets/test/tuning.test.js b/ai-platform/snippets/test/tuning.test.js deleted file mode 100644 index b67dd25aa0..0000000000 --- a/ai-platform/snippets/test/tuning.test.js +++ /dev/null @@ -1,82 +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. - -/* eslint-disable */ - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const uuid = require('uuid') -const sinon = require('sinon'); - -const aiplatform = require('@google-cloud/aiplatform'); -const clientOptions = { - apiEndpoint: 'europe-west4-aiplatform.googleapis.com', -}; -const pipelineClient = new aiplatform.v1.PipelineServiceClient(clientOptions); - -const {tuneModel} = require('../tuning'); - -const projectId = process.env.CAIP_PROJECT_ID; -const location = 'europe-west4'; -const timestampId = `${new Date().toISOString().replace(/(:|\.)/g, '-').toLowerCase()}` -const pipelineJobName = `my-tuning-pipeline-${timestampId}` -const modelDisplayName = `my-tuned-model-${timestampId}` -const bucketName = `ucaip-samples-europe-west4/training_pipeline_output`; -const bucketUri = `gs://${bucketName}/tune-model-nodejs` - -describe('Tune a model', () => { - const stubConsole = function () { - sinon.stub(console, 'error'); - sinon.stub(console, 'log'); - }; - - const restoreConsole = function () { - console.log.restore(); - console.error.restore(); - }; - - after(async () => { - // Cancel and delete the pipeline job - const name = pipelineClient.pipelineJobPath( - projectId, - location, - pipelineJobName - ); - - const cancelRequest = { - name, - }; - - pipelineClient.cancelPipelineJob(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return pipelineClient.deletePipeline(deleteRequest); - }); - }); - - beforeEach(stubConsole); - afterEach(restoreConsole); - - it('should prompt-tune an existing model', async () => { - // Act - await tuneModel(projectId, pipelineJobName, modelDisplayName, bucketUri); - - // Assert - assert.include(console.log.firstCall.args, 'Tuning pipeline job:'); - }); -}); diff --git a/ai-platform/snippets/test/upload-model.test.js b/ai-platform/snippets/test/upload-model.test.js index b06c3eb1a9..70bec63d5d 100644 --- a/ai-platform/snippets/test/upload-model.test.js +++ b/ai-platform/snippets/test/upload-model.test.js @@ -30,7 +30,7 @@ const imageUri = 'gcr.io/cloud-ml-service-public/cloud-ml-online-prediction-model-server-cpu:v1_15py3cmle_op_images_20200229_0210_RC00'; const artifactUri = 'gs://ucaip-samples-us-central1/model/explain/'; const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; +const location = 'us-central1'; let modelId; diff --git a/ai-platform/snippets/tuning.js b/ai-platform/snippets/tuning.js deleted file mode 100644 index f4ee1138fd..0000000000 --- a/ai-platform/snippets/tuning.js +++ /dev/null @@ -1,104 +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 - * - * https://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. - */ - -'use strict'; - -async function main( - project, - pipelineJobId, - modelDisplayName, - gcsOutputDirectory, - location = 'europe-west4', - datasetUri = 'gs://cloud-samples-data/ai-platform/generative_ai/headline_classification.jsonl', - trainSteps = 300 -) { - // [START aiplatform_model_tuning] - // [START generativeaionvertexai_model_tuning] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {PipelineServiceClient} = aiplatform.v1; - - // Import the helper module for converting arbitrary protobuf.Value objects. - const {helpers} = aiplatform; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'europe-west4-aiplatform.googleapis.com', - }; - const model = 'text-bison@001'; - - const pipelineClient = new PipelineServiceClient(clientOptions); - - async function tuneLLM() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const parameters = { - train_steps: helpers.toValue(trainSteps), - project: helpers.toValue(project), - location: helpers.toValue('us-central1'), - dataset_uri: helpers.toValue(datasetUri), - large_model_reference: helpers.toValue(model), - model_display_name: helpers.toValue(modelDisplayName), - accelerator_type: helpers.toValue('GPU'), // Optional: GPU or TPU - }; - - const runtimeConfig = { - gcsOutputDirectory, - parameterValues: parameters, - }; - - const pipelineJob = { - templateUri: - 'https://us-kfp.pkg.dev/ml-pipeline/large-language-model-pipelines/tune-large-model/v2.0.0', - displayName: 'my-tuning-job', - runtimeConfig, - }; - - const createPipelineRequest = { - parent, - pipelineJob, - pipelineJobId, - }; - await new Promise((resolve, reject) => { - pipelineClient.createPipelineJob(createPipelineRequest).then( - response => resolve(response), - e => reject(e) - ); - }).then(response => { - const [result] = response; - console.log('Tuning pipeline job:'); - console.log(`\tName: ${result.name}`); - console.log( - `\tCreate time: ${new Date(1970, 0, 1) - .setSeconds(result.createTime.seconds) - .toLocaleString()}` - ); - console.log(`\tStatus: ${result.status}`); - }); - } - - await tuneLLM(); - // [END aiplatform_model_tuning] - // [END generativeaionvertexai_model_tuning] -} - -exports.tuneModel = main; diff --git a/generative-ai/snippets/count-tokens/countTokens.js b/generative-ai/snippets/count-tokens/countTokens.js index 54fed24dc1..c75ef1d8c6 100644 --- a/generative-ai/snippets/count-tokens/countTokens.js +++ b/generative-ai/snippets/count-tokens/countTokens.js @@ -21,7 +21,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function countTokens( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/count-tokens/countTokensAdvanced.js b/generative-ai/snippets/count-tokens/countTokensAdvanced.js index c14108dd18..8831f50525 100644 --- a/generative-ai/snippets/count-tokens/countTokensAdvanced.js +++ b/generative-ai/snippets/count-tokens/countTokensAdvanced.js @@ -21,7 +21,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function countTokens( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/function-calling/functionCallingAdvanced.js b/generative-ai/snippets/function-calling/functionCallingAdvanced.js index 3baed88224..8c59df6ca8 100644 --- a/generative-ai/snippets/function-calling/functionCallingAdvanced.js +++ b/generative-ai/snippets/function-calling/functionCallingAdvanced.js @@ -65,7 +65,7 @@ const generationConfig = { async function functionCallingAdvanced( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/function-calling/functionCallingBasic.js b/generative-ai/snippets/function-calling/functionCallingBasic.js index e8d8affe86..999ad03818 100644 --- a/generative-ai/snippets/function-calling/functionCallingBasic.js +++ b/generative-ai/snippets/function-calling/functionCallingBasic.js @@ -46,7 +46,7 @@ const functionDeclarations = [ async function functionCallingBasic( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/function-calling/functionCallingStreamChat.js b/generative-ai/snippets/function-calling/functionCallingStreamChat.js index 0ae9d8546a..88844a6925 100644 --- a/generative-ai/snippets/function-calling/functionCallingStreamChat.js +++ b/generative-ai/snippets/function-calling/functionCallingStreamChat.js @@ -55,7 +55,7 @@ const functionResponseParts = [ async function functionCallingStreamChat( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/function-calling/functionCallingStreamContent.js b/generative-ai/snippets/function-calling/functionCallingStreamContent.js index 11b28d2292..923ac6529a 100644 --- a/generative-ai/snippets/function-calling/functionCallingStreamContent.js +++ b/generative-ai/snippets/function-calling/functionCallingStreamContent.js @@ -56,7 +56,7 @@ const functionResponseParts = [ async function functionCallingStreamContent( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/gemini-all-modalities.js b/generative-ai/snippets/gemini-all-modalities.js index 7bd6abd89f..8297629b20 100644 --- a/generative-ai/snippets/gemini-all-modalities.js +++ b/generative-ai/snippets/gemini-all-modalities.js @@ -22,7 +22,7 @@ async function analyze_all_modalities(projectId = 'PROJECT_ID') { const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-1.5-flash-001', + model: 'gemini-2.0-flash-001', }); const videoFilePart = { diff --git a/generative-ai/snippets/gemini-audio-summarization.js b/generative-ai/snippets/gemini-audio-summarization.js index 1efbecb98d..b250571f17 100644 --- a/generative-ai/snippets/gemini-audio-summarization.js +++ b/generative-ai/snippets/gemini-audio-summarization.js @@ -22,7 +22,7 @@ async function summarize_audio(projectId = 'PROJECT_ID') { const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-1.5-flash-001', + model: 'gemini-2.0-flash-001', }); const filePart = { diff --git a/generative-ai/snippets/gemini-audio-transcription.js b/generative-ai/snippets/gemini-audio-transcription.js index f0b7d71c18..3a365fc2c6 100644 --- a/generative-ai/snippets/gemini-audio-transcription.js +++ b/generative-ai/snippets/gemini-audio-transcription.js @@ -22,7 +22,7 @@ async function transcript_audio(projectId = 'PROJECT_ID') { const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-1.5-flash-001', + model: 'gemini-2.0-flash-001', }); const filePart = { diff --git a/generative-ai/snippets/gemini-pdf.js b/generative-ai/snippets/gemini-pdf.js index 9032ab0527..314af58d13 100644 --- a/generative-ai/snippets/gemini-pdf.js +++ b/generative-ai/snippets/gemini-pdf.js @@ -22,7 +22,7 @@ async function analyze_pdf(projectId = 'PROJECT_ID') { const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-1.5-flash-001', + model: 'gemini-2.0-flash-001', }); const filePart = { diff --git a/generative-ai/snippets/gemini-system-instruction.js b/generative-ai/snippets/gemini-system-instruction.js index 2407c5e7c0..0395034bce 100644 --- a/generative-ai/snippets/gemini-system-instruction.js +++ b/generative-ai/snippets/gemini-system-instruction.js @@ -22,7 +22,7 @@ async function set_system_instruction(projectId = 'PROJECT_ID') { const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-1.5-flash-001', + model: 'gemini-2.0-flash-001', systemInstruction: { parts: [ {text: 'You are a helpful language translator.'}, diff --git a/generative-ai/snippets/gemini-text-input.js b/generative-ai/snippets/gemini-text-input.js index 79209fa3ea..7ce63492c0 100644 --- a/generative-ai/snippets/gemini-text-input.js +++ b/generative-ai/snippets/gemini-text-input.js @@ -22,7 +22,7 @@ async function generate_from_text_input(projectId = 'PROJECT_ID') { const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-1.5-flash-001', + model: 'gemini-2.0-flash-001', }); const prompt = diff --git a/generative-ai/snippets/gemini-translate.js b/generative-ai/snippets/gemini-translate.js index 82628368d7..05e03e52ba 100644 --- a/generative-ai/snippets/gemini-translate.js +++ b/generative-ai/snippets/gemini-translate.js @@ -26,7 +26,7 @@ async function geminiTranslation(projectId) { */ // projectId = 'your-project-id'; const location = 'us-central1'; - const modelName = 'gemini-1.0-pro'; + const modelName = 'gemini-2.0-flash-001'; // The text to be translated. const text = 'Hello! How are you doing today?'; // The language code of the target language. Defaults to "fr" (*French). diff --git a/generative-ai/snippets/gemini-video-audio.js b/generative-ai/snippets/gemini-video-audio.js index 47aa48ffe4..0b6d7fe123 100644 --- a/generative-ai/snippets/gemini-video-audio.js +++ b/generative-ai/snippets/gemini-video-audio.js @@ -22,7 +22,7 @@ async function analyze_video_with_audio(projectId = 'PROJECT_ID') { const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-1.5-flash-001', + model: 'gemini-2.0-flash-001', }); const filePart = { diff --git a/generative-ai/snippets/grounding/groundingPrivateDataBasic.js b/generative-ai/snippets/grounding/groundingPrivateDataBasic.js index ce9fbe21af..067d7c5a87 100644 --- a/generative-ai/snippets/grounding/groundingPrivateDataBasic.js +++ b/generative-ai/snippets/grounding/groundingPrivateDataBasic.js @@ -25,7 +25,7 @@ const { async function generateContentWithVertexAISearchGrounding( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001', + model = 'gemini-2.0-flash-001', dataStoreId = 'DATASTORE_ID' ) { // Initialize Vertex with your Cloud project and location diff --git a/generative-ai/snippets/grounding/groundingPublicDataBasic.js b/generative-ai/snippets/grounding/groundingPublicDataBasic.js index f64e787261..f273e4f8a9 100644 --- a/generative-ai/snippets/grounding/groundingPublicDataBasic.js +++ b/generative-ai/snippets/grounding/groundingPublicDataBasic.js @@ -21,7 +21,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function generateContentWithGoogleSearchGrounding( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); @@ -31,13 +31,13 @@ async function generateContentWithGoogleSearchGrounding( generationConfig: {maxOutputTokens: 256}, }); - const googleSearchRetrievalTool = { - googleSearchRetrieval: {}, + const googleSearchTool = { + googleSearch: {}, }; const request = { contents: [{role: 'user', parts: [{text: 'Why is the sky blue?'}]}], - tools: [googleSearchRetrievalTool], + tools: [googleSearchTool], }; const result = await generativeModelPreview.generateContent(request); diff --git a/generative-ai/snippets/inference/nonStreamMultiModalityBasic.js b/generative-ai/snippets/inference/nonStreamMultiModalityBasic.js index 53613df554..51d6f76197 100644 --- a/generative-ai/snippets/inference/nonStreamMultiModalityBasic.js +++ b/generative-ai/snippets/inference/nonStreamMultiModalityBasic.js @@ -20,7 +20,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); */ const PROJECT_ID = process.env.CAIP_PROJECT_ID; const LOCATION = 'us-central1'; -const MODEL = 'gemini-1.5-flash-001'; +const MODEL = 'gemini-2.0-flash-001'; async function generateContent() { // Initialize Vertex AI diff --git a/generative-ai/snippets/inference/nonStreamTextBasic.js b/generative-ai/snippets/inference/nonStreamTextBasic.js index cc2f77aeef..6ef2f01e92 100644 --- a/generative-ai/snippets/inference/nonStreamTextBasic.js +++ b/generative-ai/snippets/inference/nonStreamTextBasic.js @@ -20,7 +20,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); */ const PROJECT_ID = process.env.CAIP_PROJECT_ID; const LOCATION = process.env.LOCATION; -const MODEL = 'gemini-1.5-flash-001'; +const MODEL = 'gemini-2.0-flash-001'; async function generateContent() { // Initialize Vertex with your Cloud project and location diff --git a/generative-ai/snippets/inference/streamMultiModalityBasic.js b/generative-ai/snippets/inference/streamMultiModalityBasic.js index 0e47509cd0..a839989414 100644 --- a/generative-ai/snippets/inference/streamMultiModalityBasic.js +++ b/generative-ai/snippets/inference/streamMultiModalityBasic.js @@ -20,7 +20,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); */ const PROJECT_ID = process.env.CAIP_PROJECT_ID; const LOCATION = process.env.LOCATION; -const MODEL = 'gemini-1.5-flash-001'; +const MODEL = 'gemini-2.0-flash-001'; async function generateContent() { // Initialize Vertex AI diff --git a/generative-ai/snippets/inference/streamTextBasic.js b/generative-ai/snippets/inference/streamTextBasic.js index 388dc93f71..ece438f6f5 100644 --- a/generative-ai/snippets/inference/streamTextBasic.js +++ b/generative-ai/snippets/inference/streamTextBasic.js @@ -20,7 +20,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); */ const PROJECT_ID = process.env.CAIP_PROJECT_ID; const LOCATION = process.env.LOCATION; -const MODEL = 'gemini-1.5-flash-001'; +const MODEL = 'gemini-2.0-flash-001'; async function generateContent() { // Initialize Vertex with your Cloud project and location diff --git a/generative-ai/snippets/nonStreamingChat.js b/generative-ai/snippets/nonStreamingChat.js index 6e5055e84c..1a6d3ce09b 100644 --- a/generative-ai/snippets/nonStreamingChat.js +++ b/generative-ai/snippets/nonStreamingChat.js @@ -22,7 +22,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function createNonStreamingChat( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/nonStreamingContent.js b/generative-ai/snippets/nonStreamingContent.js index e7acb2c2e0..71c6a67872 100644 --- a/generative-ai/snippets/nonStreamingContent.js +++ b/generative-ai/snippets/nonStreamingContent.js @@ -22,7 +22,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function createNonStreamingContent( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/nonStreamingMultipartContent.js b/generative-ai/snippets/nonStreamingMultipartContent.js index 0204819951..a391b96a13 100644 --- a/generative-ai/snippets/nonStreamingMultipartContent.js +++ b/generative-ai/snippets/nonStreamingMultipartContent.js @@ -21,7 +21,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function createNonStreamingMultipartContent( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001', + model = 'gemini-2.0-flash-001', image = 'gs://generativeai-downloads/images/scones.jpg', mimeType = 'image/jpeg' ) { diff --git a/generative-ai/snippets/safetySettings.js b/generative-ai/snippets/safetySettings.js index 0c952d2b90..52b229fa65 100644 --- a/generative-ai/snippets/safetySettings.js +++ b/generative-ai/snippets/safetySettings.js @@ -24,7 +24,7 @@ const { */ const PROJECT_ID = process.env.CAIP_PROJECT_ID; const LOCATION = 'us-central1'; -const MODEL = 'gemini-1.5-flash-001'; +const MODEL = 'gemini-2.0-flash-001'; async function setSafetySettings() { // Initialize Vertex with your Cloud project and location diff --git a/generative-ai/snippets/sendMultiModalPromptWithImage.js b/generative-ai/snippets/sendMultiModalPromptWithImage.js index de09a22e45..bdeb9484ca 100644 --- a/generative-ai/snippets/sendMultiModalPromptWithImage.js +++ b/generative-ai/snippets/sendMultiModalPromptWithImage.js @@ -27,7 +27,7 @@ async function getBase64(url) { async function sendMultiModalPromptWithImage( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // For images, the SDK supports base64 strings const landmarkImage1 = await getBase64( diff --git a/generative-ai/snippets/sendMultiModalPromptWithVideo.js b/generative-ai/snippets/sendMultiModalPromptWithVideo.js index 078c80440e..3126264f29 100644 --- a/generative-ai/snippets/sendMultiModalPromptWithVideo.js +++ b/generative-ai/snippets/sendMultiModalPromptWithVideo.js @@ -21,7 +21,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function sendMultiModalPromptWithVideo( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/streamChat.js b/generative-ai/snippets/streamChat.js index a3693b9bfb..212313f95a 100644 --- a/generative-ai/snippets/streamChat.js +++ b/generative-ai/snippets/streamChat.js @@ -21,7 +21,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function createStreamChat( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/streamContent.js b/generative-ai/snippets/streamContent.js index 1ee893a67b..54e34a9c12 100644 --- a/generative-ai/snippets/streamContent.js +++ b/generative-ai/snippets/streamContent.js @@ -22,7 +22,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function createStreamContent( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001' + model = 'gemini-2.0-flash-001' ) { // Initialize Vertex with your Cloud project and location const vertexAI = new VertexAI({project: projectId, location: location}); diff --git a/generative-ai/snippets/streamMultipartContent.js b/generative-ai/snippets/streamMultipartContent.js index 7604476c67..434f7fa5e3 100644 --- a/generative-ai/snippets/streamMultipartContent.js +++ b/generative-ai/snippets/streamMultipartContent.js @@ -21,7 +21,7 @@ const {VertexAI} = require('@google-cloud/vertexai'); async function createStreamMultipartContent( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-1.5-flash-001', + model = 'gemini-2.0-flash-001', image = 'gs://generativeai-downloads/images/scones.jpg', mimeType = 'image/jpeg' ) { diff --git a/generative-ai/snippets/test/count-tokens/countTokens.test.js b/generative-ai/snippets/test/count-tokens/countTokens.test.js index 738553a29e..90543d9559 100644 --- a/generative-ai/snippets/test/count-tokens/countTokens.test.js +++ b/generative-ai/snippets/test/count-tokens/countTokens.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Count tokens', async () => { /** @@ -30,7 +30,7 @@ describe('Count tokens', async () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should count tokens', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/count-tokens/countTokensAdvanced.test.js b/generative-ai/snippets/test/count-tokens/countTokensAdvanced.test.js index 2e37a0225c..aa944d1676 100644 --- a/generative-ai/snippets/test/count-tokens/countTokensAdvanced.test.js +++ b/generative-ai/snippets/test/count-tokens/countTokensAdvanced.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Count tokens advanced', async () => { /** @@ -30,7 +30,7 @@ describe('Count tokens advanced', async () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should count tokens in a multimodal prompt', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/function-calling/functionCallingAdvanced.test.js b/generative-ai/snippets/test/function-calling/functionCallingAdvanced.test.js index 7e117c6770..dcdf1b69b1 100644 --- a/generative-ai/snippets/test/function-calling/functionCallingAdvanced.test.js +++ b/generative-ai/snippets/test/function-calling/functionCallingAdvanced.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Function Calling Advanced', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Function Calling Advanced', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should define multiple functions and have the model invoke the specified one', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/function-calling/functionCallingBasic.test.js b/generative-ai/snippets/test/function-calling/functionCallingBasic.test.js index 4375f1e56d..17debc7400 100644 --- a/generative-ai/snippets/test/function-calling/functionCallingBasic.test.js +++ b/generative-ai/snippets/test/function-calling/functionCallingBasic.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Function Calling', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Function Calling', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should define a function and have the model invoke it', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/function-calling/functionCallingStreamChat.test.js b/generative-ai/snippets/test/function-calling/functionCallingStreamChat.test.js index e430ea4a77..f303e05168 100644 --- a/generative-ai/snippets/test/function-calling/functionCallingStreamChat.test.js +++ b/generative-ai/snippets/test/function-calling/functionCallingStreamChat.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Function Calling Stream Chat', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Function Calling Stream Chat', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should create stream chat and begin the conversation the same in each instance', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/function-calling/functionCallingStreamContent.test.js b/generative-ai/snippets/test/function-calling/functionCallingStreamContent.test.js index 1804bcfbf5..403f07c9ee 100644 --- a/generative-ai/snippets/test/function-calling/functionCallingStreamContent.test.js +++ b/generative-ai/snippets/test/function-calling/functionCallingStreamContent.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Function Calling Stream Content', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Function Calling Stream Content', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should create stream chat and begin the conversation the same in each instance', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/grounding/groundingPrivateDataBasic.test.js b/generative-ai/snippets/test/grounding/groundingPrivateDataBasic.test.js index 478d3015e1..6179e36390 100644 --- a/generative-ai/snippets/test/grounding/groundingPrivateDataBasic.test.js +++ b/generative-ai/snippets/test/grounding/groundingPrivateDataBasic.test.js @@ -22,7 +22,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.GOOGLE_SAMPLES_PROJECT; const location = process.env.LOCATION; const datastore_id = process.env.DATASTORE_ID; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Private data grounding', async () => { /** @@ -31,7 +31,7 @@ describe('Private data grounding', async () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should ground results in private VertexAI search data', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/grounding/groundingPublicDataBasic.test.js b/generative-ai/snippets/test/grounding/groundingPublicDataBasic.test.js index a891ecc8af..d84f9e7662 100644 --- a/generative-ai/snippets/test/grounding/groundingPublicDataBasic.test.js +++ b/generative-ai/snippets/test/grounding/groundingPublicDataBasic.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Google search grounding', async () => { /** @@ -30,12 +30,12 @@ describe('Google search grounding', async () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should ground results in public search data', async () => { const output = execSync( `node ./grounding/groundingPublicDataBasic.js ${projectId} ${location} ${model}` ); - assert(output.match(/GroundingMetadata.*[Ww]hy is the sky blue?/)); + assert(output.match(/blue/)); }); }); diff --git a/generative-ai/snippets/test/nonStreamingChat.test.js b/generative-ai/snippets/test/nonStreamingChat.test.js index 673b38107e..bf9a1e831c 100644 --- a/generative-ai/snippets/test/nonStreamingChat.test.js +++ b/generative-ai/snippets/test/nonStreamingChat.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI NonStreaming Chat', async () => { /** @@ -30,13 +30,13 @@ describe('Generative AI NonStreaming Chat', async () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should create nonstreaming chat and begin the conversation the same in each instance', async () => { const output = execSync( `node ./nonStreamingChat.js ${projectId} ${location} ${model}` ); - assert(output.includes('Hello'), output); + assert(output.length > 0); }); }); diff --git a/generative-ai/snippets/test/nonStreamingContent.test.js b/generative-ai/snippets/test/nonStreamingContent.test.js index e4b3f9351a..2114b8d61a 100644 --- a/generative-ai/snippets/test/nonStreamingContent.test.js +++ b/generative-ai/snippets/test/nonStreamingContent.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI NonStreaming Content', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI NonStreaming Content', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should create nonstreaming content', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/nonStreamingMultipartContent.test.js b/generative-ai/snippets/test/nonStreamingMultipartContent.test.js index 0de6379453..ce71d24a8d 100644 --- a/generative-ai/snippets/test/nonStreamingMultipartContent.test.js +++ b/generative-ai/snippets/test/nonStreamingMultipartContent.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI NonStreaming Multipart Content', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI NonStreaming Multipart Content', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; const image = 'gs://generativeai-downloads/images/scones.jpg'; diff --git a/generative-ai/snippets/test/safetySettings.test.js b/generative-ai/snippets/test/safetySettings.test.js index 175b77c08d..eef90920de 100644 --- a/generative-ai/snippets/test/safetySettings.test.js +++ b/generative-ai/snippets/test/safetySettings.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Safety settings', async () => { /** @@ -30,7 +30,7 @@ describe('Safety settings', async () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should reject a dangerous request', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/sendMultiModalPromptWithImage.test.js b/generative-ai/snippets/test/sendMultiModalPromptWithImage.test.js index 10cb849867..154b0b282e 100644 --- a/generative-ai/snippets/test/sendMultiModalPromptWithImage.test.js +++ b/generative-ai/snippets/test/sendMultiModalPromptWithImage.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Stream MultiModal with Image', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Stream MultiModal with Image', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should create stream multimodal content', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/sendMultiModalPromptWithVideo.test.js b/generative-ai/snippets/test/sendMultiModalPromptWithVideo.test.js index ee1cc0a006..81dd6f9c69 100644 --- a/generative-ai/snippets/test/sendMultiModalPromptWithVideo.test.js +++ b/generative-ai/snippets/test/sendMultiModalPromptWithVideo.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Stream MultiModal with Video', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Stream MultiModal with Video', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should create stream multimodal content', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/streamChat.test.js b/generative-ai/snippets/test/streamChat.test.js index 92fd2c659d..954f6955cf 100644 --- a/generative-ai/snippets/test/streamChat.test.js +++ b/generative-ai/snippets/test/streamChat.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Stream Chat', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Stream Chat', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should create stream chat and begin the conversation the same in each instance', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/streamContent.test.js b/generative-ai/snippets/test/streamContent.test.js index 309f8e6ac2..ebb6adcef8 100644 --- a/generative-ai/snippets/test/streamContent.test.js +++ b/generative-ai/snippets/test/streamContent.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Stream Content', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Stream Content', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; it('should create stream content', async () => { const output = execSync( diff --git a/generative-ai/snippets/test/streamMultipartContent.test.js b/generative-ai/snippets/test/streamMultipartContent.test.js index eef4bd20c1..6671ec45d6 100644 --- a/generative-ai/snippets/test/streamMultipartContent.test.js +++ b/generative-ai/snippets/test/streamMultipartContent.test.js @@ -21,7 +21,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; const location = process.env.LOCATION; -const model = 'gemini-1.5-flash-001'; +const model = 'gemini-2.0-flash-001'; describe('Generative AI Stream Multipart Content', () => { /** @@ -30,7 +30,7 @@ describe('Generative AI Stream Multipart Content', () => { */ // const projectId = 'YOUR_PROJECT_ID'; // const location = 'YOUR_LOCATION'; - // const model = 'gemini-1.5-flash-001'; + // const model = 'gemini-2.0-flash-001'; const image = 'gs://generativeai-downloads/images/scones.jpg';