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-create-features-sample.js b/ai-platform/snippets/batch-create-features-sample.js deleted file mode 100644 index 5659258134..0000000000 --- a/ai-platform/snippets/batch-create-features-sample.js +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Creates a batch of Features in a given EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_batch_create_features_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function batchCreateFeatures() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const ageFeature = { - valueType: 'INT64', - description: 'User age', - }; - - const ageFeatureRequest = { - feature: ageFeature, - featureId: 'age', - }; - - const genderFeature = { - valueType: 'STRING', - description: 'User gender', - }; - - const genderFeatureRequest = { - feature: genderFeature, - featureId: 'gender', - }; - - const likedGenresFeature = { - valueType: 'STRING_ARRAY', - description: 'An array of genres that this user liked', - }; - - const likedGenresFeatureRequest = { - feature: likedGenresFeature, - featureId: 'liked_genres', - }; - - const requests = [ - ageFeatureRequest, - genderFeatureRequest, - likedGenresFeatureRequest, - ]; - - const request = { - parent: parent, - requests: requests, - }; - - // Batch Create Features request - const [operation] = await featurestoreServiceClient.batchCreateFeatures( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Batch create features response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - batchCreateFeatures(); - // [END aiplatform_batch_create_features_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/batch-prediction/batch-predict-bq.js b/ai-platform/snippets/batch-prediction/batch-predict-bq.js deleted file mode 100644 index 175442cbdd..0000000000 --- a/ai-platform/snippets/batch-prediction/batch-predict-bq.js +++ /dev/null @@ -1,95 +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, outputUri) { - // [START generativeaionvertexai_batch_predict_gemini_createjob_bigquery] - // Import 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'; - // URI of the output BigQuery table. - // E.g. "bq://[PROJECT].[DATASET].[TABLE]" - // outputUri = 'bq://projectid.dataset.table'; - - // URI of the multimodal input BigQuery table. - // E.g. "bq://[PROJECT].[DATASET].[TABLE]" - const inputUri = - '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`; - - // Specify the location of the api endpoint. - const clientOptions = { - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiate the client. - const jobServiceClient = new aiplatformLib.JobServiceClient(clientOptions); - - // Create a Gemini batch prediction job using BigQuery input and output datasets. - async function create_batch_prediction_gemini_bq() { - const bqSource = new aiplatform.BigQuerySource({ - inputUri: inputUri, - }); - - const inputConfig = new aiplatform.BatchPredictionJob.InputConfig({ - bigquerySource: bqSource, - instancesFormat: 'bigquery', - }); - - const bqDestination = new aiplatform.BigQueryDestination({ - outputUri: outputUri, - }); - - const outputConfig = new aiplatform.BatchPredictionJob.OutputConfig({ - bigqueryDestination: bqDestination, - predictionsFormat: 'bigquery', - }); - - const batchPredictionJob = new aiplatform.BatchPredictionJob({ - displayName: 'Batch predict with Gemini - BigQuery', - model: modelName, // Add model parameters per request in the input BigQuery table. - inputConfig: inputConfig, - outputConfig: outputConfig, - }); - - const request = { - parent: parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - console.log('Response name: ', response.name); - // Example response: - // Response name: projects//locations/us-central1/batchPredictionJobs/ - } - - await create_batch_prediction_gemini_bq(); - // [END generativeaionvertexai_batch_predict_gemini_createjob_bigquery] -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/ai-platform/snippets/batch-prediction/batch-predict-gcs.js b/ai-platform/snippets/batch-prediction/batch-predict-gcs.js deleted file mode 100644 index 9ed5e1f707..0000000000 --- a/ai-platform/snippets/batch-prediction/batch-predict-gcs.js +++ /dev/null @@ -1,98 +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, outputUri) { - // [START generativeaionvertexai_batch_predict_gemini_createjob_gcs] - // Import 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'; - // URI of the output folder in Google Cloud Storage. - // E.g. "gs://[BUCKET]/[OUTPUT]" - // outputUri = 'gs://my-bucket'; - - // URI of the input file in Google Cloud Storage. - // E.g. "gs://[BUCKET]/[DATASET].jsonl" - // Or try: - // "gs://cloud-samples-data/generative-ai/batch/gemini_multimodal_batch_predict.jsonl" - // for a batch prediction that uses audio, video, and an image. - const inputUri = - '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`; - - // Specify the location of the api endpoint. - const clientOptions = { - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiate the client. - const jobServiceClient = new aiplatformLib.JobServiceClient(clientOptions); - - // Create a Gemini batch prediction job using Google Cloud Storage input and output buckets. - async function create_batch_prediction_gemini_gcs() { - const gcsSource = new aiplatform.GcsSource({ - uris: [inputUri], - }); - - const inputConfig = new aiplatform.BatchPredictionJob.InputConfig({ - gcsSource: gcsSource, - instancesFormat: 'jsonl', - }); - - const gcsDestination = new aiplatform.GcsDestination({ - outputUriPrefix: outputUri, - }); - - const outputConfig = new aiplatform.BatchPredictionJob.OutputConfig({ - gcsDestination: gcsDestination, - predictionsFormat: 'jsonl', - }); - - const batchPredictionJob = new aiplatform.BatchPredictionJob({ - displayName: 'Batch predict with Gemini - GCS', - model: modelName, - inputConfig: inputConfig, - outputConfig: outputConfig, - }); - - const request = { - parent: parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - console.log('Response name: ', response.name); - // Example response: - // Response name: projects//locations/us-central1/batchPredictionJobs/ - } - - await create_batch_prediction_gemini_gcs(); - // [END generativeaionvertexai_batch_predict_gemini_createjob_gcs] -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/ai-platform/snippets/batch-read-feature-values-sample.js b/ai-platform/snippets/batch-read-feature-values-sample.js deleted file mode 100644 index 75a198936f..0000000000 --- a/ai-platform/snippets/batch-read-feature-values-sample.js +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Batch reads Feature values from a Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - inputCsvFile, - destinationTableUri, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_batch_read_feature_values_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const inputCsvFile = 'YOUR_INPUT_CSV_FILE_URI'; - // const destinationTableUri = 'YOUR_BQ_DESTINATION_TABLE_URI'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function batchReadFeatureValues() { - // Configure the featurestoreId resource - const featurestore = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - const csvReadInstances = { - gcsSource: { - uris: [inputCsvFile], - }, - }; - - const destination = { - bigqueryDestination: { - // # Output to BigQuery table created earlier - outputUri: destinationTableUri, - }, - }; - - const usersFeatureSelector = { - idMatcher: { - ids: [ - // features, use "*" if you want to select all features within this entity type - 'age', - 'gender', - 'liked_genres', - ], - }, - }; - - const usersEntityTypeSpec = { - // Read the 'age', 'gender' and 'liked_genres' features from the 'perm_users' entity - entityTypeId: 'perm_users', - featureSelector: usersFeatureSelector, - }; - - const moviesFeatureSelector = { - idMatcher: { - ids: ['*'], - }, - }; - - const moviesEntityTypeSpec = { - // Read the all features from the 'perm_movies' entity - entityTypeId: 'perm_movies', - featureSelector: moviesFeatureSelector, - }; - - const entityTypeSpecs = [usersEntityTypeSpec, moviesEntityTypeSpec]; - - // Construct request - const request = { - featurestore: featurestore, - csvReadInstances: csvReadInstances, - destination: destination, - entityTypeSpecs: entityTypeSpecs, - }; - - // Batch Read Feature Values Request - const [operation] = await featurestoreServiceClient.batchReadFeatureValues( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Batch read feature values response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - batchReadFeatureValues(); - // [END aiplatform_batch_read_feature_values_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); 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/cancel-custom-job.js b/ai-platform/snippets/cancel-custom-job.js deleted file mode 100644 index b7e56cafb3..0000000000 --- a/ai-platform/snippets/cancel-custom-job.js +++ /dev/null @@ -1,61 +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_cancel_custom_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - */ - - // 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 cancelCustomJob() { - // Configure the name resource - const name = jobServiceClient.customJobPath(project, location, customJobId); - const request = { - name, - }; - - // Cancel custom job request - const [response] = await jobServiceClient.cancelCustomJob(request); - - console.log('Cancel custom job response:\n', response); - } - cancelCustomJob(); - // [END aiplatform_cancel_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/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-text-classification.js b/ai-platform/snippets/create-batch-prediction-job-text-classification.js deleted file mode 100644 index f9cc5f3504..0000000000 --- a/ai-platform/snippets/create-batch-prediction-job-text-classification.js +++ /dev/null @@ -1,93 +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'; - -async function main( - batchPredictionDisplayName, - modelId, - gcsSourceUri, - gcsDestinationOutputUriPrefix, - project, - location = 'us-central1' -) { - // [START aiplatform_create_batch_prediction_job_text_classification_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:///destination_path" - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // 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 createBatchPredictionJobTextClassification() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const modelName = `projects/${project}/locations/${location}/models/${modelId}`; - - const inputConfig = { - instancesFormat: 'jsonl', - gcsSource: {uris: [gcsSourceUri]}, - }; - const outputConfig = { - predictionsFormat: 'jsonl', - gcsDestination: {outputUriPrefix: gcsDestinationOutputUriPrefix}, - }; - const batchPredictionJob = { - displayName: batchPredictionDisplayName, - model: modelName, - inputConfig, - outputConfig, - }; - const request = { - parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - - console.log('Create batch prediction job text classification response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createBatchPredictionJobTextClassification(); - // [END aiplatform_create_batch_prediction_job_text_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-batch-prediction-job-text-entity-extraction.js b/ai-platform/snippets/create-batch-prediction-job-text-entity-extraction.js deleted file mode 100644 index 4497c777a9..0000000000 --- a/ai-platform/snippets/create-batch-prediction-job-text-entity-extraction.js +++ /dev/null @@ -1,93 +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'; - -async function main( - batchPredictionDisplayName, - modelId, - gcsSourceUri, - gcsDestinationOutputUriPrefix, - project, - location = 'us-central1' -) { - // [START aiplatform_create_batch_prediction_job_text_entity_extraction_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:///destination_path" - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // 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 createBatchPredictionJobTextEntityExtraction() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const modelName = `projects/${project}/locations/${location}/models/${modelId}`; - - const inputConfig = { - instancesFormat: 'jsonl', - gcsSource: {uris: [gcsSourceUri]}, - }; - const outputConfig = { - predictionsFormat: 'jsonl', - gcsDestination: {outputUriPrefix: gcsDestinationOutputUriPrefix}, - }; - const batchPredictionJob = { - displayName: batchPredictionDisplayName, - model: modelName, - inputConfig, - outputConfig, - }; - const request = { - parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - - console.log('Create batch prediction job text entity extraction response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createBatchPredictionJobTextEntityExtraction(); - // [END aiplatform_create_batch_prediction_job_text_entity_extraction_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-batch-prediction-job-text-sentiment-analysis.js b/ai-platform/snippets/create-batch-prediction-job-text-sentiment-analysis.js deleted file mode 100644 index db85e5996c..0000000000 --- a/ai-platform/snippets/create-batch-prediction-job-text-sentiment-analysis.js +++ /dev/null @@ -1,93 +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'; - -async function main( - batchPredictionDisplayName, - modelId, - gcsSourceUri, - gcsDestinationOutputUriPrefix, - project, - location = 'us-central1' -) { - // [START aiplatform_create_batch_prediction_job_text_sentiment_analysis_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:///destination_path" - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // 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 createBatchPredictionJobTextSentimentAnalysis() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const modelName = `projects/${project}/locations/${location}/models/${modelId}`; - - const inputConfig = { - instancesFormat: 'jsonl', - gcsSource: {uris: [gcsSourceUri]}, - }; - const outputConfig = { - predictionsFormat: 'jsonl', - gcsDestination: {outputUriPrefix: gcsDestinationOutputUriPrefix}, - }; - const batchPredictionJob = { - displayName: batchPredictionDisplayName, - model: modelName, - inputConfig, - outputConfig, - }; - const request = { - parent, - batchPredictionJob, - }; - - // Create batch prediction job request - const [response] = await jobServiceClient.createBatchPredictionJob(request); - - console.log('Create batch prediction job text sentiment analysis response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createBatchPredictionJobTextSentimentAnalysis(); - // [END aiplatform_create_batch_prediction_job_text_sentiment_analysis_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); 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:///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-batch-prediction-job-video-classification.js b/ai-platform/snippets/create-batch-prediction-job-video-classification.js deleted file mode 100644 index 6208ffb89a..0000000000 --- a/ai-platform/snippets/create-batch-prediction-job-video-classification.js +++ /dev/null @@ -1,108 +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( - batchPredictionDisplayName, - modelId, - gcsSourceUri, - gcsDestinationOutputUriPrefix, - project, - location = 'us-central1' -) { - // [START aiplatform_create_batch_prediction_job_video_classification_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:///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 createBatchPredictionJobVideoClassification() { - // 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.VideoClassificationPredictionParams({ - confidenceThreshold: 0.5, - maxPredictions: 1000, - segmentClassification: true, - shotClassification: true, - oneSecIntervalClassification: true, - }); - - 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 classification response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createBatchPredictionJobVideoClassification(); - // [END aiplatform_create_batch_prediction_job_video_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-batch-prediction-job-video-object-tracking.js b/ai-platform/snippets/create-batch-prediction-job-video-object-tracking.js deleted file mode 100644 index 0e5b898efd..0000000000 --- a/ai-platform/snippets/create-batch-prediction-job-video-object-tracking.js +++ /dev/null @@ -1,104 +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( - batchPredictionDisplayName, - modelId, - gcsSourceUri, - gcsDestinationOutputUriPrefix, - project, - location = 'us-central1' -) { - // [START aiplatform_create_batch_prediction_job_video_object_tracking_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:///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 createBatchPredictionJobVideoObjectTracking() { - // 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.VideoObjectTrackingPredictionParams({ - 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 object tracking response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createBatchPredictionJobVideoObjectTracking(); - // [END aiplatform_create_batch_prediction_job_video_object_tracking_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 deleted file mode 100644 index cae369024e..0000000000 --- a/ai-platform/snippets/create-custom-job.js +++ /dev/null @@ -1,86 +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( - customJobDisplayName, - containerImageUri, - project, - location = 'us-central1' -) { - // [START aiplatform_create_custom_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const customJobDisplayName = 'YOUR_CUSTOM_JOB_DISPLAY_NAME'; - // const containerImageUri = 'YOUR_CONTAINER_IMAGE_URI'; - // 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 createCustomJob() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const customJob = { - displayName: customJobDisplayName, - jobSpec: { - workerPoolSpecs: [ - { - machineSpec: { - machineType: 'n1-standard-4', - acceleratorType: 'NVIDIA_TESLA_K80', - acceleratorCount: 1, - }, - replicaCount: 1, - containerSpec: { - imageUri: containerImageUri, - command: [], - args: [], - }, - }, - ], - }, - }; - const request = {parent, customJob}; - - // Create custom job request - const [response] = await jobServiceClient.createCustomJob(request); - - console.log('Create custom job response:\n', JSON.stringify(response)); - } - createCustomJob(); - // [END aiplatform_create_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/create-dataset-image.js b/ai-platform/snippets/create-dataset-image.js deleted file mode 100644 index 0335351825..0000000000 --- a/ai-platform/snippets/create-dataset-image.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(datasetDisplayName, project, location = 'us-central1') { - // [START aiplatform_create_dataset_image_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetDisplayName = "YOUR_DATASTE_DISPLAY_NAME"; - // 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', - }; - - // Instantiates a client - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function createDatasetImage() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - // Configure the dataset resource - const dataset = { - displayName: datasetDisplayName, - metadataSchemaUri: - 'gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml', - }; - const request = { - parent, - dataset, - }; - - // Create Dataset Request - const [response] = await datasetServiceClient.createDataset(request); - console.log(`Long running operation: ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Create dataset image response'); - console.log(`Name : ${result.name}`); - console.log(`Display name : ${result.displayName}`); - console.log(`Metadata schema uri : ${result.metadataSchemaUri}`); - console.log(`Metadata : ${JSON.stringify(result.metadata)}`); - console.log(`Labels : ${JSON.stringify(result.labels)}`); - } - createDatasetImage(); - // [END aiplatform_create_dataset_image_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-dataset-tabular-bigquery.js b/ai-platform/snippets/create-dataset-tabular-bigquery.js deleted file mode 100644 index a68b3b8331..0000000000 --- a/ai-platform/snippets/create-dataset-tabular-bigquery.js +++ /dev/null @@ -1,108 +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( - datasetDisplayName, - bigquerySourceUri, - project, - location = 'us-central1' -) { - // [START aiplatform_create_dataset_tabular_bigquery_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetDisplayName = 'YOUR_DATASET_DISPLAY_NAME'; - // const bigquerySourceUri = 'YOUR_BIGQUERY_SOURCE_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', - }; - - // Instantiates a client - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function createDatasetTabularBigquery() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const metadata = { - structValue: { - fields: { - inputConfig: { - structValue: { - fields: { - bigquerySource: { - structValue: { - fields: { - uri: { - listValue: { - values: [{stringValue: bigquerySourceUri}], - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }; - // Configure the dataset resource - const dataset = { - displayName: datasetDisplayName, - metadataSchemaUri: - 'gs://google-cloud-aiplatform/schema/dataset/metadata/tabular_1.0.0.yaml', - metadata: metadata, - }; - const request = { - parent, - dataset, - }; - - // Create dataset request - const [response] = await datasetServiceClient.createDataset(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Create dataset tabular bigquery response'); - console.log(`\tName : ${result.name}`); - console.log(`\tDisplay name : ${result.displayName}`); - console.log(`\tMetadata schema uri : ${result.metadataSchemaUri}`); - console.log(`\tMetadata : ${JSON.stringify(result.metadata)}`); - } - createDatasetTabularBigquery(); - // [END aiplatform_create_dataset_tabular_bigquery_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-dataset-tabular-gcs.js b/ai-platform/snippets/create-dataset-tabular-gcs.js deleted file mode 100644 index 34dd8bf312..0000000000 --- a/ai-platform/snippets/create-dataset-tabular-gcs.js +++ /dev/null @@ -1,108 +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( - datasetDisplayName, - gcsSourceUri, - project, - location = 'us-central1' -) { - // [START aiplatform_create_dataset_tabular_gcs_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetDisplayName = 'YOUR_DATASET_DISPLAY_NAME'; - // const gcsSourceUri = 'YOUR_GCS_SOURCE_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', - }; - - // Instantiates a client - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function createDatasetTabularGcs() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const metadata = { - structValue: { - fields: { - inputConfig: { - structValue: { - fields: { - gcsSource: { - structValue: { - fields: { - uri: { - listValue: { - values: [{stringValue: gcsSourceUri}], - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }; - // Configure the dataset resource - const dataset = { - displayName: datasetDisplayName, - metadataSchemaUri: - 'gs://google-cloud-aiplatform/schema/dataset/metadata/tabular_1.0.0.yaml', - metadata: metadata, - }; - const request = { - parent, - dataset, - }; - - // Create dataset request - const [response] = await datasetServiceClient.createDataset(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Create dataset tabular gcs response'); - console.log(`\tName : ${result.name}`); - console.log(`\tDisplay name : ${result.displayName}`); - console.log(`\tMetadata schema uri : ${result.metadataSchemaUri}`); - console.log(`\tMetadata : ${JSON.stringify(result.metadata)}`); - } - createDatasetTabularGcs(); - // [END aiplatform_create_dataset_tabular_gcs_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-dataset-text.js b/ai-platform/snippets/create-dataset-text.js deleted file mode 100644 index 93b99be7e5..0000000000 --- a/ai-platform/snippets/create-dataset-text.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(datasetDisplayName, project, location = 'us-central1') { - // [START aiplatform_create_dataset_text_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetDisplayName = "YOUR_DATASTE_DISPLAY_NAME"; - // 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', - }; - - // Instantiates a client - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function createDatasetText() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - // Configure the dataset resource - const dataset = { - displayName: datasetDisplayName, - metadataSchemaUri: - 'gs://google-cloud-aiplatform/schema/dataset/metadata/text_1.0.0.yaml', - }; - const request = { - parent, - dataset, - }; - - // Create Dataset Request - const [response] = await datasetServiceClient.createDataset(request); - console.log(`Long running operation: ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Create dataset text response'); - console.log(`Name : ${result.name}`); - console.log(`Display name : ${result.displayName}`); - console.log(`Metadata schema uri : ${result.metadataSchemaUri}`); - console.log(`Metadata : ${JSON.stringify(result.metadata)}`); - console.log(`Labels : ${JSON.stringify(result.labels)}`); - } - createDatasetText(); - // [END aiplatform_create_dataset_text_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-dataset-video.js b/ai-platform/snippets/create-dataset-video.js deleted file mode 100644 index 04c6c2e74a..0000000000 --- a/ai-platform/snippets/create-dataset-video.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(datasetDisplayName, project, location = 'us-central1') { - // [START aiplatform_create_dataset_video_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetDisplayName = "YOUR_DATASTE_DISPLAY_NAME"; - // 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', - }; - - // Instantiates a client - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function createDatasetVideo() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - // Configure the dataset resource - const dataset = { - displayName: datasetDisplayName, - metadataSchemaUri: - 'gs://google-cloud-aiplatform/schema/dataset/metadata/video_1.0.0.yaml', - }; - const request = { - parent, - dataset, - }; - - // Create Dataset Request - const [response] = await datasetServiceClient.createDataset(request); - console.log(`Long running operation: ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Create dataset video response'); - console.log(`Name : ${result.name}`); - console.log(`Display name : ${result.displayName}`); - console.log(`Metadata schema uri : ${result.metadataSchemaUri}`); - console.log(`Metadata : ${JSON.stringify(result.metadata)}`); - console.log(`Labels : ${JSON.stringify(result.labels)}`); - } - createDatasetVideo(); - // [END aiplatform_create_dataset_video_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-dataset.js b/ai-platform/snippets/create-dataset.js deleted file mode 100644 index bf87a34f5c..0000000000 --- a/ai-platform/snippets/create-dataset.js +++ /dev/null @@ -1,89 +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( - datasetDisplayName, - metadataSchemaUri, - project, - location = 'us-central1' -) { - // [START aiplatform_create_dataset_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetDisplayName = 'YOUR_DATASET_DISPLAY_NAME'; - // const metadataSchemaUri = 'YOUR_METADATA_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', - }; - - // Instantiates a client - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function createDataset() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - // Configure the dataset resource - const dataset = { - displayName: datasetDisplayName, - metadataSchemaUri: metadataSchemaUri, - }; - const request = { - parent, - dataset, - }; - - // Create Dataset Request - const [response] = await datasetServiceClient.createDataset(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - const [createDatasetResponse] = await response.promise(); - - console.log('Create dataset response'); - console.log(`\tName : ${createDatasetResponse.name}`); - console.log(`\tDisplay name : ${createDatasetResponse.displayName}`); - console.log( - `\tMetadata schema uri : ${createDatasetResponse.metadataSchemaUri}` - ); - console.log( - `\tMetadata : ${JSON.stringify(createDatasetResponse.metadata)}` - ); - console.log(`\tCreate time : ${createDatasetResponse.createTime}`); - console.log(`\tUpdate time : ${createDatasetResponse.updateTime}`); - console.log(`\tLabels : ${JSON.stringify(createDatasetResponse.labels)}`); - } - createDataset(); - // [END aiplatform_create_dataset_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-endpoint.js b/ai-platform/snippets/create-endpoint.js deleted file mode 100644 index 1a1abbadbd..0000000000 --- a/ai-platform/snippets/create-endpoint.js +++ /dev/null @@ -1,77 +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(endpointDisplayName, project, location = 'us-central1') { - // [START aiplatform_create_endpoint_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const endpointDisplayName = 'YOUR_ENDPOINT_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // 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 createEndpoint() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - const endpoint = { - displayName: endpointDisplayName, - }; - const request = { - parent, - endpoint, - }; - - // Get and print out a list of all the endpoints for this resource - const [response] = await endpointServiceClient.createEndpoint(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Create endpoint response'); - console.log(`\tName : ${result.name}`); - console.log(`\tDisplay name : ${result.displayName}`); - console.log(`\tDescription : ${result.description}`); - console.log(`\tLabels : ${JSON.stringify(result.labels)}`); - console.log(`\tCreate time : ${JSON.stringify(result.createTime)}`); - console.log(`\tUpdate time : ${JSON.stringify(result.updateTime)}`); - } - createEndpoint(); - // [END aiplatform_create_endpoint_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-entity-type-monitoring-sample.js b/ai-platform/snippets/create-entity-type-monitoring-sample.js deleted file mode 100644 index d244484751..0000000000 --- a/ai-platform/snippets/create-entity-type-monitoring-sample.js +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Creates a new EntityType with monitoring configuration in a given Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - description, - duration = 86400, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_create_entity_type_monitoring_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const description = 'YOUR_ENTITY_TYPE_DESCRIPTION'; - // const duration = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = - require('@google-cloud/aiplatform').v1beta1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function createEntityTypeMonitoring() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const entityType = { - description: description, - monitoringConfig: { - snapshotAnalysis: { - monitoringInterval: { - seconds: Number(duration), - }, - }, - }, - }; - - const request = { - parent: parent, - entityTypeId: entityTypeId, - entityType: entityType, - }; - - // Create EntityType request - const [operation] = await featurestoreServiceClient.createEntityType( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Create entity type monitoring response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createEntityTypeMonitoring(); - // [END aiplatform_create_entity_type_monitoring_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-entity-type-sample.js b/ai-platform/snippets/create-entity-type-sample.js deleted file mode 100644 index fe867db22d..0000000000 --- a/ai-platform/snippets/create-entity-type-sample.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Creates a new EntityType in a given Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - description, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_create_entity_type_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const description = 'YOUR_ENTITY_TYPE_DESCRIPTION'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function createEntityType() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const entityType = { - description: description, - }; - - const request = { - parent: parent, - entityTypeId: entityTypeId, - entityType: entityType, - }; - - // Create EntityType request - const [operation] = await featurestoreServiceClient.createEntityType( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Create entity type response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createEntityType(); - // [END aiplatform_create_entity_type_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-feature-sample.js b/ai-platform/snippets/create-feature-sample.js deleted file mode 100644 index e637f89057..0000000000 --- a/ai-platform/snippets/create-feature-sample.js +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Creates a new Feature in a given EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - featureId, - valueType, - description, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_create_feature_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const featureId = 'YOUR_FEATURE_ID'; - // const valueType = 'FEATURE_VALUE_DATA_TYPE'; - // const description = 'YOUR_ENTITY_TYPE_DESCRIPTION'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function createFeature() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const feature = { - valueType: valueType, - description: description, - }; - - const request = { - parent: parent, - feature: feature, - featureId: featureId, - }; - - // Create Feature request - const [operation] = await featurestoreServiceClient.createFeature(request, { - timeout: Number(timeout), - }); - const [response] = await operation.promise(); - - console.log('Create feature response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createFeature(); - // [END aiplatform_create_feature_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-featurestore-fixed-nodes-sample.js b/ai-platform/snippets/create-featurestore-fixed-nodes-sample.js deleted file mode 100644 index 6fcd87be62..0000000000 --- a/ai-platform/snippets/create-featurestore-fixed-nodes-sample.js +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Creates a new Featurestore with fixed nodes configuration in a given project and location. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - fixedNodeCount = 1, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 900000 -) { - // [START aiplatform_create_featurestore_fixed_nodes_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const fixedNodeCount = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function createFeaturestoreFixedNodes() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const featurestore = { - onlineServingConfig: {fixedNodeCount: Number(fixedNodeCount)}, - }; - - const request = { - parent: parent, - featurestore: featurestore, - featurestoreId: featurestoreId, - }; - - // Create Featurestore request - const [operation] = await featurestoreServiceClient.createFeaturestore( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Create featurestore fixed nodes response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createFeaturestoreFixedNodes(); - // [END aiplatform_create_featurestore_fixed_nodes_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-featurestore-sample.js b/ai-platform/snippets/create-featurestore-sample.js deleted file mode 100644 index a4933a544e..0000000000 --- a/ai-platform/snippets/create-featurestore-sample.js +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Creates a new Featurestore in a given project and location. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - minNodeCount = 1, - maxNodeCount = 5, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 900000 -) { - // [START aiplatform_create_featurestore_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const minNodeCount = ; - // const maxNodeCount = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = - require('@google-cloud/aiplatform').v1beta1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function createFeaturestore() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const featurestore = { - onlineServingConfig: { - scaling: { - minNodeCount: minNodeCount, - maxNodeCount: maxNodeCount, - }, - }, - }; - - const request = { - parent: parent, - featurestore: featurestore, - featurestoreId: featurestoreId, - }; - - // Create Featurestore request - const [operation] = await featurestoreServiceClient.createFeaturestore( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Create featurestore response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createFeaturestore(); - // [END aiplatform_create_featurestore_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-hyperparameter-tuning-job.js b/ai-platform/snippets/create-hyperparameter-tuning-job.js deleted file mode 100644 index d6803a57e9..0000000000 --- a/ai-platform/snippets/create-hyperparameter-tuning-job.js +++ /dev/null @@ -1,113 +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( - displayName, - containerImageUri, - project, - location = 'us-central1' -) { - // [START aiplatform_create_hyperparameter_tuning_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample. - * (Not necessary if passing values as arguments) - */ - /* - const displayName = 'YOUR HYPERPARAMETER TUNING JOB; - const containerImageUri = 'TUNING JOB CONTAINER URI; - const project = 'YOUR PROJECT ID'; - const location = 'us-central1'; - */ - // Imports the Google Cloud Pipeline 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 createHyperParameterTuningJob() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - // Create the hyperparameter tuning job configuration - const hyperparameterTuningJob = { - displayName, - maxTrialCount: 2, - parallelTrialCount: 1, - maxFailedTrialCount: 1, - studySpec: { - metrics: [ - { - metricId: 'accuracy', - goal: 'MAXIMIZE', - }, - ], - parameters: [ - { - parameterId: 'lr', - doubleValueSpec: { - minValue: 0.001, - maxValue: 0.1, - }, - }, - ], - }, - trialJobSpec: { - workerPoolSpecs: [ - { - machineSpec: { - machineType: 'n1-standard-4', - acceleratorType: 'NVIDIA_TESLA_K80', - acceleratorCount: 1, - }, - replicaCount: 1, - containerSpec: { - imageUri: containerImageUri, - command: [], - args: [], - }, - }, - ], - }, - }; - - const [response] = await jobServiceClient.createHyperparameterTuningJob({ - parent, - hyperparameterTuningJob, - }); - - console.log('Create hyperparameter tuning job response:'); - console.log(`\tDisplay name: ${response.displayName}`); - console.log(`\tTuning job resource name: ${response.name}`); - console.log(`\tJob status: ${response.state}`); - } - - createHyperParameterTuningJob(); - // [END aiplatform_create_hyperparameter_tuning_job_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-image-classification.js b/ai-platform/snippets/create-training-pipeline-image-classification.js deleted file mode 100644 index 9cc566057b..0000000000 --- a/ai-platform/snippets/create-training-pipeline-image-classification.js +++ /dev/null @@ -1,102 +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( - datasetId, - modelDisplayName, - trainingPipelineDisplayName, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_image_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample. - * (Not necessary if passing values as arguments) - */ - /* - const datasetId = 'YOUR DATASET'; - const modelDisplayName = 'NEW MODEL NAME; - const trainingPipelineDisplayName = 'NAME FOR TRAINING PIPELINE'; - const project = 'YOUR PROJECT ID'; - const location = 'us-central1'; - */ - // Imports the Google Cloud Pipeline Service Client library - const aiplatform = require('@google-cloud/aiplatform'); - - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - const ModelType = definition.AutoMlImageClassificationInputs.ModelType; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const {PipelineServiceClient} = aiplatform.v1; - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineImageClassification() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - // Values should match the input expected by your model. - const trainingTaskInputsMessage = - new definition.AutoMlImageClassificationInputs({ - multiLabel: true, - modelType: ModelType.CLOUD, - budgetMilliNodeHours: 8000, - disableEarlyStopping: false, - }); - - const trainingTaskInputs = trainingTaskInputsMessage.toValue(); - - const trainingTaskDefinition = - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_image_classification_1.0.0.yaml'; - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = {datasetId}; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition, - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = {parent, trainingPipeline}; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline image classification response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - - createTrainingPipelineImageClassification(); - // [END aiplatform_create_training_pipeline_image_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-image-object-detection.js b/ai-platform/snippets/create-training-pipeline-image-object-detection.js deleted file mode 100644 index b790c037ab..0000000000 --- a/ai-platform/snippets/create-training-pipeline-image-object-detection.js +++ /dev/null @@ -1,99 +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, - modelDisplayName, - trainingPipelineDisplayName, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_image_object_detection_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - const ModelType = definition.AutoMlImageObjectDetectionInputs.ModelType; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineImageObjectDetection() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const trainingTaskInputsObj = - new definition.AutoMlImageObjectDetectionInputs({ - disableEarlyStopping: false, - modelType: ModelType.CLOUD_1, - budgetMilliNodeHours: 20000, - }); - - const trainingTaskInputs = trainingTaskInputsObj.toValue(); - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = {datasetId: datasetId}; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_image_object_detection_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline image object detection response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineImageObjectDetection(); - // [END aiplatform_create_training_pipeline_image_object_detection_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-tabular-classification.js b/ai-platform/snippets/create-training-pipeline-tabular-classification.js deleted file mode 100644 index 6e1e974566..0000000000 --- a/ai-platform/snippets/create-training-pipeline-tabular-classification.js +++ /dev/null @@ -1,113 +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, - modelDisplayName, - trainingPipelineDisplayName, - targetColumn, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_tabular_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const targetColumn = 'YOUR_TARGET_COLUMN'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineTablesClassification() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const transformations = [ - {auto: {column_name: 'sepal_width'}}, - {auto: {column_name: 'sepal_length'}}, - {auto: {column_name: 'petal_length'}}, - {auto: {column_name: 'petal_width'}}, - ]; - const trainingTaskInputsObj = new definition.AutoMlTablesInputs({ - targetColumn: targetColumn, - predictionType: 'classification', - transformations: transformations, - trainBudgetMilliNodeHours: 8000, - disableEarlyStopping: false, - optimizationObjective: 'minimize-log-loss', - }); - const trainingTaskInputs = trainingTaskInputsObj.toValue(); - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = { - datasetId: datasetId, - fractionSplit: { - trainingFraction: 0.8, - validationFraction: 0.1, - testFraction: 0.1, - }, - }; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_tables_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline tabular classification response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineTablesClassification(); - // [END aiplatform_create_training_pipeline_tabular_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-tabular-regression.js b/ai-platform/snippets/create-training-pipeline-tabular-regression.js deleted file mode 100644 index d20433fa15..0000000000 --- a/ai-platform/snippets/create-training-pipeline-tabular-regression.js +++ /dev/null @@ -1,138 +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, - modelDisplayName, - trainingPipelineDisplayName, - targetColumn, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_tabular_regression_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const targetColumn = 'YOUR_TARGET_COLUMN'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineTablesRegression() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const transformations = [ - {auto: {column_name: 'STRING_5000unique_NULLABLE'}}, - {auto: {column_name: 'INTEGER_5000unique_NULLABLE'}}, - {auto: {column_name: 'FLOAT_5000unique_NULLABLE'}}, - {auto: {column_name: 'FLOAT_5000unique_REPEATED'}}, - {auto: {column_name: 'NUMERIC_5000unique_NULLABLE'}}, - {auto: {column_name: 'BOOLEAN_2unique_NULLABLE'}}, - { - timestamp: { - column_name: 'TIMESTAMP_1unique_NULLABLE', - invalid_values_allowed: true, - }, - }, - {auto: {column_name: 'DATE_1unique_NULLABLE'}}, - {auto: {column_name: 'TIME_1unique_NULLABLE'}}, - { - timestamp: { - column_name: 'DATETIME_1unique_NULLABLE', - invalid_values_allowed: true, - }, - }, - {auto: {column_name: 'STRUCT_NULLABLE.STRING_5000unique_NULLABLE'}}, - {auto: {column_name: 'STRUCT_NULLABLE.INTEGER_5000unique_NULLABLE'}}, - {auto: {column_name: 'STRUCT_NULLABLE.FLOAT_5000unique_NULLABLE'}}, - {auto: {column_name: 'STRUCT_NULLABLE.FLOAT_5000unique_REQUIRED'}}, - {auto: {column_name: 'STRUCT_NULLABLE.FLOAT_5000unique_REPEATED'}}, - {auto: {column_name: 'STRUCT_NULLABLE.NUMERIC_5000unique_NULLABLE'}}, - {auto: {column_name: 'STRUCT_NULLABLE.BOOLEAN_2unique_NULLABLE'}}, - {auto: {column_name: 'STRUCT_NULLABLE.TIMESTAMP_1unique_NULLABLE'}}, - ]; - - const trainingTaskInputsObj = new definition.AutoMlTablesInputs({ - transformations, - targetColumn, - predictionType: 'regression', - trainBudgetMilliNodeHours: 8000, - disableEarlyStopping: false, - optimizationObjective: 'minimize-rmse', - }); - const trainingTaskInputs = trainingTaskInputsObj.toValue(); - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = { - datasetId: datasetId, - fractionSplit: { - trainingFraction: 0.8, - validationFraction: 0.1, - testFraction: 0.1, - }, - }; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_tables_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline tabular regression response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineTablesRegression(); - // [END aiplatform_create_training_pipeline_tabular_regression_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-text-classification.js b/ai-platform/snippets/create-training-pipeline-text-classification.js deleted file mode 100644 index fe87e941da..0000000000 --- a/ai-platform/snippets/create-training-pipeline-text-classification.js +++ /dev/null @@ -1,94 +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, - modelDisplayName, - trainingPipelineDisplayName, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_text_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineTextClassification() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const trainingTaskInputObj = new definition.AutoMlTextClassificationInputs({ - multiLabel: false, - }); - const trainingTaskInputs = trainingTaskInputObj.toValue(); - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = {datasetId: datasetId}; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_text_classification_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline text classification response :'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineTextClassification(); - // [END aiplatform_create_training_pipeline_text_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-text-entity-extraction.js b/ai-platform/snippets/create-training-pipeline-text-entity-extraction.js deleted file mode 100644 index d0dc802b61..0000000000 --- a/ai-platform/snippets/create-training-pipeline-text-entity-extraction.js +++ /dev/null @@ -1,92 +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, - modelDisplayName, - trainingPipelineDisplayName, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_text_entity_extraction_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineTextEntityExtraction() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const trainingTaskInputObj = new definition.AutoMlTextExtractionInputs({}); - const trainingTaskInputs = trainingTaskInputObj.toValue(); - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = {datasetId: datasetId}; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_text_extraction_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline text entity extraction response :'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineTextEntityExtraction(); - // [END aiplatform_create_training_pipeline_text_entity_extraction_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-text-sentiment-analysis.js b/ai-platform/snippets/create-training-pipeline-text-sentiment-analysis.js deleted file mode 100644 index 1059437fb9..0000000000 --- a/ai-platform/snippets/create-training-pipeline-text-sentiment-analysis.js +++ /dev/null @@ -1,94 +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, - modelDisplayName, - trainingPipelineDisplayName, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_text_sentiment_analysis_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineTextSentimentAnalysis() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const trainingTaskInputObj = new definition.AutoMlTextSentimentInputs({ - sentimentMax: 4, - }); - const trainingTaskInputs = trainingTaskInputObj.toValue(); - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = {datasetId: datasetId}; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_text_sentiment_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline text sentiment analysis response :'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineTextSentimentAnalysis(); - // [END aiplatform_create_training_pipeline_text_sentiment_analysis_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-video-action-recognition.js b/ai-platform/snippets/create-training-pipeline-video-action-recognition.js deleted file mode 100644 index accb3de20b..0000000000 --- a/ai-platform/snippets/create-training-pipeline-video-action-recognition.js +++ /dev/null @@ -1,96 +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, - modelDisplayName, - trainingPipelineDisplayName, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_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 modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineVideoActionRecognition() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - // Values should match the input expected by your model. - const trainingTaskInputObj = - new definition.AutoMlVideoActionRecognitionInputs({ - // modelType can be either 'CLOUD' or 'MOBILE_VERSATILE_1' - modelType: 'CLOUD', - }); - const trainingTaskInputs = trainingTaskInputObj.toValue(); - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = {datasetId: datasetId}; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_video_action_recognition_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline video action recognition response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineVideoActionRecognition(); - // [END aiplatform_create_training_pipeline_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-training-pipeline-video-classification.js b/ai-platform/snippets/create-training-pipeline-video-classification.js deleted file mode 100644 index 3989c4c2a6..0000000000 --- a/ai-platform/snippets/create-training-pipeline-video-classification.js +++ /dev/null @@ -1,94 +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, - modelDisplayName, - trainingPipelineDisplayName, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_video_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineVideoClassification() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - // Values should match the input expected by your model. - const trainingTaskInputObj = new definition.AutoMlVideoClassificationInputs( - {} - ); - const trainingTaskInputs = trainingTaskInputObj.toValue(); - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = {datasetId: datasetId}; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_video_classification_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline video classification response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineVideoClassification(); - // [END aiplatform_create_training_pipeline_video_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/create-training-pipeline-video-object-tracking.js b/ai-platform/snippets/create-training-pipeline-video-object-tracking.js deleted file mode 100644 index 42fc795e38..0000000000 --- a/ai-platform/snippets/create-training-pipeline-video-object-tracking.js +++ /dev/null @@ -1,96 +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, - modelDisplayName, - trainingPipelineDisplayName, - project, - location = 'us-central1' -) { - // [START aiplatform_create_training_pipeline_video_object_tracking_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {definition} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; - const ModelType = definition.AutoMlVideoObjectTrackingInputs.ModelType; - - // Imports the Google Cloud Pipeline Service Client library - const {PipelineServiceClient} = aiplatform.v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function createTrainingPipelineVideoObjectTracking() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const trainingTaskInputsObj = - new definition.AutoMlVideoObjectTrackingInputs({ - modelType: ModelType.CLOUD, - }); - const trainingTaskInputs = trainingTaskInputsObj.toValue(); - - const modelToUpload = {displayName: modelDisplayName}; - const inputDataConfig = {datasetId: datasetId}; - const trainingPipeline = { - displayName: trainingPipelineDisplayName, - trainingTaskDefinition: - 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_video_object_tracking_1.0.0.yaml', - trainingTaskInputs, - inputDataConfig, - modelToUpload, - }; - const request = { - parent, - trainingPipeline, - }; - - // Create training pipeline request - const [response] = - await pipelineServiceClient.createTrainingPipeline(request); - - console.log('Create training pipeline video object tracking response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - createTrainingPipelineVideoObjectTracking(); - // [END aiplatform_create_training_pipeline_video_object_tracking_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); 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-dataset.js b/ai-platform/snippets/delete-dataset.js deleted file mode 100644 index 6b6da42e57..0000000000 --- a/ai-platform/snippets/delete-dataset.js +++ /dev/null @@ -1,65 +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, project, location = 'us-central1') { - // [START aiplatform_delete_dataset_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // 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', - }; - - // Instantiates a client - const datasetServiceClient = new DatasetServiceClient(clientOptions); - - async function deleteDataset() { - // Configure the resource - const name = datasetServiceClient.datasetPath(project, location, datasetId); - const request = {name}; - - // Delete Dataset Request - const [response] = await datasetServiceClient.deleteDataset(request); - console.log(`Long running operation: ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Delete dataset response:\n', result); - } - deleteDataset(); - // [END aiplatform_delete_dataset_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/delete-endpoint.js b/ai-platform/snippets/delete-endpoint.js deleted file mode 100644 index aa66ece8e1..0000000000 --- a/ai-platform/snippets/delete-endpoint.js +++ /dev/null @@ -1,69 +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(endpointId, project, location = 'us-central1') { - // [START aiplatform_delete_endpoint_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const endpointId = 'YOUR_ENDPOINT_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // 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 deleteEndpoint() { - // Configure the parent resource - const endpoint = { - name: `projects/${project}/locations/${location}/endpoints/${endpointId}`, - }; - - // NOTE: Be sure to undeploy any models deployed to the endpoint before - // attempting to delete the endpoint. - - // Delete endpoint request - const [response] = await endpointServiceClient.deleteEndpoint(endpoint); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Delete endpoint response:\n', result); - } - deleteEndpoint(); - // [END aiplatform_delete_endpoint_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/delete-entity-type-sample.js b/ai-platform/snippets/delete-entity-type-sample.js deleted file mode 100644 index 84f490a0f8..0000000000 --- a/ai-platform/snippets/delete-entity-type-sample.js +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Deletes a single EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - force, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_delete_entity_type_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const force = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function deleteEntityType() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const request = { - name: name, - force: Boolean(force), - }; - - // Delete EntityType request - const [operation] = await featurestoreServiceClient.deleteEntityType( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Delete entity type response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - deleteEntityType(); - // [END aiplatform_delete_entity_type_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/delete-feature-sample.js b/ai-platform/snippets/delete-feature-sample.js deleted file mode 100644 index c509de9798..0000000000 --- a/ai-platform/snippets/delete-feature-sample.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Deletes a single Feature. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - featureId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_delete_feature_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const featureId = 'YOUR_FEATURE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function deleteFeature() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}/features/${featureId}`; - - const request = { - name: name, - }; - - // Delete Feature request - const [operation] = await featurestoreServiceClient.deleteFeature(request, { - timeout: Number(timeout), - }); - const [response] = await operation.promise(); - - console.log('Delete feature response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - deleteFeature(); - // [END aiplatform_delete_feature_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/delete-featurestore-sample.js b/ai-platform/snippets/delete-featurestore-sample.js deleted file mode 100644 index e7220eba12..0000000000 --- a/ai-platform/snippets/delete-featurestore-sample.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Deletes a single Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - force = false, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 60000 -) { - // [START aiplatform_delete_featurestore_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const force = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function deleteFeaturestore() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - name: name, - force: Boolean(force), - }; - - // Delete Featurestore request - const [operation] = await featurestoreServiceClient.deleteFeaturestore( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Delete featurestore response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - deleteFeaturestore(); - // [END aiplatform_delete_featurestore_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/delete-model.js b/ai-platform/snippets/delete-model.js deleted file mode 100644 index a00b2b7743..0000000000 --- a/ai-platform/snippets/delete-model.js +++ /dev/null @@ -1,64 +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, project, location = 'us-central1') { - // [START aiplatform_delete_model_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - */ - - // const modelId = 'YOUR_MODEL_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 deleteModel() { - // Configure the resource - const name = modelServiceClient.modelPath(project, location, modelId); - const request = {name}; - - // Delete Model Request - const [response] = await modelServiceClient.deleteModel(request); - console.log(`Long running operation: ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Delete model response:\n', result); - } - deleteModel(); - // [END aiplatform_delete_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/deploy-model.js b/ai-platform/snippets/deploy-model.js deleted file mode 100644 index f9d6a4eed0..0000000000 --- a/ai-platform/snippets/deploy-model.js +++ /dev/null @@ -1,152 +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, - deployedModelDisplayName, - endpointId, - project, - location = 'us-central1' -) { - // [START aiplatform_deploy_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 deployModel() { - // 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, - automaticResources: {minReplicaCount: 1, maxReplicaCount: 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('\tDeployed model'); - if (!modelDeployed) { - console.log('\t\tId : {}'); - console.log('\t\tModel : {}'); - console.log('\t\tDisplay name : {}'); - console.log('\t\tCreate time : {}'); - - console.log('\t\tDedicated resources'); - console.log('\t\t\tMin replica count : {}'); - console.log('\t\t\tMachine spec {}'); - console.log('\t\t\t\tMachine type : {}'); - console.log('\t\t\t\tAccelerator type : {}'); - console.log('\t\t\t\tAccelerator count : {}'); - - console.log('\t\tAutomatic resources'); - console.log('\t\t\tMin replica count : {}'); - console.log('\t\t\tMax replica count : {}'); - } else { - console.log(`\t\tId : ${modelDeployed.id}`); - console.log(`\t\tModel : ${modelDeployed.model}`); - console.log(`\t\tDisplay name : ${modelDeployed.displayName}`); - console.log(`\t\tCreate time : ${modelDeployed.createTime}`); - - const dedicatedResources = modelDeployed.dedicatedResources; - console.log('\t\tDedicated resources'); - if (!dedicatedResources) { - console.log('\t\t\tMin replica count : {}'); - console.log('\t\t\tMachine spec {}'); - console.log('\t\t\t\tMachine type : {}'); - console.log('\t\t\t\tAccelerator type : {}'); - console.log('\t\t\t\tAccelerator count : {}'); - } else { - console.log( - `\t\t\tMin replica count : \ - ${dedicatedResources.minReplicaCount}` - ); - const machineSpec = dedicatedResources.machineSpec; - console.log('\t\t\tMachine spec'); - console.log(`\t\t\t\tMachine type : ${machineSpec.machineType}`); - console.log( - `\t\t\t\tAccelerator type : ${machineSpec.acceleratorType}` - ); - console.log( - `\t\t\t\tAccelerator count : ${machineSpec.acceleratorCount}` - ); - } - - const automaticResources = modelDeployed.automaticResources; - console.log('\t\tAutomatic resources'); - if (!automaticResources) { - console.log('\t\t\tMin replica count : {}'); - console.log('\t\t\tMax replica count : {}'); - } else { - console.log( - `\t\t\tMin replica count : \ - ${automaticResources.minReplicaCount}` - ); - console.log( - `\t\t\tMax replica count : \ - ${automaticResources.maxReplicaCount}` - ); - } - } - } - deployModel(); - // [END aiplatform_deploy_model_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/embedding-model-tuning.js b/ai-platform/snippets/embedding-model-tuning.js deleted file mode 100644 index 4860ab3b0a..0000000000 --- a/ai-platform/snippets/embedding-model-tuning.js +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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'; - -// [START aiplatform_genai_code_model_tuning] -// [START generativeaionvertexai_genai_code_model_tuning] -async function main( - apiEndpoint, - project, - outputDir, - pipelineJobDisplayName = 'embedding-customization-pipeline-sample', - baseModelVersionId = 'text-embedding-005', - taskType = 'DEFAULT', - corpusPath = 'gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/corpus.jsonl', - queriesPath = 'gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/queries.jsonl', - trainLabelPath = 'gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/train.tsv', - testLabelPath = 'gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/test.tsv', - outputDimensionality = 768, - learningRateMultiplier = 1.0, - batchSize = 128, - trainSteps = 1000 -) { - const aiplatform = require('@google-cloud/aiplatform'); - const {PipelineServiceClient} = aiplatform.v1; - const {helpers} = aiplatform; // helps construct protobuf.Value objects. - - const client = new PipelineServiceClient({apiEndpoint}); - const match = apiEndpoint.match(/(?\w+-\w+)/); - const location = match ? match.groups.L : 'us-central1'; - const parent = `projects/${project}/locations/${location}`; - const params = { - base_model_version_id: baseModelVersionId, - task_type: taskType, - queries_path: queriesPath, - corpus_path: corpusPath, - train_label_path: trainLabelPath, - test_label_path: testLabelPath, - batch_size: batchSize, - train_steps: trainSteps, - output_dimensionality: outputDimensionality, - learning_rate_multiplier: learningRateMultiplier, - }; - const runtimeConfig = { - gcsOutputDirectory: outputDir, - parameterValues: Object.fromEntries( - Object.entries(params).map(([k, v]) => [k, helpers.toValue(v)]) - ), - }; - const pipelineJob = { - templateUri: - 'https://us-kfp.pkg.dev/ml-pipeline/llm-text-embedding/tune-text-embedding-model/v1.1.4', - displayName: pipelineJobDisplayName, - runtimeConfig, - }; - async function createTuneJob() { - const [response] = await client.createPipelineJob({parent, pipelineJob}); - console.log(`job_name: ${response.name}`); - console.log(`job_state: ${response.state}`); - } - - await createTuneJob(); -} -// [END aiplatform_genai_code_model_tuning] -// [END generativeaionvertexai_genai_code_model_tuning] - -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-image.test.js b/ai-platform/snippets/expensive-test/create-data-labeling-job-image.test.js deleted file mode 100644 index c3381e16ef..0000000000 --- a/ai-platform/snippets/expensive-test/create-data-labeling-job-image.test.js +++ /dev/null @@ -1,69 +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 displayName = `temp_create_data_labeling_job_image_test_${uuid()}`; -const datasetId = '1905673553261363200'; -const instructionUri = - 'gs://ucaip-sample-resources/images/datalabeling_instructions.pdf'; -const annotationSpec = 'roses'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -let dataLabelingJobId; - -describe('AI platform create data labeling job image', () => { - it('should create a new data labeling job image', async () => { - const stdout = execSync( - `node ./create-data-labeling-job-image.js ${displayName} ${datasetId} \ - ${instructionUri} \ - ${annotationSpec} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create data labeling job image response/); - dataLabelingJobId = stdout - .split('/locations/us-central1/dataLabelingJobs/')[1] - .split('\n')[0]; - }); - after('should cancel the data labeling job and delete it', async () => { - execSync( - `node ./cancel-data-labeling-job.js ${dataLabelingJobId} ${project} \ - ${location}`, - { - cwd, - } - ); - execSync( - `node ./delete-data-labeling-job.js ${dataLabelingJobId} ${project} \ - ${location}`, - { - cwd, - } - ); - }); -}); 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 deleted file mode 100644 index 33800c8ea1..0000000000 --- a/ai-platform/snippets/expensive-test/create-data-labeling-job-video.test.js +++ /dev/null @@ -1,70 +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 displayName = `temp_create_data_labeling_job_video_test_${uuid()}`; -const datasetId = '3459133949727473664'; -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; - -let dataLabelingJobId; - -describe('AI platform create data labeling job video', () => { - it('should create a new data labeling job video', async () => { - const stdout = execSync( - `node ./create-data-labeling-job-video.js ${displayName} ${datasetId} \ - ${instructionUri} \ - ${annotationSpec} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create data labeling job video response/); - dataLabelingJobId = stdout - .split('/locations/us-central1/dataLabelingJobs/')[1] - .split('\n')[0]; - }); - after('should cancel the data labeling job and delete it', async () => { - execSync( - `node ./cancel-data-labeling-job.js ${dataLabelingJobId} ${project} \ - ${location}`, - { - cwd, - } - ); - execSync( - `node ./delete-data-labeling-job.js ${dataLabelingJobId} ${project} \ - ${location}`, - { - cwd, - } - ); - }); -}); 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 deleted file mode 100644 index 342c54a554..0000000000 --- a/ai-platform/snippets/expensive-test/create-data-labeling-job.test.js +++ /dev/null @@ -1,73 +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 displayName = `temp_create_data_labeling_job_test_${uuid()}`; -const datasetId = '8268327440875520000'; -const instructionUri = - 'gs://ucaip-sample-resources/images/datalabeling_instructions.pdf'; -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; - -let dataLabelingJobId; - -describe('AI platform create data labeling job', () => { - it('should create a new data labeling job', async () => { - const stdout = execSync( - `node ./create-data-labeling-job.js ${displayName} ${datasetId} \ - ${instructionUri} \ - ${inputsSchemaUri} \ - ${annotationSpec} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create data labeling job response/); - dataLabelingJobId = stdout - .split('/locations/us-central1/dataLabelingJobs/')[1] - .split('\n')[0]; - }); - after('should cancel the data labeling job and delete it', async () => { - execSync( - `node ./cancel-data-labeling-job.js ${dataLabelingJobId} ${project} \ - ${location}`, - { - cwd, - } - ); - execSync( - `node ./delete-data-labeling-job.js ${dataLabelingJobId} ${project} \ - ${location}`, - { - cwd, - } - ); - }); -}); diff --git a/ai-platform/snippets/expensive-test/get-training-pipeline.test.js b/ai-platform/snippets/expensive-test/get-training-pipeline.test.js deleted file mode 100644 index 1f553f8438..0000000000 --- a/ai-platform/snippets/expensive-test/get-training-pipeline.test.js +++ /dev/null @@ -1,42 +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 trainingPipelineId = '1419759782528548864'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get training pipeline', () => { - it('should get the training pipeline', async () => { - const stdout = execSync( - `node ./get-training-pipeline.js ${trainingPipelineId} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get training pipeline response/); - }); -}); 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 deleted file mode 100644 index bb6ca67862..0000000000 --- a/ai-platform/snippets/expensive-test/import-data-text-entity-extraction.test.js +++ /dev/null @@ -1,46 +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 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; - -describe('AI platform import data text entity extraction', () => { - it('should import data to text entity extraction dataset', async () => { - const stdout = execSync( - `node ./import-data-text-entity-extraction.js ${datasetId} \ - ${gcsSourceUri} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Import data text entity extraction response/); - }); -}); 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 deleted file mode 100644 index 8449d211f1..0000000000 --- a/ai-platform/snippets/expensive-test/import-data-text-sentiment-analysis.test.js +++ /dev/null @@ -1,46 +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 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; - -describe('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} \ - ${gcsSourceUri} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Import data text sentiment analysis response/); - }); -}); 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 deleted file mode 100644 index 592390e924..0000000000 --- a/ai-platform/snippets/expensive-test/import-data-video-object-tracking.test.js +++ /dev/null @@ -1,46 +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 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; - -describe('AI platform import data video object tracking', () => { - it('should import video object tracking data to dataset', async () => { - const stdout = execSync( - `node ./import-data-video-object-tracking.js ${datasetId} \ - ${gcsSourceUri} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Import data video object tracking response/); - }); -}); diff --git a/ai-platform/snippets/export-feature-values-sample.js b/ai-platform/snippets/export-feature-values-sample.js deleted file mode 100644 index 04d9c34c09..0000000000 --- a/ai-platform/snippets/export-feature-values-sample.js +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Exports Feature values from all the entities of a target EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - destinationTableUri, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_export_feature_values_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const destinationTableUri = 'YOUR_BQ_DESTINATION_TABLE_URI'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function exportFeatureValues() { - // Configure the entityType resource - const entityType = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const destination = { - bigqueryDestination: { - // # Output to BigQuery table created earlier - outputUri: destinationTableUri, - }, - }; - - const featureSelector = { - idMatcher: { - ids: ['age', 'gender', 'liked_genres'], - }, - }; - - const request = { - entityType: entityType, - destination: destination, - featureSelector: featureSelector, - fullExport: {}, - }; - - // Export Feature Values Request - const [operation] = await featurestoreServiceClient.exportFeatureValues( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Export feature values response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - exportFeatureValues(); - // [END aiplatform_export_feature_values_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/export-feature-values-snapshot-sample.js b/ai-platform/snippets/export-feature-values-snapshot-sample.js deleted file mode 100644 index f527bfb10e..0000000000 --- a/ai-platform/snippets/export-feature-values-snapshot-sample.js +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Exports Feature values with snapshot from all the entities of a target EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - destinationTableUri, - timestamp, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_export_feature_values_snapshot_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const destinationTableUri = 'YOUR_BQ_DESTINATION_TABLE_URI'; - // const timestamp = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function exportFeatureValuesSnapshot() { - // Configure the entityType resource - const entityType = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const destination = { - bigqueryDestination: { - // # Output to BigQuery table created earlier - outputUri: destinationTableUri, - }, - }; - - const featureSelector = { - idMatcher: { - ids: ['age', 'gender', 'liked_genres'], - }, - }; - - const snapshotExport = { - startTime: { - seconds: Number(timestamp), - }, - }; - - const request = { - entityType: entityType, - destination: destination, - featureSelector: featureSelector, - snapshotExport: snapshotExport, - }; - - // Export Feature Values Request - const [operation] = await featurestoreServiceClient.exportFeatureValues( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Export feature values snapshot response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - exportFeatureValuesSnapshot(); - // [END aiplatform_export_feature_values_snapshot_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/export-model-tabular-classification.js b/ai-platform/snippets/export-model-tabular-classification.js deleted file mode 100644 index bbdabab538..0000000000 --- a/ai-platform/snippets/export-model-tabular-classification.js +++ /dev/null @@ -1,80 +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( - gcsDestinationOutputUriPrefix, - modelId, - project, - location = 'us-central1' -) { - // [START aiplatform_export_model_tabular_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const gcsDestinationOutputUriPrefix ='YOUR_GCS_DESTINATION_\ - // OUTPUT_URI_PREFIX'; eg. "gs:///destination_path" - // const modelId = 'YOUR_MODEL_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 exportModelTabularClassification() { - // Configure the name resources - const name = `projects/${project}/locations/${location}/models/${modelId}`; - // Configure the outputConfig resources - const outputConfig = { - exportFormatId: 'tf-saved-model', - artifactDestination: { - outputUriPrefix: gcsDestinationOutputUriPrefix, - }, - }; - const request = { - name, - outputConfig, - }; - - // Export Model request - const [response] = await modelServiceClient.exportModel(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - console.log(`Export model response : ${JSON.stringify(response.result)}`); - } - exportModelTabularClassification(); - // [END aiplatform_export_model_tabular_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/export-model.js b/ai-platform/snippets/export-model.js deleted file mode 100644 index a7fb1fbdad..0000000000 --- a/ai-platform/snippets/export-model.js +++ /dev/null @@ -1,84 +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, - gcsDestinationOutputUriPrefix, - exportFormat, - project, - location = 'us-central1' -) { - // [START aiplatform_export_model_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - (Not necessary if passing values as arguments) - */ - - // const modelId = 'YOUR_MODEL_ID'; - // const gcsDestinationOutputUriPrefix ='YOUR_GCS_DEST_OUTPUT_URI_PREFIX'; - // eg. "gs:///destination_path" - // const exportFormat = 'YOUR_EXPORT_FORMAT'; - // 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 exportModel() { - // Configure the name resources - const name = `projects/${project}/locations/${location}/models/${modelId}`; - // Configure the outputConfig resources - const outputConfig = { - exportFormatId: exportFormat, - gcsDestination: { - outputUriPrefix: gcsDestinationOutputUriPrefix, - }, - }; - const request = { - name, - outputConfig, - }; - - // Export Model request - const [response] = await modelServiceClient.exportModel(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log(`Export model response : ${JSON.stringify(result)}`); - } - exportModel(); - // [END aiplatform_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/gemma2PredictGpu.js b/ai-platform/snippets/gemma2PredictGpu.js deleted file mode 100644 index 244de43edb..0000000000 --- a/ai-platform/snippets/gemma2PredictGpu.js +++ /dev/null @@ -1,75 +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'; - -// [START generativeaionvertexai_gemma2_predict_gpu] -async function gemma2PredictGpu(predictionServiceClient) { - // Imports the Google Cloud Prediction Service Client library - const { - // TODO(developer): Uncomment PredictionServiceClient before running the sample. - // PredictionServiceClient, - helpers, - } = require('@google-cloud/aiplatform'); - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = 'your-project-id'; - const endpointRegion = 'your-vertex-endpoint-region'; - const endpointId = 'your-vertex-endpoint-id'; - - // Default configuration - const config = {maxOutputTokens: 1024, temperature: 0.9, topP: 1.0, topK: 1}; - // Prompt used in the prediction - const prompt = 'Why is the sky blue?'; - - // Encapsulate the prompt in a correct format for GPUs - // Example format: [{inputs: 'Why is the sky blue?', parameters: {temperature: 0.9}}] - const input = { - inputs: prompt, - parameters: config, - }; - - // Convert input message to a list of GAPIC instances for model input - const instances = [helpers.toValue(input)]; - - // TODO(developer): Uncomment apiEndpoint and predictionServiceClient before running the sample. - // const apiEndpoint = `${endpointRegion}-aiplatform.googleapis.com`; - - // Create a client - // predictionServiceClient = new PredictionServiceClient({apiEndpoint}); - - // Call the Gemma2 endpoint - const gemma2Endpoint = `projects/${projectId}/locations/${endpointRegion}/endpoints/${endpointId}`; - - const [response] = await predictionServiceClient.predict({ - endpoint: gemma2Endpoint, - instances, - }); - - const predictions = response.predictions; - const text = predictions[0].stringValue; - - console.log('Predictions:', text); - return text; -} - -module.exports = gemma2PredictGpu; - -// TODO(developer): Uncomment below lines before running the sample. -// gemma2PredictGpu(...process.argv.slice(2)).catch(err => { -// console.error(err.message); -// process.exitCode = 1; -// }); -// [END generativeaionvertexai_gemma2_predict_gpu] diff --git a/ai-platform/snippets/gemma2PredictTpu.js b/ai-platform/snippets/gemma2PredictTpu.js deleted file mode 100644 index c854e97009..0000000000 --- a/ai-platform/snippets/gemma2PredictTpu.js +++ /dev/null @@ -1,77 +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 gemma2PredictTpu(predictionServiceClient) { - // [START generativeaionvertexai_gemma2_predict_tpu] - // Imports the Google Cloud Prediction Service Client library - const { - // TODO(developer): Uncomment PredictionServiceClient before running the sample. - // PredictionServiceClient, - helpers, - } = require('@google-cloud/aiplatform'); - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = 'your-project-id'; - const endpointRegion = 'your-vertex-endpoint-region'; - const endpointId = 'your-vertex-endpoint-id'; - - // Prompt used in the prediction - const prompt = 'Why is the sky blue?'; - - // Encapsulate the prompt in a correct format for TPUs - // Example format: [{prompt: 'Why is the sky blue?', temperature: 0.9}] - const input = { - prompt, - // Parameters for default configuration - maxOutputTokens: 1024, - temperature: 0.9, - topP: 1.0, - topK: 1, - }; - - // Convert input message to a list of GAPIC instances for model input - const instances = [helpers.toValue(input)]; - - // TODO(developer): Uncomment apiEndpoint and predictionServiceClient before running the sample. - // const apiEndpoint = `${endpointRegion}-aiplatform.googleapis.com`; - - // Create a client - // predictionServiceClient = new PredictionServiceClient({apiEndpoint}); - - // Call the Gemma2 endpoint - const gemma2Endpoint = `projects/${projectId}/locations/${endpointRegion}/endpoints/${endpointId}`; - - const [response] = await predictionServiceClient.predict({ - endpoint: gemma2Endpoint, - instances, - }); - - const predictions = response.predictions; - const text = predictions[0].stringValue; - - console.log('Predictions:', text); - // [END generativeaionvertexai_gemma2_predict_tpu] - return text; -} - -module.exports = gemma2PredictTpu; - -// TODO(developer): Uncomment below lines before running the sample. -// gemma2PredictTpu(...process.argv.slice(2)).catch(err => { -// console.error(err.message); -// process.exitCode = 1; -// }); 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-custom-job.js b/ai-platform/snippets/get-custom-job.js deleted file mode 100644 index 7589a725af..0000000000 --- a/ai-platform/snippets/get-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_get_custom_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - */ - - // 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 getCustomJob() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/customJobs/${customJobId}`; - const request = { - name, - }; - - // Get custom job request - const [response] = await jobServiceClient.getCustomJob(request); - - console.log('Get custom job response'); - console.log(`\t${JSON.stringify(response)}`); - } - getCustomJob(); - // [END aiplatform_get_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/get-entity-type-sample.js b/ai-platform/snippets/get-entity-type-sample.js deleted file mode 100644 index 7123bb34e5..0000000000 --- a/ai-platform/snippets/get-entity-type-sample.js +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Gets details of a single EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 5000 -) { - // [START aiplatform_get_entity_type_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function getEntityType() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const request = { - name: name, - }; - - // Get EntityType request - const [response] = await featurestoreServiceClient.getEntityType(request, { - timeout: Number(timeout), - }); - - console.log('Get entity type response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - getEntityType(); - // [END aiplatform_get_entity_type_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/get-feature-sample.js b/ai-platform/snippets/get-feature-sample.js deleted file mode 100644 index e89fcdc355..0000000000 --- a/ai-platform/snippets/get-feature-sample.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Gets details of a single Feature. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - featureId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_get_feature_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const featureId = 'YOUR_FEATURE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function getFeature() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}/features/${featureId}`; - - const request = { - name: name, - }; - - // Get Feature request - const [response] = await featurestoreServiceClient.getFeature(request, { - timeout: Number(timeout), - }); - - console.log('Get feature response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - getFeature(); - // [END aiplatform_get_feature_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/get-featurestore-sample.js b/ai-platform/snippets/get-featurestore-sample.js deleted file mode 100644 index fe6e38f394..0000000000 --- a/ai-platform/snippets/get-featurestore-sample.js +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Gets details of a single Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 5000 -) { - // [START aiplatform_get_featurestore_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function getFeaturestore() { - // Configure the parent resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - name: name, - }; - - // Get Featurestore request - const [response] = await featurestoreServiceClient.getFeaturestore( - request, - {timeout: Number(timeout)} - ); - - console.log('Get featurestore response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - getFeaturestore(); - // [END aiplatform_get_featurestore_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/get-hyperparameter-tuning-job.js b/ai-platform/snippets/get-hyperparameter-tuning-job.js deleted file mode 100644 index 9c2d6d4e12..0000000000 --- a/ai-platform/snippets/get-hyperparameter-tuning-job.js +++ /dev/null @@ -1,69 +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'; - -async function main(tuningJobId, project, location = 'us-central1') { - // [START aiplatform_get_hyperparameter_tuning_job_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const tuningJobId = 'YOUR_TUNING_JOB_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Model 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 getHyperparameterTuningJob() { - // Configure the parent resource - const name = jobServiceClient.hyperparameterTuningJobPath( - project, - location, - tuningJobId - ); - const request = { - name, - }; - // Get and print out a list of all the endpoints for this resource - const [response] = - await jobServiceClient.getHyperparameterTuningJob(request); - - console.log('Get hyperparameter tuning job response'); - console.log(`\tDisplay name: ${response.displayName}`); - console.log(`\tTuning job resource name: ${response.name}`); - console.log(`\tJob status: ${response.state}`); - } - getHyperparameterTuningJob(); - // [END aiplatform_get_hyperparameter_tuning_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-image-classification.js b/ai-platform/snippets/get-model-evaluation-image-classification.js deleted file mode 100644 index 0b67c1cfe3..0000000000 --- a/ai-platform/snippets/get-model-evaluation-image-classification.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'; - -async function main(modelId, evaluationId, project, location = 'us-central1') { - // [START aiplatform_get_model_evaluation_image_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationImageClassification() { - // Configure the name 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 image classification response'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - console.log(`\tSlice dimensions : ${response.sliceDimensions}`); - - const modelExplanation = response.modelExplanation; - if (modelExplanation === null) { - console.log(`\tModel explanation: ${JSON.stringify(modelExplanation)}`); - } else { - const meanAttributions = modelExplanation.meanAttributions; - for (const meanAttribution of meanAttributions) { - console.log('\t\tMean attribution'); - console.log( - `\t\t\tBaseline output value : \ - ${meanAttribution.baselineOutputValue}` - ); - console.log( - `\t\t\tInstance output value : \ - ${meanAttribution.instanceOutputValue}` - ); - console.log( - `\t\t\tFeature attributions : \ - ${JSON.stringify(meanAttribution.featureAttributions)}` - ); - console.log(`\t\t\tOutput index : ${meanAttribution.outputIndex}`); - console.log( - `\t\t\tOutput display name : \ - ${meanAttribution.outputDisplayName}` - ); - console.log( - `\t\t\tApproximation error : \ - ${meanAttribution.approximationError}` - ); - } - } - } - getModelEvaluationImageClassification(); - // [END aiplatform_get_model_evaluation_image_classification_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-image-object-detection.js b/ai-platform/snippets/get-model-evaluation-image-object-detection.js deleted file mode 100644 index fc60fc7ac5..0000000000 --- a/ai-platform/snippets/get-model-evaluation-image-object-detection.js +++ /dev/null @@ -1,110 +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_image_object_detection_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationImageObjectDetection() { - // Configure the name 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 image object detection 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}`); - - const modelExplanation = response.modelExplanation; - console.log('\tModel explanation'); - if (modelExplanation === null) { - console.log('\t\t{}'); - } else { - const meanAttributions = modelExplanation.meanAttributions; - if (meanAttributions === null) { - console.log('\t\t\t []'); - } else { - for (const meanAttribution of meanAttributions) { - console.log('\t\tMean attribution'); - console.log( - `\t\t\tBaseline output value : \ - ${meanAttribution.baselineOutputValue}` - ); - console.log( - `\t\t\tInstance output value : \ - ${meanAttribution.instanceOutputValue}` - ); - console.log( - `\t\t\tFeature attributions : \ - ${meanAttribution.featureAttributions}` - ); - console.log(`\t\t\tOutput index : ${meanAttribution.outputIndex}`); - console.log( - `\t\t\tOutput display name : \ - ${meanAttribution.outputDisplayName}` - ); - console.log( - `\t\t\tApproximation error : \ - ${meanAttribution.approximationError}` - ); - } - } - } - } - getModelEvaluationImageObjectDetection(); - // [END aiplatform_get_model_evaluation_image_object_detection_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-slice.js b/ai-platform/snippets/get-model-evaluation-slice.js deleted file mode 100644 index a90e8cda24..0000000000 --- a/ai-platform/snippets/get-model-evaluation-slice.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'; - -async function main( - modelId, - evaluationId, - sliceId, - project, - location = 'us-central1' -) { - // [START aiplatform_get_model_evaluation_slice_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // const modelId = 'YOUR_MODEL_ID'; - // const evaluationId = 'YOUR_EVALUATION_ID'; - // const sliceId = 'YOUR_SLICE_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', - }; - // Specifies the location of the api endpoint - const modelServiceClient = new ModelServiceClient(clientOptions); - - async function getModelEvaluationSlice() { - // Configure the parent resource - const name = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}/slices/${sliceId}`; - const request = { - name, - }; - - // Get and print out a list of all the endpoints for this resource - const [response] = - await modelServiceClient.getModelEvaluationSlice(request); - - console.log('Get model evaluation slice'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics_Schema_Uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - - console.log('Slice'); - const slice = response.slice; - console.log(`\tDimension :${slice.dimension}`); - console.log(`\tValue :${slice.value}`); - } - getModelEvaluationSlice(); - // [END aiplatform_get_model_evaluation_slice_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-tabular-classification.js b/ai-platform/snippets/get-model-evaluation-tabular-classification.js deleted file mode 100644 index 63f0c98c7e..0000000000 --- a/ai-platform/snippets/get-model-evaluation-tabular-classification.js +++ /dev/null @@ -1,111 +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_tabular_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationTabularClassification() { - // Configure the parent resources - const name = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}`; - const request = { - name, - }; - - // Get model evaluation request - const [response] = await modelServiceClient.getModelEvaluation(request); - - console.log('Get model evaluation tabular classification response'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - console.log(`\tSlice dimensions : ${response.sliceDimensions}`); - - const modelExplanation = response.modelExplanation; - console.log('\tModel explanation'); - if (!modelExplanation) { - console.log('\t\t{}'); - } else { - const meanAttributions = modelExplanation.meanAttributions; - if (!meanAttributions) { - console.log('\t\t\t []'); - } else { - for (const meanAttribution of meanAttributions) { - console.log('\t\tMean attribution'); - console.log( - `\t\t\tBaseline output value : \ - ${meanAttribution.baselineOutputValue}` - ); - console.log( - `\t\t\tInstance output value : \ - ${meanAttribution.instanceOutputValue}` - ); - console.log( - `\t\t\tFeature attributions : \ - ${JSON.stringify(meanAttribution.featureAttributions)}` - ); - console.log(`\t\t\tOutput index : ${meanAttribution.outputIndex}`); - console.log( - `\t\t\tOutput display name : \ - ${meanAttribution.outputDisplayName}` - ); - console.log( - `\t\t\tApproximation error : \ - ${meanAttribution.approximationError}` - ); - } - } - } - } - getModelEvaluationTabularClassification(); - // [END aiplatform_get_model_evaluation_tabular_classification_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-tabular-regression.js b/ai-platform/snippets/get-model-evaluation-tabular-regression.js deleted file mode 100644 index 55766745a1..0000000000 --- a/ai-platform/snippets/get-model-evaluation-tabular-regression.js +++ /dev/null @@ -1,111 +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_tabular_regression_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationTabularRegression() { - // Configure the parent resources - const name = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}`; - const request = { - name, - }; - - // Get model evaluation request - const [response] = await modelServiceClient.getModelEvaluation(request); - - console.log('Get model evaluation tabular regression response'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - console.log(`\tSlice dimensions : ${response.sliceDimensions}`); - - const modelExplanation = response.modelExplanation; - console.log('\tModel explanation'); - if (!modelExplanation) { - console.log('\t\t{}'); - } else { - const meanAttributions = modelExplanation.meanAttributions; - if (!meanAttributions) { - console.log('\t\t\t []'); - } else { - for (const meanAttribution of meanAttributions) { - console.log('\t\tMean attribution'); - console.log( - `\t\t\tBaseline output value : \ - ${meanAttribution.baselineOutputValue}` - ); - console.log( - `\t\t\tInstance output value : \ - ${meanAttribution.instanceOutputValue}` - ); - console.log( - `\t\t\tFeature attributions : \ - ${JSON.stringify(meanAttribution.featureAttributions)}` - ); - console.log(`\t\t\tOutput index : ${meanAttribution.outputIndex}`); - console.log( - `\t\t\tOutput display name : \ - ${meanAttribution.outputDisplayName}` - ); - console.log( - `\t\t\tApproximation error : \ - ${meanAttribution.approximationError}` - ); - } - } - } - } - getModelEvaluationTabularRegression(); - // [END aiplatform_get_model_evaluation_tabular_regression_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-text-classification.js b/ai-platform/snippets/get-model-evaluation-text-classification.js deleted file mode 100644 index bb28b0a21c..0000000000 --- a/ai-platform/snippets/get-model-evaluation-text-classification.js +++ /dev/null @@ -1,109 +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_text_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationTextClassification() { - // Configure the resources - const name = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}`; - const request = { - name, - }; - - // Get model evaluation request - const [response] = await modelServiceClient.getModelEvaluation(request); - - console.log('Get model evaluation text classification response :'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - - const modelExplanation = response.modelExplanation; - console.log('\tModel explanation'); - if (modelExplanation === null) { - console.log('\t\t{}'); - } else { - const meanAttributions = modelExplanation.meanAttributions; - if (meanAttributions === null) { - console.log('\t\t\t []'); - } else { - for (const meanAttribution of meanAttributions) { - console.log('\t\tMean attribution'); - console.log( - `\t\t\tBaseline output value : \ - ${meanAttribution.baselineOutputValue}` - ); - console.log( - `\t\t\tInstance output value : \ - ${meanAttribution.instanceOutputValue}` - ); - console.log( - `\t\t\tFeature attributions : \ - ${JSON.stringify(meanAttribution.featureAttributions)}` - ); - console.log(`\t\t\tOutput index : ${meanAttribution.outputIndex}`); - console.log( - `\t\t\tOutput display name : \ - ${meanAttribution.outputDisplayName}` - ); - console.log( - `\t\t\tApproximation error : \ - ${meanAttribution.approximationError}` - ); - } - } - } - } - getModelEvaluationTextClassification(); - // [END aiplatform_get_model_evaluation_text_classification_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-text-entity-extraction.js b/ai-platform/snippets/get-model-evaluation-text-entity-extraction.js deleted file mode 100644 index b5182362a6..0000000000 --- a/ai-platform/snippets/get-model-evaluation-text-entity-extraction.js +++ /dev/null @@ -1,109 +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_text_entity_extraction_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationTextEntityExtraction() { - // Configure the resources - const name = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}`; - const request = { - name, - }; - - // Get model evaluation request - const [response] = await modelServiceClient.getModelEvaluation(request); - - console.log('Get model evaluation text entity extraction response :'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - - const modelExplanation = response.modelExplanation; - console.log('\tModel explanation'); - if (modelExplanation === null) { - console.log('\t\t{}'); - } else { - const meanAttributions = modelExplanation.meanAttributions; - if (meanAttributions === null) { - console.log('\t\t\t []'); - } else { - for (const meanAttribution of meanAttributions) { - console.log('\t\tMean attribution'); - console.log( - `\t\t\tBaseline output value : \ - ${meanAttribution.baselineOutputValue}` - ); - console.log( - `\t\t\tInstance output value : \ - ${meanAttribution.instanceOutputValue}` - ); - console.log( - `\t\t\tFeature attributions : \ - ${JSON.stringify(meanAttribution.featureAttributions)}` - ); - console.log(`\t\t\tOutput index : ${meanAttribution.outputIndex}`); - console.log( - `\t\t\tOutput display name : \ - ${meanAttribution.outputDisplayName}` - ); - console.log( - `\t\t\tApproximation error : \ - ${meanAttribution.approximationError}` - ); - } - } - } - } - getModelEvaluationTextEntityExtraction(); - // [END aiplatform_get_model_evaluation_text_entity_extraction_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-text-sentiment-analysis.js b/ai-platform/snippets/get-model-evaluation-text-sentiment-analysis.js deleted file mode 100644 index 095651915e..0000000000 --- a/ai-platform/snippets/get-model-evaluation-text-sentiment-analysis.js +++ /dev/null @@ -1,109 +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_text_sentiment_analysis_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationTextSentimentAnalysis() { - // Configure the resources - const name = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}`; - const request = { - name, - }; - - // Get model evaluation request - const [response] = await modelServiceClient.getModelEvaluation(request); - - console.log('Get model evaluation text sentiment analysis response :'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - - const modelExplanation = response.modelExplanation; - console.log('\tModel explanation'); - if (modelExplanation === null) { - console.log('\t\t{}'); - } else { - const meanAttributions = modelExplanation.meanAttributions; - if (meanAttributions === null) { - console.log('\t\t\t []'); - } else { - for (const meanAttribution of meanAttributions) { - console.log('\t\tMean attribution'); - console.log( - `\t\t\tBaseline output value : \ - ${meanAttribution.baselineOutputValue}` - ); - console.log( - `\t\t\tInstance output value : \ - ${meanAttribution.instanceOutputValue}` - ); - console.log( - `\t\t\tFeature attributions : \ - ${JSON.stringify(meanAttribution.featureAttributions)}` - ); - console.log(`\t\t\tOutput index : ${meanAttribution.outputIndex}`); - console.log( - `\t\t\tOutput display name : \ - ${meanAttribution.outputDisplayName}` - ); - console.log( - `\t\t\tApproximation error : \ - ${meanAttribution.approximationError}` - ); - } - } - } - } - getModelEvaluationTextSentimentAnalysis(); - // [END aiplatform_get_model_evaluation_text_sentiment_analysis_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-video-action-recognition.js b/ai-platform/snippets/get-model-evaluation-video-action-recognition.js deleted file mode 100644 index 8b67cc9fed..0000000000 --- a/ai-platform/snippets/get-model-evaluation-video-action-recognition.js +++ /dev/null @@ -1,80 +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'; - -async function main(modelId, evaluationId, project, location = 'us-central1') { - // [START aiplatform_get_model_evaluation_video_action_recognition_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationVideoActionRecognition() { - // Configure the parent resources - const name = modelServiceClient.modelEvaluationPath( - project, - location, - modelId, - evaluationId - ); - const request = { - name, - }; - - // Create get model evaluation request - const [response] = await modelServiceClient.getModelEvaluation(request); - - console.log('Get model evaluation video action recognition response'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - console.log(`\tSlice dimensions : ${response.sliceDimensions}`); - } - getModelEvaluationVideoActionRecognition(); - // [END aiplatform_get_model_evaluation_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/get-model-evaluation-video-classification.js b/ai-platform/snippets/get-model-evaluation-video-classification.js deleted file mode 100644 index 2a98fa367e..0000000000 --- a/ai-platform/snippets/get-model-evaluation-video-classification.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'; - -async function main(modelId, evaluationId, project, location = 'us-central1') { - // [START aiplatform_get_model_evaluation_video_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationVideoClassification() { - // 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 video classification response'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - console.log(`\tSlice dimensions : ${response.sliceDimensions}`); - } - getModelEvaluationVideoClassification(); - // [END aiplatform_get_model_evaluation_video_classification_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-video-object-tracking.js b/ai-platform/snippets/get-model-evaluation-video-object-tracking.js deleted file mode 100644 index 76198ce5a5..0000000000 --- a/ai-platform/snippets/get-model-evaluation-video-object-tracking.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'; - -async function main(modelId, evaluationId, project, location = 'us-central1') { - // [START aiplatform_get_model_evaluation_video_object_tracking_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 getModelEvaluationVideoObjectTracking() { - // 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 video object tracking response'); - console.log(`\tName : ${response.name}`); - console.log(`\tMetrics schema uri : ${response.metricsSchemaUri}`); - console.log(`\tMetrics : ${JSON.stringify(response.metrics)}`); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - console.log(`\tSlice dimensions : ${response.sliceDimensions}`); - } - getModelEvaluationVideoObjectTracking(); - // [END aiplatform_get_model_evaluation_video_object_tracking_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/get-model.js b/ai-platform/snippets/get-model.js deleted file mode 100644 index 5723c2780f..0000000000 --- a/ai-platform/snippets/get-model.js +++ /dev/null @@ -1,129 +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, project, location = 'us-central1') { - // [START aiplatform_get_model_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const modelId = 'YOUR_MODEL_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 getModel() { - // Configure the parent resource - const name = `projects/${project}/locations/${location}/models/${modelId}`; - const request = { - name, - }; - // Get and print out a list of all the endpoints for this resource - const [response] = await modelServiceClient.getModel(request); - - console.log('Get model response'); - console.log(`\tName : ${response.name}`); - console.log(`\tDisplayName : ${response.displayName}`); - console.log(`\tDescription : ${response.description}`); - console.log(`\tMetadata schema uri : ${response.metadataSchemaUri}`); - console.log(`\tMetadata : ${JSON.stringify(response.metadata)}`); - console.log(`\tTraining pipeline : ${response.trainingPipeline}`); - console.log(`\tArtifact uri : ${response.artifactUri}`); - console.log( - `\tSupported deployment resource types : \ - ${response.supportedDeploymentResourceTypes}` - ); - console.log( - `\tSupported input storage formats : \ - ${response.supportedInputStorageFormats}` - ); - console.log( - `\tSupported output storage formats : \ - ${response.supportedOutputStoragFormats}` - ); - console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`); - console.log(`\tUpdate time : ${JSON.stringify(response.updateTime)}`); - console.log(`\tLabels : ${JSON.stringify(response.labels)}`); - - const predictSchemata = response.predictSchemata; - console.log('\tPredict schemata'); - console.log(`\tInstance schema uri : ${predictSchemata.instanceSchemaUri}`); - console.log( - `\tParameters schema uri : ${predictSchemata.prametersSchemaUri}` - ); - console.log( - `\tPrediction schema uri : ${predictSchemata.predictionSchemaUri}` - ); - - const [supportedExportFormats] = response.supportedExportFormats; - console.log('\tSupported export formats'); - console.log(`\t${supportedExportFormats}`); - - const containerSpec = response.containerSpec; - console.log('\tContainer Spec'); - if (!containerSpec) { - console.log(`\t\t${JSON.stringify(containerSpec)}`); - console.log('\t\tImage uri : {}'); - console.log('\t\tCommand : {}'); - console.log('\t\tArgs : {}'); - console.log('\t\tPredict route : {}'); - console.log('\t\tHealth route : {}'); - console.log('\t\tEnv'); - console.log('\t\t\t{}'); - console.log('\t\tPort'); - console.log('\t\t{}'); - } else { - console.log(`\t\t${JSON.stringify(containerSpec)}`); - console.log(`\t\tImage uri : ${containerSpec.imageUri}`); - console.log(`\t\tCommand : ${containerSpec.command}`); - console.log(`\t\tArgs : ${containerSpec.args}`); - console.log(`\t\tPredict route : ${containerSpec.predictRoute}`); - console.log(`\t\tHealth route : ${containerSpec.healthRoute}`); - const env = containerSpec.env; - console.log('\t\tEnv'); - console.log(`\t\t\t${JSON.stringify(env)}`); - const ports = containerSpec.ports; - console.log('\t\tPort'); - console.log(`\t\t\t${JSON.stringify(ports)}`); - } - - const [deployedModels] = response.deployedModels; - console.log('\tDeployed models'); - console.log('\t\t', deployedModels); - } - getModel(); - // [END aiplatform_get_model_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/get-training-pipeline.js b/ai-platform/snippets/get-training-pipeline.js deleted file mode 100644 index eca150c5eb..0000000000 --- a/ai-platform/snippets/get-training-pipeline.js +++ /dev/null @@ -1,67 +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'; - -async function main(trainingPipelineId, project, location = 'us-central1') { - // [START aiplatform_get_training_pipeline_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const trainingPipelineId = 'YOUR_MODEL_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - // Imports the Google Cloud Model Service Client library - const {PipelineServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - - // Instantiates a client - const pipelineServiceClient = new PipelineServiceClient(clientOptions); - - async function getTrainingPipeline() { - // Configure the parent resource - const name = pipelineServiceClient.trainingPipelinePath( - project, - location, - trainingPipelineId - ); - const request = { - name, - }; - // Get and print out a list of all the endpoints for this resource - const [response] = await pipelineServiceClient.getTrainingPipeline(request); - - console.log('Get training pipeline response'); - console.log(`\tTraining pipeline name: ${response.displayName}`); - console.log(`\tTraining pipeline state: ${response.state}`); - } - getTrainingPipeline(); - // [END aiplatform_get_training_pipeline_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/imagen-edit-image-inpainting-insert-mask.js b/ai-platform/snippets/imagen-edit-image-inpainting-insert-mask.js deleted file mode 100644 index 843ddb663c..0000000000 --- a/ai-platform/snippets/imagen-edit-image-inpainting-insert-mask.js +++ /dev/null @@ -1,121 +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() { - // [START generativeaionvertexai_imagen_edit_image_inpainting_insert_mask] - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = process.env.CAIP_PROJECT_ID; - const location = 'us-central1'; - const inputFile = 'resources/woman.png'; - const maskFile = 'resources/woman_inpainting_insert_mask.png'; - const prompt = 'hat'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction Service Client library - 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: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function editImageInpaintingInsertMask() { - const fs = require('fs'); - const util = require('util'); - // Configure the parent resource - const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imagegeneration@006`; - - const imageFile = fs.readFileSync(inputFile); - // Convert the image data to a Buffer and base64 encode it. - const encodedImage = Buffer.from(imageFile).toString('base64'); - - const maskImageFile = fs.readFileSync(maskFile); - // Convert the image mask data to a Buffer and base64 encode it. - const encodedMask = Buffer.from(maskImageFile).toString('base64'); - - const promptObj = { - prompt: prompt, // The text prompt describing what you want to see inserted - editMode: 'inpainting-insert', - image: { - bytesBase64Encoded: encodedImage, - }, - mask: { - image: { - bytesBase64Encoded: encodedMask, - }, - }, - }; - const instanceValue = helpers.toValue(promptObj); - const instances = [instanceValue]; - - const parameter = { - // Optional parameters - seed: 100, - // Controls the strength of the prompt - // 0-9 (low strength), 10-20 (medium strength), 21+ (high strength) - guidanceScale: 21, - sampleCount: 1, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - const predictions = response.predictions; - if (predictions.length === 0) { - console.log( - 'No image was generated. Check the request parameters and prompt.' - ); - } else { - let i = 1; - for (const prediction of predictions) { - const buff = Buffer.from( - prediction.structValue.fields.bytesBase64Encoded.stringValue, - 'base64' - ); - // Write image content to the output file - const writeFile = util.promisify(fs.writeFile); - const filename = `output${i}.png`; - await writeFile(filename, buff); - console.log(`Saved image ${filename}`); - i++; - } - } - } - await editImageInpaintingInsertMask(); - // [END generativeaionvertexai_imagen_edit_image_inpainting_insert_mask] -} - -main().catch(err => { - console.error(err); - process.exitcode = 1; -}); diff --git a/ai-platform/snippets/imagen-edit-image-inpainting-remove-mask.js b/ai-platform/snippets/imagen-edit-image-inpainting-remove-mask.js deleted file mode 100644 index 01901422af..0000000000 --- a/ai-platform/snippets/imagen-edit-image-inpainting-remove-mask.js +++ /dev/null @@ -1,121 +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() { - // [START generativeaionvertexai_imagen_edit_image_inpainting_remove_mask] - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = process.env.CAIP_PROJECT_ID; - const location = 'us-central1'; - const inputFile = 'resources/volleyball_game.png'; - const maskFile = 'resources/volleyball_game_inpainting_remove_mask.png'; - const prompt = 'volleyball game'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction Service Client library - 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: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function editImageInpaintingRemoveMask() { - const fs = require('fs'); - const util = require('util'); - // Configure the parent resource - const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imagegeneration@006`; - - const imageFile = fs.readFileSync(inputFile); - // Convert the image data to a Buffer and base64 encode it. - const encodedImage = Buffer.from(imageFile).toString('base64'); - - const maskImageFile = fs.readFileSync(maskFile); - // Convert the image mask data to a Buffer and base64 encode it. - const encodedMask = Buffer.from(maskImageFile).toString('base64'); - - const promptObj = { - prompt: prompt, // The text prompt describing the entire image - editMode: 'inpainting-remove', - image: { - bytesBase64Encoded: encodedImage, - }, - mask: { - image: { - bytesBase64Encoded: encodedMask, - }, - }, - }; - const instanceValue = helpers.toValue(promptObj); - const instances = [instanceValue]; - - const parameter = { - // Optional parameters - seed: 100, - // Controls the strength of the prompt - // 0-9 (low strength), 10-20 (medium strength), 21+ (high strength) - guidanceScale: 21, - sampleCount: 1, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - const predictions = response.predictions; - if (predictions.length === 0) { - console.log( - 'No image was generated. Check the request parameters and prompt.' - ); - } else { - let i = 1; - for (const prediction of predictions) { - const buff = Buffer.from( - prediction.structValue.fields.bytesBase64Encoded.stringValue, - 'base64' - ); - // Write image content to the output file - const writeFile = util.promisify(fs.writeFile); - const filename = `output${i}.png`; - await writeFile(filename, buff); - console.log(`Saved image ${filename}`); - i++; - } - } - } - await editImageInpaintingRemoveMask(); - // [END generativeaionvertexai_imagen_edit_image_inpainting_remove_mask] -} - -main().catch(err => { - console.error(err); - process.exitcode = 1; -}); diff --git a/ai-platform/snippets/imagen-edit-image-mask-free.js b/ai-platform/snippets/imagen-edit-image-mask-free.js deleted file mode 100644 index f5b58ada60..0000000000 --- a/ai-platform/snippets/imagen-edit-image-mask-free.js +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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 generativeaionvertexai_imagen_edit_image_mask_free] - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = process.env.CAIP_PROJECT_ID; - const location = 'us-central1'; - const inputFile = 'resources/cat.png'; - const prompt = 'dog'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction Service Client library - 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: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function editImageMaskFree() { - const fs = require('fs'); - const util = require('util'); - // Configure the parent resource - const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imagegeneration@002`; - - const imageFile = fs.readFileSync(inputFile); - // Convert the image data to a Buffer and base64 encode it. - const encodedImage = Buffer.from(imageFile).toString('base64'); - - const promptObj = { - prompt: prompt, // The text prompt describing what you want to see - image: { - bytesBase64Encoded: encodedImage, - }, - }; - const instanceValue = helpers.toValue(promptObj); - const instances = [instanceValue]; - - const parameter = { - // Optional parameters - seed: 100, - // Controls the strength of the prompt - // 0-9 (low strength), 10-20 (medium strength), 21+ (high strength) - guidanceScale: 21, - sampleCount: 1, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - const predictions = response.predictions; - if (predictions.length === 0) { - console.log( - 'No image was generated. Check the request parameters and prompt.' - ); - } else { - let i = 1; - for (const prediction of predictions) { - const buff = Buffer.from( - prediction.structValue.fields.bytesBase64Encoded.stringValue, - 'base64' - ); - // Write image content to the output file - const writeFile = util.promisify(fs.writeFile); - const filename = `output${i}.png`; - await writeFile(filename, buff); - console.log(`Saved image ${filename}`); - i++; - } - } - } - await editImageMaskFree(); - // [END generativeaionvertexai_imagen_edit_image_mask_free] -} - -main().catch(err => { - console.error(err); - process.exitcode = 1; -}); diff --git a/ai-platform/snippets/imagen-edit-image-outpainting-mask.js b/ai-platform/snippets/imagen-edit-image-outpainting-mask.js deleted file mode 100644 index 458d2fb206..0000000000 --- a/ai-platform/snippets/imagen-edit-image-outpainting-mask.js +++ /dev/null @@ -1,121 +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() { - // [START generativeaionvertexai_imagen_edit_image_outpainting_mask] - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = process.env.CAIP_PROJECT_ID; - const location = 'us-central1'; - const inputFile = 'resources/roller_skaters.png'; - const maskFile = 'resources/roller_skaters_mask.png'; - const prompt = 'city with skyscrapers'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction Service Client library - 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: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function editImageOutpaintingMask() { - const fs = require('fs'); - const util = require('util'); - // Configure the parent resource - const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imagegeneration@006`; - - const imageFile = fs.readFileSync(inputFile); - // Convert the image data to a Buffer and base64 encode it. - const encodedImage = Buffer.from(imageFile).toString('base64'); - - const maskImageFile = fs.readFileSync(maskFile); - // Convert the image mask data to a Buffer and base64 encode it. - const encodedMask = Buffer.from(maskImageFile).toString('base64'); - - const promptObj = { - prompt: prompt, // The optional text prompt describing what you want to see inserted - editMode: 'outpainting', - image: { - bytesBase64Encoded: encodedImage, - }, - mask: { - image: { - bytesBase64Encoded: encodedMask, - }, - }, - }; - const instanceValue = helpers.toValue(promptObj); - const instances = [instanceValue]; - - const parameter = { - // Optional parameters - seed: 100, - // Controls the strength of the prompt - // 0-9 (low strength), 10-20 (medium strength), 21+ (high strength) - guidanceScale: 21, - sampleCount: 1, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - const predictions = response.predictions; - if (predictions.length === 0) { - console.log( - 'No image was generated. Check the request parameters and prompt.' - ); - } else { - let i = 1; - for (const prediction of predictions) { - const buff = Buffer.from( - prediction.structValue.fields.bytesBase64Encoded.stringValue, - 'base64' - ); - // Write image content to the output file - const writeFile = util.promisify(fs.writeFile); - const filename = `output${i}.png`; - await writeFile(filename, buff); - console.log(`Saved image ${filename}`); - i++; - } - } - } - await editImageOutpaintingMask(); - // [END generativeaionvertexai_imagen_edit_image_outpainting_mask] -} - -main().catch(err => { - console.error(err); - process.exitcode = 1; -}); diff --git a/ai-platform/snippets/imagen-generate-image.js b/ai-platform/snippets/imagen-generate-image.js deleted file mode 100644 index 5601fb0079..0000000000 --- a/ai-platform/snippets/imagen-generate-image.js +++ /dev/null @@ -1,103 +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() { - // [START generativeaionvertexai_imagen_generate_image] - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = process.env.CAIP_PROJECT_ID; - const location = 'us-central1'; - const prompt = 'a dog reading a newspaper'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction Service Client library - 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: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function generateImage() { - const fs = require('fs'); - const util = require('util'); - // Configure the parent resource - const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imagen-3.0-generate-001`; - - const promptText = { - prompt: prompt, // The text prompt describing what you want to see - }; - const instanceValue = helpers.toValue(promptText); - const instances = [instanceValue]; - - const parameter = { - sampleCount: 1, - // You can't use a seed value and watermark at the same time. - // seed: 100, - // addWatermark: false, - aspectRatio: '1:1', - safetyFilterLevel: 'block_some', - personGeneration: 'allow_adult', - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - const predictions = response.predictions; - if (predictions.length === 0) { - console.log( - 'No image was generated. Check the request parameters and prompt.' - ); - } else { - let i = 1; - for (const prediction of predictions) { - const buff = Buffer.from( - prediction.structValue.fields.bytesBase64Encoded.stringValue, - 'base64' - ); - // Write image content to the output file - const writeFile = util.promisify(fs.writeFile); - const filename = `output${i}.png`; - await writeFile(filename, buff); - console.log(`Saved image ${filename}`); - i++; - } - } - } - await generateImage(); - // [END generativeaionvertexai_imagen_generate_image] -} - -main().catch(err => { - console.error(err); - process.exitcode = 1; -}); diff --git a/ai-platform/snippets/imagen-get-short-form-image-captions.js b/ai-platform/snippets/imagen-get-short-form-image-captions.js deleted file mode 100644 index 0af93ece76..0000000000 --- a/ai-platform/snippets/imagen-get-short-form-image-captions.js +++ /dev/null @@ -1,94 +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() { - // [START generativeaionvertexai_imagen_get_short_form_image_captions] - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = process.env.CAIP_PROJECT_ID; - const location = 'us-central1'; - const inputFile = 'resources/cat.png'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction Service Client library - 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: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function getShortFormImageCaptions() { - const fs = require('fs'); - // Configure the parent resource - const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imagetext@001`; - - const imageFile = fs.readFileSync(inputFile); - // Convert the image data to a Buffer and base64 encode it. - const encodedImage = Buffer.from(imageFile).toString('base64'); - - const instance = { - image: { - bytesBase64Encoded: encodedImage, - }, - }; - const instanceValue = helpers.toValue(instance); - const instances = [instanceValue]; - - const parameter = { - // Optional parameters - language: 'en', - sampleCount: 2, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - const predictions = response.predictions; - if (predictions.length === 0) { - console.log( - 'No captions were generated. Check the request parameters and image.' - ); - } else { - predictions.forEach(prediction => { - console.log(prediction.stringValue); - }); - } - } - await getShortFormImageCaptions(); - // [END generativeaionvertexai_imagen_get_short_form_image_captions] -} - -main().catch(err => { - console.error(err); - process.exitcode = 1; -}); diff --git a/ai-platform/snippets/imagen-get-short-form-image-responses.js b/ai-platform/snippets/imagen-get-short-form-image-responses.js deleted file mode 100644 index 4762be4230..0000000000 --- a/ai-platform/snippets/imagen-get-short-form-image-responses.js +++ /dev/null @@ -1,96 +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() { - // [START generativeaionvertexai_imagen_get_short_form_image_responses] - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = process.env.CAIP_PROJECT_ID; - const location = 'us-central1'; - const inputFile = 'resources/cat.png'; - // The question about the contents of the image. - const prompt = 'What breed of cat is this a picture of?'; - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction Service Client library - 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: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function getShortFormImageResponses() { - const fs = require('fs'); - // Configure the parent resource - const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imagetext@001`; - - const imageFile = fs.readFileSync(inputFile); - // Convert the image data to a Buffer and base64 encode it. - const encodedImage = Buffer.from(imageFile).toString('base64'); - - const instance = { - prompt: prompt, - image: { - bytesBase64Encoded: encodedImage, - }, - }; - const instanceValue = helpers.toValue(instance); - const instances = [instanceValue]; - - const parameter = { - // Optional parameters - sampleCount: 2, - }; - const parameters = helpers.toValue(parameter); - - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - const predictions = response.predictions; - if (predictions.length === 0) { - console.log( - 'No responses were generated. Check the request parameters and image.' - ); - } else { - predictions.forEach(prediction => { - console.log(prediction.stringValue); - }); - } - } - await getShortFormImageResponses(); - // [END generativeaionvertexai_imagen_get_short_form_image_responses] -} - -main().catch(err => { - console.error(err); - process.exitcode = 1; -}); diff --git a/ai-platform/snippets/imagen-verify-image-watermark.js b/ai-platform/snippets/imagen-verify-image-watermark.js deleted file mode 100644 index 16aa270c6c..0000000000 --- a/ai-platform/snippets/imagen-verify-image-watermark.js +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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 generativeaionvertexai_imagen_verify_image_watermark] - /** - * TODO(developer): Update these variables before running the sample. - */ - const projectId = process.env.CAIP_PROJECT_ID; - const location = 'us-central1'; - const inputFile = 'resources/dog_newspaper.png'; // has watermark - - const aiplatform = require('@google-cloud/aiplatform'); - - // Imports the Google Cloud Prediction Service Client library - 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: `${location}-aiplatform.googleapis.com`, - }; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(clientOptions); - - async function verifyImageWatermark() { - const fs = require('fs'); - // Configure the parent resource - const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imageverification@001`; - - const imageFile = fs.readFileSync(inputFile); - // Convert the image data to a Buffer and base64 encode it. - const encodedImage = Buffer.from(imageFile).toString('base64'); - - const instance = { - image: { - bytesBase64Encoded: encodedImage, - }, - }; - const instanceValue = helpers.toValue(instance); - const instances = [instanceValue]; - - const request = { - endpoint, - instances, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - const predictions = response.predictions; - if (predictions.length === 0) { - console.log('No decision was generated. Check the request image.'); - } else { - predictions.forEach(prediction => { - // "ACCEPT" if the image contains a digital watermark - // "REJECT" if the image does not contain a digital watermark - console.log(prediction.structValue.fields.decision.stringValue); - }); - } - } - await verifyImageWatermark(); - // [END generativeaionvertexai_imagen_verify_image_watermark] -} - -main().catch(err => { - console.error(err); - process.exitcode = 1; -}); diff --git a/ai-platform/snippets/import-data-image-classification.js b/ai-platform/snippets/import-data-image-classification.js deleted file mode 100644 index a65718500d..0000000000 --- a/ai-platform/snippets/import-data-image-classification.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_image_classification_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:////[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 importDataImageClassification() { - 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/image_classification_single_label_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 - const [importDataResponse] = await response.promise(); - - console.log( - `Import data image classification response : \ - ${JSON.stringify(importDataResponse)}` - ); - } - importDataImageClassification(); - // [END aiplatform_import_data_image_classification_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-image-object-detection.js b/ai-platform/snippets/import-data-image-object-detection.js deleted file mode 100644 index fd9745603a..0000000000 --- a/ai-platform/snippets/import-data-image-object-detection.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_image_object_detection_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:////[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 importDataImageObjectDetection() { - 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/image_bounding_box_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 image object detection response : \ - ${JSON.stringify(response.result)}` - ); - } - importDataImageObjectDetection(); - // [END aiplatform_import_data_image_object_detection_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-text-classification-single-label.js b/ai-platform/snippets/import-data-text-classification-single-label.js deleted file mode 100644 index 7114018363..0000000000 --- a/ai-platform/snippets/import-data-text-classification-single-label.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_text_classification_single_label_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:////[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 importDataTextClassificationSingleLabel() { - 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/text_classification_single_label_io_format_1.0.0.yaml', - }, - ]; - const request = { - name, - importConfigs, - }; - - // Import data request - const [response] = await datasetServiceClient.importData(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - const [importDataResponse] = await response.promise(); - - console.log( - `Import data text classification single label response : \ - ${JSON.stringify(importDataResponse.result)}` - ); - } - importDataTextClassificationSingleLabel(); - // [END aiplatform_import_data_text_classification_single_label_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-text-entity-extraction.js b/ai-platform/snippets/import-data-text-entity-extraction.js deleted file mode 100644 index 743b36468b..0000000000 --- a/ai-platform/snippets/import-data-text-entity-extraction.js +++ /dev/null @@ -1,81 +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_text_entity_extraction_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - */ - - // const datasetId = "YOUR_DATASET_ID"; - // const gcsSourceUri = "YOUR_GCS_SOURCE_URI"; - // eg. "gs:////[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 importDataTextEntityExtraction() { - 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/text_extraction_io_format_1.0.0.yaml', - }, - ]; - const request = { - name, - importConfigs, - }; - - // Import data request - const [response] = await datasetServiceClient.importData(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - const [importDataResponse] = await response.promise(); - - console.log( - `Import data text entity extraction response : \ - ${JSON.stringify(importDataResponse.result)}` - ); - } - importDataTextEntityExtraction(); - // [END aiplatform_import_data_text_entity_extraction_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-text-sentiment-analysis.js b/ai-platform/snippets/import-data-text-sentiment-analysis.js deleted file mode 100644 index c455fdb25e..0000000000 --- a/ai-platform/snippets/import-data-text-sentiment-analysis.js +++ /dev/null @@ -1,81 +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_text_sentiment_analysis_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - */ - - // const datasetId = "YOUR_DATASET_ID"; - // const gcsSourceUri = "YOUR_GCS_SOURCE_URI"; - // eg. "gs:////[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 importDataTextSentimentAnalysis() { - 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/text_sentiment_io_format_1.0.0.yaml', - }, - ]; - const request = { - name, - importConfigs, - }; - - // Import data request - const [response] = await datasetServiceClient.importData(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - const [importDataResponse] = await response.promise(); - - console.log( - `Import data text sentiment analysis response : \ - ${JSON.stringify(importDataResponse.result, null, 2)}` - ); - } - importDataTextSentimentAnalysis(); - // [END aiplatform_import_data_text_sentiment_analysis_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:////[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-video-classification.js b/ai-platform/snippets/import-data-video-classification.js deleted file mode 100644 index 7439bb8cce..0000000000 --- a/ai-platform/snippets/import-data-video-classification.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_classification_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:////[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 importDataVideoClassification() { - 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_classification_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 classification response : \ - ${JSON.stringify(response.result)}` - ); - } - importDataVideoClassification(); - // [END aiplatform_import_data_video_classification_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-object-tracking.js b/ai-platform/snippets/import-data-video-object-tracking.js deleted file mode 100644 index b447fa2988..0000000000 --- a/ai-platform/snippets/import-data-video-object-tracking.js +++ /dev/null @@ -1,81 +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_object_tracking_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - */ - - // const datasetId = 'YOUR_DATASET_ID'; - // const gcsSourceUri = 'YOUR_GCS_SOURCE_URI'; - // eg. 'gs:////[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 importDataVideoObjectTracking() { - 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_object_tracking_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: ${JSON.stringify(response.name)}`); - - // Wait for operation to complete - const [importDataResponse] = await response.promise(); - - console.log( - `Import data video object tracking response : \ - ${JSON.stringify(importDataResponse)}` - ); - } - importDataVideoObjectTracking(); - // [END aiplatform_import_data_video_object_tracking_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:////[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/import-feature-values-sample.js b/ai-platform/snippets/import-feature-values-sample.js deleted file mode 100644 index 01a174bfcb..0000000000 --- a/ai-platform/snippets/import-feature-values-sample.js +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Imports Feature values into the Featurestore from a source storage. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - avroGcsUri, - entityIdField, - featureTimeField, - workerCount = 2, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_import_feature_values_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const avroGcsUri = 'AVRO_FILE_IN_THE_GCS_URI'; - // const entityIdField = 'ENTITY_ID_FIELD_IN_AVRO'; - // const featureTimeField = 'TIMESTAMP_FIELD_IN_AVRO'; - // const workerCount = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function importFeatureValues() { - // Configure the entityType resource - const entityType = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const avroSource = { - gcsSource: { - uris: [avroGcsUri], - }, - }; - - const featureSpecs = [{id: 'age'}, {id: 'gender'}, {id: 'liked_genres'}]; - - const request = { - entityType: entityType, - avroSource: avroSource, - entityIdField: entityIdField, - featureSpecs: featureSpecs, - featureTimeField: featureTimeField, - workerCount: Number(workerCount), - }; - - // Import Feature Values Request - const [operation] = await featurestoreServiceClient.importFeatureValues( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Import feature values response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - importFeatureValues(); - // [END aiplatform_import_feature_values_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-endpoints.js b/ai-platform/snippets/list-endpoints.js deleted file mode 100644 index 01e425910c..0000000000 --- a/ai-platform/snippets/list-endpoints.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 - * - * 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'; - -async function main(projectId, location = 'us-central1') { - // [START aiplatform_list_endpoints_sample] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - const {EndpointServiceClient} = require('@google-cloud/aiplatform'); - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: 'us-central1-aiplatform.googleapis.com', - }; - const client = new EndpointServiceClient(clientOptions); - - async function listEndpoints() { - // Configure the parent resource - const parent = `projects/${projectId}/locations/${location}`; - const request = { - parent, - }; - - // Get and print out a list of all the endpoints for this resource - const [result] = await client.listEndpoints(request); - for (const endpoint of result) { - console.log(`\nEndpoint name: ${endpoint.name}`); - console.log(`Display name: ${endpoint.displayName}`); - if (endpoint.deployedModels[0]) { - console.log( - `First deployed model: ${endpoint.deployedModels[0].model}` - ); - } - } - } - listEndpoints(); - // [END aiplatform_list_endpoints_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-entity-types-async-sample.js b/ai-platform/snippets/list-entity-types-async-sample.js deleted file mode 100644 index c6b1c7401e..0000000000 --- a/ai-platform/snippets/list-entity-types-async-sample.js +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists EntityTypes Asynchronously in a given Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 5000 -) { - // [START aiplatform_list_entity_types_async_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listEntityTypesAsync() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - parent: parent, - }; - - // List EntityTypes Async request - const iterable = await featurestoreServiceClient.listEntityTypesAsync( - request, - {timeout: Number(timeout)} - ); - - console.log('List entity types async response'); - console.log('Raw response:'); - for await (const response of iterable) { - console.log(JSON.stringify(response, null, 2)); - } - } - listEntityTypesAsync(); - // [END aiplatform_list_entity_types_async_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-entity-types-sample.js b/ai-platform/snippets/list-entity-types-sample.js deleted file mode 100644 index 716842a0b0..0000000000 --- a/ai-platform/snippets/list-entity-types-sample.js +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists EntityTypes in a given Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 5000 -) { - // [START aiplatform_list_entity_types_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listEntityTypes() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - parent: parent, - }; - - // List EntityTypes request - const [response] = await featurestoreServiceClient.listEntityTypes( - request, - {timeout: Number(timeout)} - ); - - console.log('List entity types response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - listEntityTypes(); - // [END aiplatform_list_entity_types_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-entity-types-stream-sample.js b/ai-platform/snippets/list-entity-types-stream-sample.js deleted file mode 100644 index 5197d79fc0..0000000000 --- a/ai-platform/snippets/list-entity-types-stream-sample.js +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists EntityTypes using streaming in a given Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 5000 -) { - // [START aiplatform_list_entity_types_stream_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listEntityTypesStream() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - parent: parent, - }; - - // List EntityTypes stream request - const streamObject = await featurestoreServiceClient.listEntityTypesStream( - request, - {timeout: Number(timeout)} - ); - - console.log('List entity types stream response'); - console.log('Raw response:'); - streamObject.on('data', response => { - console.log(JSON.stringify(response, null, 2)); - }); - - streamObject.on('end', () => { - console.log('No more data to read'); - }); - - streamObject.on('close', () => { - console.log('Stream object listEntityTypesStream is closed'); - }); - } - listEntityTypesStream(); - // [END aiplatform_list_entity_types_stream_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-features-async-sample.js b/ai-platform/snippets/list-features-async-sample.js deleted file mode 100644 index 5df6446fc2..0000000000 --- a/ai-platform/snippets/list-features-async-sample.js +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists Features Asynchronously in a given EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_list_features_async_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listFeaturesAsync() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const request = { - parent: parent, - }; - - // List Features async request - const iterable = await featurestoreServiceClient.listFeaturesAsync( - request, - { - timeout: Number(timeout), - } - ); - - console.log('List features async response'); - console.log('Raw response:'); - for await (const response of iterable) { - console.log(JSON.stringify(response, null, 2)); - } - } - listFeaturesAsync(); - // [END aiplatform_list_features_async_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-features-sample.js b/ai-platform/snippets/list-features-sample.js deleted file mode 100644 index da75bfdf1b..0000000000 --- a/ai-platform/snippets/list-features-sample.js +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists Features in a given EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_list_features_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listFeatures() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const request = { - parent: parent, - }; - - // List Features request - const [response] = await featurestoreServiceClient.listFeatures(request, { - timeout: Number(timeout), - }); - - console.log('List features response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - listFeatures(); - // [END aiplatform_list_features_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-features-stream-sample.js b/ai-platform/snippets/list-features-stream-sample.js deleted file mode 100644 index c85e3f5462..0000000000 --- a/ai-platform/snippets/list-features-stream-sample.js +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists Features using streaming in a given EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_list_features_stream_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listFeaturesStream() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const request = { - parent: parent, - }; - - // List Features stream request - const streamObject = await featurestoreServiceClient.listFeaturesStream( - request, - { - timeout: Number(timeout), - } - ); - - console.log('List features stream response'); - console.log('Raw response:'); - streamObject.on('data', response => { - console.log(JSON.stringify(response, null, 2)); - }); - - streamObject.on('end', () => { - console.log('No more data to read'); - }); - - streamObject.on('close', () => { - console.log('Stream object listFeaturesStream is closed'); - }); - } - listFeaturesStream(); - // [END aiplatform_list_features_stream_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-featurestores-async-sample.js b/ai-platform/snippets/list-featurestores-async-sample.js deleted file mode 100644 index 16bbc8f779..0000000000 --- a/ai-platform/snippets/list-featurestores-async-sample.js +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists Featurestores asynchronously in a given project and location. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 5000 -) { - // [START aiplatform_list_featurestores_async_sample] - /** - * 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 apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listFeaturestoresAsync() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const request = { - parent: parent, - }; - - // List featurestores async request - const iterable = await featurestoreServiceClient.listFeaturestoresAsync( - request, - {timeout: Number(timeout)} - ); - - console.log('List featurestores async response'); - console.log('Raw response:'); - for await (const response of iterable) { - console.log(JSON.stringify(response, null, 2)); - } - } - listFeaturestoresAsync(); - // [END aiplatform_list_featurestores_async_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-featurestores-sample.js b/ai-platform/snippets/list-featurestores-sample.js deleted file mode 100644 index 1bacda4376..0000000000 --- a/ai-platform/snippets/list-featurestores-sample.js +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists Featurestores in a given project and location. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 5000 -) { - // [START aiplatform_list_featurestores_sample] - /** - * 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 apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listFeaturestores() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const request = { - parent: parent, - }; - - // List featurestores request - const [response] = await featurestoreServiceClient.listFeaturestores( - request, - {timeout: Number(timeout)} - ); - - console.log('List featurestores response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - listFeaturestores(); - // [END aiplatform_list_featurestores_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-featurestores-stream-sample.js b/ai-platform/snippets/list-featurestores-stream-sample.js deleted file mode 100644 index f8515464a6..0000000000 --- a/ai-platform/snippets/list-featurestores-stream-sample.js +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Lists Featurestores using stream in a given project and location. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 5000 -) { - // [START aiplatform_list_featurestores_stream_sample] - /** - * 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 apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function listFeaturestoresStream() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const request = { - parent: parent, - }; - - // List featurestores stream request - const streamObject = - await featurestoreServiceClient.listFeaturestoresStream(request, { - timeout: Number(timeout), - }); - - console.log('List featurestores stream response'); - console.log('Raw response:'); - - streamObject.on('data', response => { - console.log(JSON.stringify(response, null, 2)); - }); - - streamObject.on('end', () => { - console.log('No more data to read'); - }); - - streamObject.on('close', () => { - console.log('Stream object listFeaturestoresStream is closed'); - }); - } - listFeaturestoresStream(); - // [END aiplatform_list_featurestores_stream_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/list-model-evaluation-slices.js b/ai-platform/snippets/list-model-evaluation-slices.js deleted file mode 100644 index b27bb56f5d..0000000000 --- a/ai-platform/snippets/list-model-evaluation-slices.js +++ /dev/null @@ -1,71 +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_list_model_evaluation_slices_sample] - /** - * TODO(developer): Uncomment these variables before running the sample - * (not necessary if passing values as arguments). To obtain evaluationId, - * instantiate the client and run the following the commands. - */ - // const parentName = `projects/${project}/locations/${location}/models/${modelId}`; - // const evalRequest = { - // parent: parentName - // }; - // const [evalResponse] = await modelServiceClient.listModelEvaluations(evalRequest); - // console.log(evalResponse); - - // 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 listModelEvaluationSlices() { - // Configure the parent resources - const parent = `projects/${project}/locations/${location}/models/${modelId}/evaluations/${evaluationId}`; - const request = { - parent, - }; - - // Get and print out a list of all the evaluation slices for this resource - const [response] = - await modelServiceClient.listModelEvaluationSlices(request); - console.log('List model evaluation response', response); - console.log(response); - } - listModelEvaluationSlices(); - // [END aiplatform_list_model_evaluation_slices_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/package.json b/ai-platform/snippets/package.json deleted file mode 100644 index 4d7ad0964f..0000000000 --- a/ai-platform/snippets/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "nodejs-aiplatform-samples", - "private": true, - "license": "Apache-2.0", - "author": "Google LLC", - "engines": { - "node": ">=16.0.0" - }, - "files": [ - "*.js" - ], - "scripts": { - "test": "c8 mocha -p -j 2 --timeout 2400000 test/*.js" - }, - "dependencies": { - "@google-cloud/aiplatform": "^3.0.0", - "@google-cloud/bigquery": "^7.0.0", - "@google-cloud/storage": "^7.0.0" - }, - "devDependencies": { - "c8": "^10.0.0", - "chai": "^4.5.0", - "mocha": "^10.0.0", - "uuid": "^10.0.0", - "sinon": "^18.0.0" - } -} - 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-custom-trained-model.js b/ai-platform/snippets/predict-custom-trained-model.js deleted file mode 100644 index 24f8ccbc5c..0000000000 --- a/ai-platform/snippets/predict-custom-trained-model.js +++ /dev/null @@ -1,105 +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(filename, endpointId, project, location = 'us-central1') { - // [START aiplatform_predict_custom_trained_model_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const filename = "YOUR_PREDICTION_FILE_NAME"; - // const endpointId = "YOUR_ENDPOINT_ID"; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const util = require('util'); - const {readFile} = require('fs'); - const readFileAsync = util.promisify(readFile); - - // Imports the Google Cloud Prediction Service Client library - const {PredictionServiceClient} = require('@google-cloud/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 predictCustomTrainedModel() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - const parameters = { - structValue: { - fields: {}, - }, - }; - const instanceDict = await readFileAsync(filename, 'utf8'); - const instanceValue = JSON.parse(instanceDict); - const instance = { - structValue: { - fields: { - Age: {stringValue: instanceValue['Age']}, - Balance: {stringValue: instanceValue['Balance']}, - Campaign: {stringValue: instanceValue['Campaign']}, - Contact: {stringValue: instanceValue['Contact']}, - Day: {stringValue: instanceValue['Day']}, - Default: {stringValue: instanceValue['Default']}, - Deposit: {stringValue: instanceValue['Deposit']}, - Duration: {stringValue: instanceValue['Duration']}, - Housing: {stringValue: instanceValue['Housing']}, - Job: {stringValue: instanceValue['Job']}, - Loan: {stringValue: instanceValue['Loan']}, - MaritalStatus: {stringValue: instanceValue['MaritalStatus']}, - Month: {stringValue: instanceValue['Month']}, - PDays: {stringValue: instanceValue['PDays']}, - POutcome: {stringValue: instanceValue['POutcome']}, - Previous: {stringValue: instanceValue['Previous']}, - }, - }, - }; - - const instances = [instance]; - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - - console.log('Predict custom trained model response'); - console.log(`\tDeployed model id : ${response.deployedModelId}`); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const prediction of predictions) { - console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`); - } - } - predictCustomTrainedModel(); - // [END aiplatform_predict_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/predict-image-classification.js b/ai-platform/snippets/predict-image-classification.js deleted file mode 100644 index 6be6685757..0000000000 --- a/ai-platform/snippets/predict-image-classification.js +++ /dev/null @@ -1,95 +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(filename, endpointId, project, location = 'us-central1') { - // [START aiplatform_predict_image_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const filename = "YOUR_PREDICTION_FILE_NAME"; - // const endpointId = "YOUR_ENDPOINT_ID"; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {instance, params, prediction} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.predict; - - // Imports the Google Cloud Prediction Service Client library - const {PredictionServiceClient} = aiplatform.v1; - - // 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 predictImageClassification() { - // Configure the endpoint resource - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - - const parametersObj = new params.ImageClassificationPredictionParams({ - confidenceThreshold: 0.5, - maxPredictions: 5, - }); - const parameters = parametersObj.toValue(); - - const fs = require('fs'); - const image = fs.readFileSync(filename, 'base64'); - const instanceObj = new instance.ImageClassificationPredictionInstance({ - content: image, - }); - const instanceValue = instanceObj.toValue(); - - const instances = [instanceValue]; - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - - console.log('Predict image classification response'); - console.log(`\tDeployed model id : ${response.deployedModelId}`); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const predictionValue of predictions) { - const predictionResultObj = - prediction.ClassificationPredictionResult.fromValue(predictionValue); - for (const [i, label] of predictionResultObj.displayNames.entries()) { - console.log(`\tDisplay name: ${label}`); - console.log(`\tConfidences: ${predictionResultObj.confidences[i]}`); - console.log(`\tIDs: ${predictionResultObj.ids[i]}\n\n`); - } - } - } - predictImageClassification(); - // [END aiplatform_predict_image_classification_sample] -} - -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-image-and-text.js b/ai-platform/snippets/predict-image-from-image-and-text.js deleted file mode 100644 index cc67fe8313..0000000000 --- a/ai-platform/snippets/predict-image-from-image-and-text.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', - baseImagePath, - textPrompt -) { - // [START aiplatform_sdk_text_image_embedding] - // [START generativeaionvertexai_sdk_text_image_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 bastImagePath = "YOUR_BASED_IMAGE_PATH" - // 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 predictImageFromImageAndText() { - // Configure the parent resource - const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; - - const fs = require('fs'); - const imageFile = fs.readFileSync(baseImagePath); - - // Convert the image data to a Buffer and base64 encode it. - const encodedImage = Buffer.from(imageFile).toString('base64'); - - const prompt = { - text: textPrompt, - image: { - bytesBase64Encoded: encodedImage, - }, - }; - 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 predictImageFromImageAndText(); - // [END aiplatform_sdk_text_image_embedding] - // [END generativeaionvertexai_sdk_text_image_embedding] -} - -exports.predictImageFromImageAndText = main; 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-image-object-detection.js b/ai-platform/snippets/predict-image-object-detection.js deleted file mode 100644 index ed6fdd5d94..0000000000 --- a/ai-platform/snippets/predict-image-object-detection.js +++ /dev/null @@ -1,98 +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(filename, endpointId, project, location = 'us-central1') { - // [START aiplatform_predict_image_object_detection_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const filename = "YOUR_PREDICTION_FILE_NAME"; - // const endpointId = "YOUR_ENDPOINT_ID"; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {instance, params, prediction} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.predict; - - // Imports the Google Cloud Prediction Service Client library - const {PredictionServiceClient} = aiplatform.v1; - - // 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 predictImageObjectDetection() { - // Configure the endpoint resource - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - - const parametersObj = new params.ImageObjectDetectionPredictionParams({ - confidenceThreshold: 0.5, - maxPredictions: 5, - }); - const parameters = parametersObj.toValue(); - - const fs = require('fs'); - const image = fs.readFileSync(filename, 'base64'); - const instanceObj = new instance.ImageObjectDetectionPredictionInstance({ - content: image, - }); - - const instanceVal = instanceObj.toValue(); - const instances = [instanceVal]; - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - - console.log('Predict image object detection response'); - console.log(`\tDeployed model id : ${response.deployedModelId}`); - const predictions = response.predictions; - console.log('Predictions :'); - for (const predictionResultVal of predictions) { - const predictionResultObj = - prediction.ImageObjectDetectionPredictionResult.fromValue( - predictionResultVal - ); - for (const [i, label] of predictionResultObj.displayNames.entries()) { - console.log(`\tDisplay name: ${label}`); - console.log(`\tConfidences: ${predictionResultObj.confidences[i]}`); - console.log(`\tIDs: ${predictionResultObj.ids[i]}`); - console.log(`\tBounding boxes: ${predictionResultObj.bboxes[i]}\n\n`); - } - } - } - predictImageObjectDetection(); - // [END aiplatform_predict_image_object_detection_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-tabular-classification.js b/ai-platform/snippets/predict-tabular-classification.js deleted file mode 100644 index c5fd9efb18..0000000000 --- a/ai-platform/snippets/predict-tabular-classification.js +++ /dev/null @@ -1,93 +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(endpointId, project, location = 'us-central1') { - // [START aiplatform_predict_tabular_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const endpointId = 'YOUR_ENDPOINT_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {prediction} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.predict; - - // 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 predictTablesClassification() { - // Configure the endpoint resource - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - const parameters = helpers.toValue({}); - - const instance = helpers.toValue({ - petal_length: '1.4', - petal_width: '1.3', - sepal_length: '5.1', - sepal_width: '2.8', - }); - - const instances = [instance]; - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - - console.log('Predict tabular classification response'); - console.log(`\tDeployed model id : ${response.deployedModelId}\n`); - const predictions = response.predictions; - console.log('Predictions :'); - for (const predictionResultVal of predictions) { - const predictionResultObj = - prediction.TabularClassificationPredictionResult.fromValue( - predictionResultVal - ); - for (const [i, class_] of predictionResultObj.classes.entries()) { - console.log(`\tClass: ${class_}`); - console.log(`\tScore: ${predictionResultObj.scores[i]}\n\n`); - } - } - } - predictTablesClassification(); - // [END aiplatform_predict_tabular_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-tabular-regression.js b/ai-platform/snippets/predict-tabular-regression.js deleted file mode 100644 index 5ef754f5d5..0000000000 --- a/ai-platform/snippets/predict-tabular-regression.js +++ /dev/null @@ -1,112 +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(endpointId, project, location = 'us-central1') { - // [START aiplatform_predict_tabular_regression_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const endpointId = 'YOUR_ENDPOINT_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {prediction} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.predict; - - // 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 predictTablesRegression() { - // Configure the endpoint resource - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - const parameters = helpers.toValue({}); - - // TODO (erschmid): Make this less painful - const instance = helpers.toValue({ - BOOLEAN_2unique_NULLABLE: false, - DATETIME_1unique_NULLABLE: '2019-01-01 00:00:00', - DATE_1unique_NULLABLE: '2019-01-01', - FLOAT_5000unique_NULLABLE: 1611, - FLOAT_5000unique_REPEATED: [2320, 1192], - INTEGER_5000unique_NULLABLE: '8', - NUMERIC_5000unique_NULLABLE: 16, - STRING_5000unique_NULLABLE: 'str-2', - STRUCT_NULLABLE: { - BOOLEAN_2unique_NULLABLE: false, - DATE_1unique_NULLABLE: '2019-01-01', - DATETIME_1unique_NULLABLE: '2019-01-01 00:00:00', - FLOAT_5000unique_NULLABLE: 1308, - FLOAT_5000unique_REPEATED: [2323, 1178], - FLOAT_5000unique_REQUIRED: 3089, - INTEGER_5000unique_NULLABLE: '1777', - NUMERIC_5000unique_NULLABLE: 3323, - TIME_1unique_NULLABLE: '23:59:59.999999', - STRING_5000unique_NULLABLE: 'str-49', - TIMESTAMP_1unique_NULLABLE: '1546387199999999', - }, - TIMESTAMP_1unique_NULLABLE: '1546387199999999', - TIME_1unique_NULLABLE: '23:59:59.999999', - }); - - const instances = [instance]; - const request = { - endpoint, - instances, - parameters, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - - console.log('Predict tabular regression response'); - console.log(`\tDeployed model id : ${response.deployedModelId}`); - const predictions = response.predictions; - console.log('\tPredictions :'); - for (const predictionResultVal of predictions) { - const predictionResultObj = - prediction.TabularRegressionPredictionResult.fromValue( - predictionResultVal - ); - console.log(`\tUpper bound: ${predictionResultObj.upper_bound}`); - console.log(`\tLower bound: ${predictionResultObj.lower_bound}`); - console.log(`\tLower bound: ${predictionResultObj.value}`); - } - } - predictTablesRegression(); - // [END aiplatform_predict_tabular_regression_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-text-classification.js b/ai-platform/snippets/predict-text-classification.js deleted file mode 100644 index 22433ee068..0000000000 --- a/ai-platform/snippets/predict-text-classification.js +++ /dev/null @@ -1,89 +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(text, endpointId, project, location) { - // [START aiplatform_predict_text_classification_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const text = 'YOUR_PREDICTION_TEXT'; - // const endpointId = 'YOUR_ENDPOINT_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {instance, prediction} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.predict; - - // Imports the Google Cloud Model Service Client library - const {PredictionServiceClient} = aiplatform.v1; - - // 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 predictTextClassification() { - // Configure the resources - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - - const predictionInstance = - new instance.TextClassificationPredictionInstance({ - content: text, - }); - const instanceValue = predictionInstance.toValue(); - - const instances = [instanceValue]; - const request = { - endpoint, - instances, - }; - - const [response] = await predictionServiceClient.predict(request); - console.log('Predict text classification response'); - console.log(`\tDeployed model id : ${response.deployedModelId}\n\n`); - - console.log('Prediction results:'); - - for (const predictionResultValue of response.predictions) { - const predictionResult = - prediction.ClassificationPredictionResult.fromValue( - predictionResultValue - ); - - for (const [i, label] of predictionResult.displayNames.entries()) { - console.log(`\tDisplay name: ${label}`); - console.log(`\tConfidences: ${predictionResult.confidences[i]}`); - console.log(`\tIDs: ${predictionResult.ids[i]}\n\n`); - } - } - } - predictTextClassification(); - // [END aiplatform_predict_text_classification_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-text-embeddings-preview.js b/ai-platform/snippets/predict-text-embeddings-preview.js deleted file mode 100644 index 9003c6c6d4..0000000000 --- a/ai-platform/snippets/predict-text-embeddings-preview.js +++ /dev/null @@ -1,65 +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 generativeaionvertexai_sdk_embedding] - - // TODO(developer): Update the following for your own use case. - const project = 'long-door-651'; - const model = 'text-embedding-005'; - const location = 'us-central1'; - // Calculate the embedding for code blocks. Using 'RETRIEVAL_DOCUMENT' for corpus. - // Specify the task type as 'CODE_RETRIEVAL_QUERY' for query, e.g. 'Retrieve a function that adds two numbers'. - const texts = - 'def func(a, b): return a + b;def func(a, b): return a - b;def func(a, b): return (a ** 2 + b ** 2) ** 0.5'; - const task = 'RETRIEVAL_DOCUMENT'; - const dimensionality = 3; - const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; - - const aiplatform = require('@google-cloud/aiplatform'); - const {PredictionServiceClient} = aiplatform.v1; - const {helpers} = aiplatform; // helps construct protobuf.Value objects. - const clientOptions = {apiEndpoint: apiEndpoint}; - const endpoint = `projects/${project}/locations/${location}/publishers/google/models/${model}`; - const parameters = helpers.toValue({ - outputDimensionality: parseInt(dimensionality), - }); - - async function callPredict() { - const instances = texts - .split(';') - .map(e => helpers.toValue({content: e, task_type: task})); - const request = {endpoint, instances, parameters}; - const client = new PredictionServiceClient(clientOptions); - const [response] = await client.predict(request); - const predictions = response.predictions; - const embeddings = predictions.map(p => { - const embeddingsProto = p.structValue.fields.embeddings; - const valuesProto = embeddingsProto.structValue.fields.values; - return valuesProto.listValue.values.map(v => v.numberValue); - }); - console.log('Got embeddings: \n' + JSON.stringify(embeddings)); - } - await callPredict(); - // [END generativeaionvertexai_sdk_embedding] -} - -main().catch(err => { - console.error(err); - process.exitCode = 1; -}); diff --git a/ai-platform/snippets/predict-text-embeddings.js b/ai-platform/snippets/predict-text-embeddings.js deleted file mode 100644 index 3032833bc4..0000000000 --- a/ai-platform/snippets/predict-text-embeddings.js +++ /dev/null @@ -1,65 +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'; - -// [START aiplatform_sdk_embedding] -// [START generativeaionvertexai_sdk_embedding] -async function main( - project, - model = 'text-embedding-005', - texts = 'banana bread?;banana muffins?', - task = 'QUESTION_ANSWERING', - dimensionality = 0, - apiEndpoint = 'us-central1-aiplatform.googleapis.com' -) { - const aiplatform = require('@google-cloud/aiplatform'); - const {PredictionServiceClient} = aiplatform.v1; - const {helpers} = aiplatform; // helps construct protobuf.Value objects. - const clientOptions = {apiEndpoint: apiEndpoint}; - const location = 'us-central1'; - const endpoint = `projects/${project}/locations/${location}/publishers/google/models/${model}`; - - async function callPredict() { - const instances = texts - .split(';') - .map(e => helpers.toValue({content: e, task_type: task})); - const parameters = helpers.toValue( - dimensionality > 0 ? {outputDimensionality: parseInt(dimensionality)} : {} - ); - const request = {endpoint, instances, parameters}; - const client = new PredictionServiceClient(clientOptions); - const [response] = await client.predict(request); - const predictions = response.predictions; - const embeddings = predictions.map(p => { - const embeddingsProto = p.structValue.fields.embeddings; - const valuesProto = embeddingsProto.structValue.fields.values; - return valuesProto.listValue.values.map(v => v.numberValue); - }); - console.log('Got embeddings: \n' + JSON.stringify(embeddings)); - } - - callPredict(); -} -// [END aiplatform_sdk_embedding] -// [END generativeaionvertexai_sdk_embedding] - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/predict-text-entity-extraction.js b/ai-platform/snippets/predict-text-entity-extraction.js deleted file mode 100644 index 4a6f318a30..0000000000 --- a/ai-platform/snippets/predict-text-entity-extraction.js +++ /dev/null @@ -1,97 +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(text, endpointId, project, location = 'us-central1') { - // [START aiplatform_predict_text_entity_extraction_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const text = "YOUR_PREDICTION_TEXT"; - // const endpointId = "YOUR_ENDPOINT_ID"; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {instance, prediction} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.predict; - - // Imports the Google Cloud Model Service Client library - const {PredictionServiceClient} = aiplatform.v1; - - // 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 predictTextEntityExtraction() { - // Configure the endpoint resource - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - - const instanceObj = new instance.TextExtractionPredictionInstance({ - content: text, - }); - const instanceVal = instanceObj.toValue(); - const instances = [instanceVal]; - - const request = { - endpoint, - instances, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - - console.log('Predict text entity extraction response :'); - console.log(`\tDeployed model id : ${response.deployedModelId}`); - - console.log('\nPredictions :'); - for (const predictionResultValue of response.predictions) { - const predictionResult = - prediction.TextExtractionPredictionResult.fromValue( - predictionResultValue - ); - - for (const [i, label] of predictionResult.displayNames.entries()) { - const textStartOffset = parseInt( - predictionResult.textSegmentStartOffsets[i] - ); - const textEndOffset = parseInt( - predictionResult.textSegmentEndOffsets[i] - ); - const entity = text.substring(textStartOffset, textEndOffset); - console.log(`\tEntity: ${entity}`); - console.log(`\tEntity type: ${label}`); - console.log(`\tConfidences: ${predictionResult.confidences[i]}`); - console.log(`\tIDs: ${predictionResult.ids[i]}\n\n`); - } - } - } - predictTextEntityExtraction(); - // [END aiplatform_predict_text_entity_extraction_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); 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-analysis.js b/ai-platform/snippets/predict-text-sentiment-analysis.js deleted file mode 100644 index 9bbbe3cecc..0000000000 --- a/ai-platform/snippets/predict-text-sentiment-analysis.js +++ /dev/null @@ -1,84 +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(text, endpointId, project, location = 'us-central1') { - // [START aiplatform_predict_text_sentiment_analysis_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const text = "YOUR_PREDICTION_TEXT"; - // const endpointId = "YOUR_ENDPOINT_ID"; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - const aiplatform = require('@google-cloud/aiplatform'); - const {instance, prediction} = - aiplatform.protos.google.cloud.aiplatform.v1.schema.predict; - - // Imports the Google Cloud Model Service Client library - const {PredictionServiceClient} = aiplatform.v1; - - // 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 predictTextSentimentAnalysis() { - // Configure the endpoint resource - const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; - - const instanceObj = new instance.TextSentimentPredictionInstance({ - content: text, - }); - const instanceVal = instanceObj.toValue(); - - const instances = [instanceVal]; - const request = { - endpoint, - instances, - }; - - // Predict request - const [response] = await predictionServiceClient.predict(request); - - console.log('Predict text sentiment analysis response:'); - console.log(`\tDeployed model id : ${response.deployedModelId}`); - - console.log('\nPredictions :'); - for (const predictionResultValue of response.predictions) { - const predictionResult = - prediction.TextSentimentPredictionResult.fromValue( - predictionResultValue - ); - console.log(`\tSentiment measure: ${predictionResult.sentiment}`); - } - } - predictTextSentimentAnalysis(); - // [END aiplatform_predict_text_sentiment_analysis_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); 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/read-feature-values-sample.js b/ai-platform/snippets/read-feature-values-sample.js deleted file mode 100644 index df4f5a379f..0000000000 --- a/ai-platform/snippets/read-feature-values-sample.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Reads Feature values of a specific entity of an EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - entityId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_read_feature_values_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const entityId = 'ENTITY_ID_TO_SERVE'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreOnlineServingServiceClient} = - require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreOnlineServingServiceClient = - new FeaturestoreOnlineServingServiceClient(clientOptions); - - async function readFeatureValues() { - // Configure the entityType resource - const entityType = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - const featureSelector = { - idMatcher: { - ids: ['age', 'gender', 'liked_genres'], - }, - }; - - const request = { - entityType: entityType, - entityId: entityId, - featureSelector: featureSelector, - }; - - // Read Feature Values Request - const [response] = - await featurestoreOnlineServingServiceClient.readFeatureValues(request, { - timeout: Number(timeout), - }); - - console.log('Read feature values response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - readFeatureValues(); - // [END aiplatform_read_feature_values_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/resources/caprese_salad.jpg b/ai-platform/snippets/resources/caprese_salad.jpg deleted file mode 100644 index 7957ca94d9..0000000000 Binary files a/ai-platform/snippets/resources/caprese_salad.jpg and /dev/null differ diff --git a/ai-platform/snippets/resources/cat.png b/ai-platform/snippets/resources/cat.png deleted file mode 100644 index 67f2b55a6f..0000000000 Binary files a/ai-platform/snippets/resources/cat.png and /dev/null differ diff --git a/ai-platform/snippets/resources/daisy.jpg b/ai-platform/snippets/resources/daisy.jpg deleted file mode 100644 index ae01cae918..0000000000 Binary files a/ai-platform/snippets/resources/daisy.jpg and /dev/null differ diff --git a/ai-platform/snippets/resources/dog_newspaper.png b/ai-platform/snippets/resources/dog_newspaper.png deleted file mode 100644 index cd47e3d770..0000000000 Binary files a/ai-platform/snippets/resources/dog_newspaper.png and /dev/null differ diff --git a/ai-platform/snippets/resources/roller_skaters.png b/ai-platform/snippets/resources/roller_skaters.png deleted file mode 100644 index e63adbfdce..0000000000 Binary files a/ai-platform/snippets/resources/roller_skaters.png and /dev/null differ diff --git a/ai-platform/snippets/resources/roller_skaters_mask.png b/ai-platform/snippets/resources/roller_skaters_mask.png deleted file mode 100644 index 333da89897..0000000000 Binary files a/ai-platform/snippets/resources/roller_skaters_mask.png and /dev/null differ diff --git a/ai-platform/snippets/resources/volleyball_game.png b/ai-platform/snippets/resources/volleyball_game.png deleted file mode 100644 index 2a335ef4fb..0000000000 Binary files a/ai-platform/snippets/resources/volleyball_game.png and /dev/null differ diff --git a/ai-platform/snippets/resources/volleyball_game_inpainting_remove_mask.png b/ai-platform/snippets/resources/volleyball_game_inpainting_remove_mask.png deleted file mode 100644 index 784c1f5a42..0000000000 Binary files a/ai-platform/snippets/resources/volleyball_game_inpainting_remove_mask.png and /dev/null differ diff --git a/ai-platform/snippets/resources/woman.png b/ai-platform/snippets/resources/woman.png deleted file mode 100644 index f232924368..0000000000 Binary files a/ai-platform/snippets/resources/woman.png and /dev/null differ diff --git a/ai-platform/snippets/resources/woman_inpainting_insert_mask.png b/ai-platform/snippets/resources/woman_inpainting_insert_mask.png deleted file mode 100644 index d5399635b0..0000000000 Binary files a/ai-platform/snippets/resources/woman_inpainting_insert_mask.png and /dev/null differ diff --git a/ai-platform/snippets/search-features-async-sample.js b/ai-platform/snippets/search-features-async-sample.js deleted file mode 100644 index c2a74fb14f..0000000000 --- a/ai-platform/snippets/search-features-async-sample.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Searches Features matching a query in a given project Asyncronously. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - query, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_search_features_async_sample] - /** - * 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 apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function searchFeaturesAsync() { - // Configure the locationResource resource - const locationResource = `projects/${project}/locations/${location}`; - - const request = { - location: locationResource, - query: query, - }; - - // Search Features async request - const iterable = await featurestoreServiceClient.searchFeaturesAsync( - request, - { - timeout: Number(timeout), - } - ); - - console.log('Search features async response'); - console.log('Raw response:'); - for await (const response of iterable) { - console.log(JSON.stringify(response, null, 2)); - } - } - searchFeaturesAsync(); - // [END aiplatform_search_features_async_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/search-features-sample.js b/ai-platform/snippets/search-features-sample.js deleted file mode 100644 index 56a1dff477..0000000000 --- a/ai-platform/snippets/search-features-sample.js +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Searches Features matching a query in a given project. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - query, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_search_features_sample] - /** - * 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 apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function searchFeatures() { - // Configure the locationResource resource - const locationResource = `projects/${project}/locations/${location}`; - - const request = { - location: locationResource, - query: query, - }; - - // Search Features request - const [response] = await featurestoreServiceClient.searchFeatures(request, { - timeout: Number(timeout), - }); - - console.log('Search features response'); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - searchFeatures(); - // [END aiplatform_search_features_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/search-features-stream-sample.js b/ai-platform/snippets/search-features-stream-sample.js deleted file mode 100644 index 798dadfcb4..0000000000 --- a/ai-platform/snippets/search-features-stream-sample.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Searches Features matching a query in a given project using streaming. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - query, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_search_features_stream_sample] - /** - * 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 apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function searchFeaturesStream() { - // Configure the locationResource resource - const locationResource = `projects/${project}/locations/${location}`; - - const request = { - location: locationResource, - query: query, - }; - - // Search Features stream request - const streamObject = await featurestoreServiceClient.searchFeaturesStream( - request, - { - timeout: Number(timeout), - } - ); - - console.log('Search features stream response'); - console.log('Raw response:'); - streamObject.on('data', response => { - console.log(JSON.stringify(response, null, 2)); - }); - - streamObject.on('end', () => { - console.log('No more data to read'); - }); - - streamObject.on('close', () => { - console.log('Stream object searchFeaturesStream is closed'); - }); - } - searchFeaturesStream(); - // [END aiplatform_search_features_stream_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 deleted file mode 100644 index 737da7add0..0000000000 --- a/ai-platform/snippets/test/batch-prediction-gemini.test.js +++ /dev/null @@ -1,89 +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 cp = require('child_process'); -const {JobServiceClient} = require('@google-cloud/aiplatform'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -describe('Batch predict with Gemini', async () => { - const projectId = process.env.CAIP_PROJECT_ID; - const outputGCSUri = 'gs://ucaip-samples-test-output/'; - const outputBqUri = `bq://${process.env.CAIP_PROJECT_ID}.gen_ai_batch_prediction.predictions_${Date.now()}`; - const location = 'us-central1'; - - const jobServiceClient = new JobServiceClient({ - apiEndpoint: `${location}-aiplatform.googleapis.com`, - }); - let batchPredictionGcsJobId; - let batchPredictionBqJobId; - - after(async () => { - let name = jobServiceClient.batchPredictionJobPath( - projectId, - location, - batchPredictionGcsJobId - ); - cancelAndDeleteJob(name); - - name = jobServiceClient.batchPredictionJobPath( - projectId, - location, - batchPredictionBqJobId - ); - cancelAndDeleteJob(name); - - function cancelAndDeleteJob(name) { - const cancelRequest = { - name, - }; - - jobServiceClient.cancelBatchPredictionJob(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return jobServiceClient.deleteBatchPredictionJob(deleteRequest); - }); - } - }); - - it('should create Batch prediction Gemini job with GCS ', async () => { - const response = execSync( - `node ./batch-prediction/batch-predict-gcs.js ${projectId} ${outputGCSUri}` - ); - - assert.match(response, new RegExp('/batchPredictionJobs/')); - batchPredictionGcsJobId = response - .split('/locations/us-central1/batchPredictionJobs/')[1] - .split('\n')[0]; - }).timeout(10000); - - it('should create Batch prediction Gemini job with BigQuery', async () => { - const response = execSync( - `node ./batch-prediction/batch-predict-bq.js ${projectId} ${outputBqUri}` - ); - - assert.match(response, new RegExp('/batchPredictionJobs/')); - batchPredictionBqJobId = response - .split('/locations/us-central1/batchPredictionJobs/')[1] - .split('\n')[0]; - }).timeout(10000); -}); 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-classification.test.js b/ai-platform/snippets/test/create-batch-prediction-job-text-classification.test.js deleted file mode 100644 index ac285ad4c4..0000000000 --- a/ai-platform/snippets/test/create-batch-prediction-job-text-classification.test.js +++ /dev/null @@ -1,74 +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_text_classification_test${uuid()}`; -const modelId = '7827432074230366208'; -const gcsSourceUri = - 'gs://ucaip-samples-test-output/inputs/batch_predict_TCN/tcn_inputs.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 text classification', () => { - it('should create a text classification batch prediction job', async () => { - const stdout = execSync( - `node ./create-batch-prediction-job-text-classification.js ${batchPredictionDisplayName} ${modelId} ${gcsSourceUri} ${gcsDestinationOutputUriPrefix} ${project} ${location}` - ); - assert.match( - stdout, - /Create batch prediction job text classification 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-batch-prediction-job-text-entity-extraction.test.js b/ai-platform/snippets/test/create-batch-prediction-job-text-entity-extraction.test.js deleted file mode 100644 index bb630905bd..0000000000 --- a/ai-platform/snippets/test/create-batch-prediction-job-text-entity-extraction.test.js +++ /dev/null @@ -1,74 +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_text_entity_extraction_test${uuid()}`; -const modelId = '6305215400179138560'; -const gcsSourceUri = - 'gs://ucaip-samples-test-output/inputs/batch_predict_TEN/ten_inputs.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 text entity extraction', () => { - it('should create a text entity extraction batch prediction job', async () => { - const stdout = execSync( - `node ./create-batch-prediction-job-text-entity-extraction.js ${batchPredictionDisplayName} ${modelId} ${gcsSourceUri} ${gcsDestinationOutputUriPrefix} ${project} ${location}` - ); - assert.match( - stdout, - /Create batch prediction job text entity extraction 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-batch-prediction-job-text-sentiment-analysis.test.js b/ai-platform/snippets/test/create-batch-prediction-job-text-sentiment-analysis.test.js deleted file mode 100644 index c9d1832615..0000000000 --- a/ai-platform/snippets/test/create-batch-prediction-job-text-sentiment-analysis.test.js +++ /dev/null @@ -1,74 +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_text_sentiment_analysis_test${uuid()}`; -const modelId = '4792568875336073216'; -const gcsSourceUri = - 'gs://ucaip-samples-test-output/inputs/batch_predict_TSN/tsn_inputs.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 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}` - ); - assert.match( - stdout, - /Create batch prediction job text sentiment analysis 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-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-batch-prediction-job-video-classification.test.js b/ai-platform/snippets/test/create-batch-prediction-job-video-classification.test.js deleted file mode 100644 index 16f8ceaf24..0000000000 --- a/ai-platform/snippets/test/create-batch-prediction-job-video-classification.test.js +++ /dev/null @@ -1,83 +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 jobServiceClient = new aiplatform.v1.JobServiceClient(clientOptions); - -const batchPredictionDisplayName = `temp_create_batch_prediction_video_classification_test${uuid()}`; -const modelId = '8596984660557299712'; -const gcsSourceUri = - 'gs://ucaip-samples-test-output/inputs/vcn_40_batch_prediction_input.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 classification', () => { - it('should create a video classification batch prediction job', async () => { - const stdout = execSync( - `node ./create-batch-prediction-job-video-classification.js \ - ${batchPredictionDisplayName} \ - ${modelId} ${gcsSourceUri} \ - ${gcsDestinationOutputUriPrefix} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create batch prediction job video classification 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-batch-prediction-job-video-object-tracking.test.js b/ai-platform/snippets/test/create-batch-prediction-job-video-object-tracking.test.js deleted file mode 100644 index 5c3a18887e..0000000000 --- a/ai-platform/snippets/test/create-batch-prediction-job-video-object-tracking.test.js +++ /dev/null @@ -1,83 +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 jobServiceClient = new aiplatform.v1.JobServiceClient(clientOptions); - -const batchPredictionDisplayName = `temp_create_batch_prediction_video_object_tracking_test${uuid()}`; -const modelId = '8609932509485989888'; -const gcsSourceUri = - 'gs://ucaip-samples-test-output/inputs/vot_batch_prediction_input.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 object tracking', () => { - it('should create a video object tracking batch prediction job', async () => { - const stdout = execSync( - `node ./create-batch-prediction-job-video-object-tracking.js \ - ${batchPredictionDisplayName} \ - ${modelId} ${gcsSourceUri} \ - ${gcsDestinationOutputUriPrefix} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create batch prediction job video object tracking 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 deleted file mode 100644 index ac87d2e9bd..0000000000 --- a/ai-platform/snippets/test/create-custom-job.test.js +++ /dev/null @@ -1,77 +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 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; - -function parseResponse(stdout) { - let res = {}; - for (let i = 0; i < stdout.length; i++) { - if (stdout[i] === '{') { - res = JSON.parse(stdout.substr(i)); - break; - } - } - return res; -} - -let customJobId; - -describe('AI platform create custom job', async function () { - this.retries(2); - it('should create a new custom job', async () => { - const stdout = execSync( - `node ./create-custom-job.js ${customJobDisplayName} \ - ${containerImageUri} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create custom job response/); - customJobId = parseResponse(stdout).name.split('/').pop(); - }); - - after('should cancel the customJob and delete it', async () => { - execSync( - `node ./cancel-custom-job.js ${customJobId} ${project} \ - ${location}`, - { - cwd, - } - ); - execSync( - `node ./delete-custom-job.js ${customJobId} ${project} \ - ${location}`, - { - cwd, - } - ); - }); -}); diff --git a/ai-platform/snippets/test/create-dataset-image.test.js b/ai-platform/snippets/test/create-dataset-image.test.js deleted file mode 100644 index bd9ea481b7..0000000000 --- a/ai-platform/snippets/test/create-dataset-image.test.js +++ /dev/null @@ -1,54 +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 datasetDisplayName = `temp_create_dataset_image_test_${uuid()}`; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -let datasetId; - -describe('AI platform create dataset image', () => { - it('should create a new image dataset in the parent resource', async () => { - const stdout = execSync( - `node ./create-dataset-image.js ${datasetDisplayName} ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create dataset image response/); - datasetId = stdout - .split('/locations/us-central1/datasets/')[1] - .split('\n')[0] - .split('/')[0]; - }); - after('should delete the created dataset', async () => { - execSync(`node ./delete-dataset.js ${datasetId} ${project} ${location}`, { - cwd, - }); - }); -}); diff --git a/ai-platform/snippets/test/create-dataset-tabular-bigquery.test.js b/ai-platform/snippets/test/create-dataset-tabular-bigquery.test.js deleted file mode 100644 index 829da9dd43..0000000000 --- a/ai-platform/snippets/test/create-dataset-tabular-bigquery.test.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'; - -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 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; - -let datasetId; - -describe('AI platform create dataset tabular bigquery', () => { - it('should create a new bigquery tabular dataset in the parent resource', async () => { - const stdout = execSync( - `node ./create-dataset-tabular-bigquery.js ${datasetDisplayName} \ - ${bigquerySourceUri} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create dataset tabular bigquery response/); - datasetId = stdout - .split(`/locations/${location}/datasets/`)[1] - .split('/')[0] - .split('/')[0]; - }); - after('should delete created dataset', async () => { - execSync(`node ./delete-dataset.js ${datasetId} ${project} ${location}`, { - cwd, - }); - }); -}); diff --git a/ai-platform/snippets/test/create-dataset-tabular-gcs.test.js b/ai-platform/snippets/test/create-dataset-tabular-gcs.test.js deleted file mode 100644 index 08ab73a8c2..0000000000 --- a/ai-platform/snippets/test/create-dataset-tabular-gcs.test.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'; - -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 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; - -let datasetId; - -describe('AI platform create dataset tabular gcs', () => { - it('should create a new gcs tabular dataset in the parent resource', async () => { - const stdout = execSync( - `node ./create-dataset-tabular-gcs.js ${datasetDisplayName} \ - ${gcsSourceUri} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create dataset tabular gcs response/); - datasetId = stdout - .split('/locations/us-central1/datasets/')[1] - .split('/')[0] - .split('/')[0]; - }); - after('should delete created dataset', async () => { - execSync(`node ./delete-dataset.js ${datasetId} ${project} ${location}`, { - cwd, - }); - }); -}); diff --git a/ai-platform/snippets/test/create-dataset-text.test.js b/ai-platform/snippets/test/create-dataset-text.test.js deleted file mode 100644 index 43e84656cc..0000000000 --- a/ai-platform/snippets/test/create-dataset-text.test.js +++ /dev/null @@ -1,53 +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 displayName = `temp_create_dataset_text_test_${uuid()}`; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -let datasetId; - -describe('AI platform create dataset text', () => { - it('should create a new dataset in the parent resource', async () => { - const stdout = execSync( - `node ./create-dataset-text.js ${displayName} ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create dataset text response/); - datasetId = stdout - .split('/locations/us-central1/datasets/')[1] - .split('\n')[0] - .split('/')[0]; - }); - after('should delete the created dataset', async () => { - execSync(`node ./delete-dataset.js ${datasetId} ${project} ${location}`, { - cwd, - }); - }); -}); diff --git a/ai-platform/snippets/test/create-dataset-video.test.js b/ai-platform/snippets/test/create-dataset-video.test.js deleted file mode 100644 index cae62a2aff..0000000000 --- a/ai-platform/snippets/test/create-dataset-video.test.js +++ /dev/null @@ -1,54 +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 datasetDisplayName = `temp_create_dataset_video_test_${uuid()}`; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -let datasetId; - -describe('AI platform create dataset video', () => { - it('should create a new video dataset in the parent resource', async () => { - const stdout = execSync( - `node ./create-dataset-video.js ${datasetDisplayName} ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create dataset video response/); - datasetId = stdout - .split('/locations/us-central1/datasets/')[1] - .split('\n')[0] - .split('/')[0]; - }); - after('should delete the created dataset', async () => { - execSync(`node ./delete-dataset.js ${datasetId} ${project} ${location}`, { - cwd, - }); - }); -}); diff --git a/ai-platform/snippets/test/create-dataset.test.js b/ai-platform/snippets/test/create-dataset.test.js deleted file mode 100644 index 99075b54db..0000000000 --- a/ai-platform/snippets/test/create-dataset.test.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'; - -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 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; - -let datasetId; - -describe('AI platform create dataset', () => { - it('should create a new dataset in the parent resource', async () => { - const stdout = execSync( - `node ./create-dataset.js ${datasetDisplayName} ${metadataSchemaUri} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create dataset response/); - datasetId = stdout - .split('/locations/us-central1/datasets/')[1] - .split('\n')[0] - .split('/')[0]; - }); - after('should delete created dataset', async () => { - execSync(`node ./delete-dataset.js ${datasetId} ${project} ${location}`, { - cwd, - }); - }); -}); diff --git a/ai-platform/snippets/test/create-endpoint.test.js b/ai-platform/snippets/test/create-endpoint.test.js deleted file mode 100644 index b989d96a8a..0000000000 --- a/ai-platform/snippets/test/create-endpoint.test.js +++ /dev/null @@ -1,53 +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 endpointDisplayName = `temp_create_endpoint_test_${uuid()}`; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; -let endpointId; - -describe('AI platform create endpoint', () => { - it('should create a new endpoint', async () => { - const stdout = execSync( - `node ./create-endpoint.js ${endpointDisplayName} ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Create endpoint response/); - endpointId = stdout - .split('/locations/us-central1/endpoints/')[1] - .split('\n')[0] - .split('/')[0]; - }); - after('delete created endpoint', async () => { - execSync(`node ./delete-endpoint.js ${endpointId} ${project} ${location}`, { - cwd, - }); - }); -}); diff --git a/ai-platform/snippets/test/create-featurestore-fixed-nodes-sample.test.js b/ai-platform/snippets/test/create-featurestore-fixed-nodes-sample.test.js deleted file mode 100644 index 566a62fd17..0000000000 --- a/ai-platform/snippets/test/create-featurestore-fixed-nodes-sample.test.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2022 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 {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; -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 project = process.env.CAIP_PROJECT_ID; -const featurestoreId = `featurestore_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const fixedNodeCount = 1; -const location = 'us-central1'; -const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; - -// Instantiates a featurestore clients -const featurestoreServiceClient = new FeaturestoreServiceClient({ - apiEndpoint: apiEndpoint, -}); - -const deleteFeaturestore = async () => { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - name: name, - force: true, - }; - - // Delete Featurestore request - const [operation] = await featurestoreServiceClient.deleteFeaturestore( - request, - {timeout: 60000} - ); - await operation.promise(); -}; - -describe('AI platform create featurestore with fixed nodes', async function () { - this.retries(2); - it('should create a featurestore', async () => { - const stdout = execSync( - `node ./create-featurestore-fixed-nodes-sample.js ${project} ${featurestoreId} ${fixedNodeCount} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Create featurestore fixed nodes response/); - }); - after('should delete the created featurestore', async () => { - await deleteFeaturestore(); - }); -}); diff --git a/ai-platform/snippets/test/create-featurestore-sample.test.js b/ai-platform/snippets/test/create-featurestore-sample.test.js deleted file mode 100644 index cb66466c26..0000000000 --- a/ai-platform/snippets/test/create-featurestore-sample.test.js +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2022 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 {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; -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 project = process.env.CAIP_PROJECT_ID; -const featurestoreId = `featurestore_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const minNodeCount = 1; -const maxNodeCount = 5; -const location = 'us-central1'; -const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; - -// Instantiates a featurestore clients -const featurestoreServiceClient = new FeaturestoreServiceClient({ - apiEndpoint: apiEndpoint, -}); - -const deleteFeaturestore = async () => { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - name: name, - force: true, - }; - - // Delete Featurestore request - const [operation] = await featurestoreServiceClient.deleteFeaturestore( - request, - {timeout: 60000} - ); - await operation.promise(); -}; - -describe('AI platform create featurestore', async function () { - this.retries(2); - it('should create a featurestore', async () => { - const stdout = execSync( - `node ./create-featurestore-sample.js ${project} ${featurestoreId} ${minNodeCount} ${maxNodeCount} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Create featurestore response/); - }); - after('should delete the created featurestore', async () => { - await deleteFeaturestore(); - }); -}); diff --git a/ai-platform/snippets/test/create-hyperparameter-tuning-job.test.js b/ai-platform/snippets/test/create-hyperparameter-tuning-job.test.js deleted file mode 100644 index 5d37625504..0000000000 --- a/ai-platform/snippets/test/create-hyperparameter-tuning-job.test.js +++ /dev/null @@ -1,78 +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 containerImageUri = - 'gcr.io/ucaip-sample-tests/ucaip-training-test:latest'; -const displayName = `temp_create_hyperparameter_tuning_job_test${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let tuningJobId; - -describe('AI platform create hyperparameter tuning job', async function () { - this.retries(2); - it('should create a new hyperparameter tuning job', async () => { - const stdout = execSync( - `node ./create-hyperparameter-tuning-job.js ${displayName} ${containerImageUri} ${project} ${location}` - ); - assert.match( - stdout, - /\/locations\/us-central1\/hyperparameterTuningJobs\// - ); - tuningJobId = stdout - .split('/locations/us-central1/hyperparameterTuningJobs/')[1] - .split('\n')[0]; - }); - - after( - 'should cancel the hyperparameter tuning job and delete it', - async () => { - const name = jobServiceClient.hyperparameterTuningJobPath( - project, - location, - tuningJobId - ); - - const cancelRequest = { - name, - }; - - jobServiceClient.cancelHyperparameterTuningJob(cancelRequest).then(() => { - const deleteRequest = { - name, - }; - - return jobServiceClient.deleteHyperparameterTuningJob(deleteRequest); - }); - } - ); -}); diff --git a/ai-platform/snippets/test/create-training-pipeline-image-classification.test.js b/ai-platform/snippets/test/create-training-pipeline-image-classification.test.js deleted file mode 100644 index 29e66437d7..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-image-classification.test.js +++ /dev/null @@ -1,74 +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, 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 pipelineServiceClient = new aiplatform.v1.PipelineServiceClient( - clientOptions -); - -const datasetId = '1084241610289446912'; -const modelDisplayName = `temp_create_training_pipeline_image_classification_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_image_classification_test_${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('AI platform create training pipeline image classification', async function () { - this.retries(2); - it('should create a new image classification training pipeline', async () => { - const stdout = execSync( - `node ./create-training-pipeline-image-classification.js ${datasetId} ${modelDisplayName} ${trainingPipelineDisplayName} ${project} ${location}` - ); - assert.match(stdout, /\/locations\/us-central1\/trainingPipelines\//); - 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-image-object-detection.test.js b/ai-platform/snippets/test/create-training-pipeline-image-object-detection.test.js deleted file mode 100644 index e94ff3230d..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-image-object-detection.test.js +++ /dev/null @@ -1,86 +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 = '3555732643297361920'; -const modelDisplayName = `temp_create_training_pipeline_image_object_detection_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_image_object_detection_test_${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('AI platform create training pipeline image object detection', async function () { - this.retries(2); - it('should create a new image object detection training pipeline', async () => { - const stdout = execSync( - `node ./create-training-pipeline-image-object-detection.js \ - ${datasetId} \ - ${modelDisplayName} \ - ${trainingPipelineDisplayName} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create training pipeline image object detection 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-tabular-classification.test.js b/ai-platform/snippets/test/create-training-pipeline-tabular-classification.test.js deleted file mode 100644 index 2409e343a7..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-tabular-classification.test.js +++ /dev/null @@ -1,88 +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 = '2438839935709478912'; -const modelDisplayName = `temp_create_training_pipeline_tables_classification_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_tables_classification_test_${uuid()}`; -const targetColumn = 'species'; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('AI platform create training pipeline tables classification', async function () { - this.retries(2); - it('should create a new tables classification training pipeline', async () => { - const stdout = execSync( - `node ./create-training-pipeline-tabular-classification.js \ - ${datasetId} \ - ${modelDisplayName} \ - ${trainingPipelineDisplayName} \ - ${targetColumn} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create training pipeline tabular 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-tabular-regression.test.js b/ai-platform/snippets/test/create-training-pipeline-tabular-regression.test.js deleted file mode 100644 index 4ded88a2ee..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-tabular-regression.test.js +++ /dev/null @@ -1,88 +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 = '3019804287640272896'; -const modelDisplayName = `temp_create_training_pipeline_tables_regression_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_tables_regression_test_${uuid()}`; -const targetColumn = 'FLOAT_5000unique_REQUIRED'; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('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( - `node ./create-training-pipeline-tabular-regression.js \ - ${datasetId} \ - ${modelDisplayName} \ - ${trainingPipelineDisplayName} \ - ${targetColumn} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create training pipeline tabular regression 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-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 deleted file mode 100644 index 01080bb0d4..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-text-entity-extraction.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 = '6203215905493614592'; -const modelDisplayName = `temp_create_training_pipeline_entity_extraction_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_entity_extraction_test_${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('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( - `node ./create-training-pipeline-text-entity-extraction.js \ - ${datasetId} \ - ${modelDisplayName} \ - ${trainingPipelineDisplayName} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create training pipeline text entity extraction 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-sentiment-analysis.test.js b/ai-platform/snippets/test/create-training-pipeline-text-sentiment-analysis.test.js deleted file mode 100644 index e8492fa19c..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-text-sentiment-analysis.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 = '5148529167758786560'; -const modelDisplayName = `temp_create_training_pipeline_sentiment_analysis_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_sentiment_analysis_test_${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('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( - `node ./create-training-pipeline-text-sentiment-analysis.js \ - ${datasetId} \ - ${modelDisplayName} \ - ${trainingPipelineDisplayName} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create training pipeline text sentiment analysis 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-video-action-recognition.test.js b/ai-platform/snippets/test/create-training-pipeline-video-action-recognition.test.js deleted file mode 100644 index 33d5f472ac..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-video-action-recognition.test.js +++ /dev/null @@ -1,77 +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, 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 pipelineServiceClient = new aiplatform.v1.PipelineServiceClient( - clientOptions -); - -const datasetId = '6881957627459272704'; -const modelDisplayName = `temp_create_training_pipeline_node_var_model_test_${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_node_var_test_${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('AI platform create training pipeline video action recognition', async function () { - this.retries(2); - it('should create a new video action-recognition training pipeline', async () => { - const stdout = execSync( - `node ./create-training-pipeline-video-action-recognition.js ${datasetId} ${modelDisplayName} ${trainingPipelineDisplayName} ${project} ${location}` - ); - assert.match( - stdout, - /Create training pipeline video action recognition 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-video-classification.test.js b/ai-platform/snippets/test/create-training-pipeline-video-classification.test.js deleted file mode 100644 index 5a818b6f17..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-video-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 = '3757409464110546944'; -const modelDisplayName = `temp_create_training_pipeline_video_classification_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_video_classification_test_${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('AI platform create training pipeline video classification', async function () { - this.retries(2); - it('should create a new video classification training pipeline', async () => { - const stdout = execSync( - `node ./create-training-pipeline-video-classification.js ${datasetId} \ - ${modelDisplayName} \ - ${trainingPipelineDisplayName} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create training pipeline video 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-video-object-tracking.test.js b/ai-platform/snippets/test/create-training-pipeline-video-object-tracking.test.js deleted file mode 100644 index b6a893360f..0000000000 --- a/ai-platform/snippets/test/create-training-pipeline-video-object-tracking.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 = '1138566280794603520'; -const modelDisplayName = `temp_create_training_pipeline_video_object_tracking_model_test${uuid()}`; -const trainingPipelineDisplayName = `temp_create_training_pipeline_video_object_tracking_test_${uuid()}`; -const location = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -let trainingPipelineId; - -describe('AI platform create training pipeline object tracking', async function () { - this.retries(2); - it('should create a new object tracking training pipeline', async () => { - const stdout = execSync( - `node ./create-training-pipeline-video-object-tracking.js \ - ${datasetId} ${modelDisplayName} \ - ${trainingPipelineDisplayName} \ - ${project} ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Create training pipeline video object tracking 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/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 deleted file mode 100644 index dcd84b9184..0000000000 --- a/ai-platform/snippets/test/deploy-model.test.js +++ /dev/null @@ -1,63 +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, 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 = '4190810559500779520'; -const deployedModelDisplayName = `temp_deploy_model_test_${uuid()}`; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; -let deployedModelId; -let endpointId; - -describe('AI platform deploy model', () => { - it('should deploy the 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.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 model', async () => { - // If test failed, the attempt to undeploy will fail too. - // Check to see whether we have a deployedModelId - if (deployedModelId === undefined) { - return; - } - - execSync(`node ./undeploy-model.js ${deployedModelId} ${endpointId} ${project} \ - ${location}`); - execSync(`node ./delete-endpoint.js ${endpointId} ${project} ${location}`); - }); -}); diff --git a/ai-platform/snippets/test/embedding-model-tuning.test.js b/ai-platform/snippets/test/embedding-model-tuning.test.js deleted file mode 100644 index 5c3a30e713..0000000000 --- a/ai-platform/snippets/test/embedding-model-tuning.test.js +++ /dev/null @@ -1,49 +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 path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const aiplatform = require('@google-cloud/aiplatform'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const cwd = path.join(__dirname, '..'); - -const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; -const project = process.env.CAIP_PROJECT_ID; -const outputDir = 'gs://ucaip-samples-us-central1/training_pipeline_output'; -const job_names = [null]; - -describe('AI platform tune text-embedding models', () => { - it('should make tuned-text embedding models', async () => { - const stdout = execSync( - `node ./embedding-model-tuning.js ${apiEndpoint} ${project} ${outputDir}`, - {cwd} - ); - const match = stdout.match(/job_name: (?\S+).+job_state: (?\S+)/s); - assert.isNotNull(match); - assert.notEqual(match.groups.S, 'PIPELINE_STATE_FAILED'); - job_names[0] = match.groups.N; - }); -}); -after(async () => { - const pipelineClient = new aiplatform.v1.PipelineServiceClient({apiEndpoint}); - pipelineClient.cancelPipelineJob({name: job_names[0]}).then(() => { - return pipelineClient.deletePipelineJob({name: job_names[0]}); - }); -}); diff --git a/ai-platform/snippets/test/entity-type-samples.test.js b/ai-platform/snippets/test/entity-type-samples.test.js deleted file mode 100644 index 50b7dc90c8..0000000000 --- a/ai-platform/snippets/test/entity-type-samples.test.js +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2022 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 {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; -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 project = process.env.CAIP_PROJECT_ID; -const featurestoreId = `featurestore_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const fixedNodeCount = 1; -const entityTypeId1 = `entity_type_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const entityTypeId2 = `entity_type_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const entityType1Description = - 'created during the entity type 1 sample testing'; -const entityType2Description = - 'created during the entity type 2 sample testing'; -const duration = 86400; -const updatedDuration = 172800; -const location = 'us-central1'; -const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; - -// Instantiates a featurestore clients -const featurestoreServiceClient = new FeaturestoreServiceClient({ - apiEndpoint: apiEndpoint, -}); - -const deleteFeaturestore = async () => { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - name: name, - force: true, - }; - - // Delete Featurestore request - const [operation] = await featurestoreServiceClient.deleteFeaturestore( - request, - {timeout: 60000} - ); - await operation.promise(); -}; - -describe('AI platform entity type api samples test', async function () { - this.retries(2); - before('should create the featurestore', async () => { - execSync( - `node ./create-featurestore-fixed-nodes-sample.js ${project} ${featurestoreId} ${fixedNodeCount} ${location} ${apiEndpoint}` - ); - }); - it('should create the entity type', async () => { - const stdout = execSync( - `node ./create-entity-type-sample.js ${project} ${featurestoreId} ${entityTypeId1} "${entityType1Description}" ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Create entity type response/); - }); - it('should create the entity type with monitoring', async () => { - const stdout = execSync( - `node ./create-entity-type-monitoring-sample.js ${project} ${featurestoreId} ${entityTypeId2} "${entityType2Description}" ${duration} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Create entity type monitoring response/); - }); - it('should get the created entity type', async () => { - const stdout = execSync( - `node ./get-entity-type-sample.js ${project} ${featurestoreId} ${entityTypeId1} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Get entity type response/); - }); - it('should list the entity types', async () => { - const stdout = execSync( - `node ./list-entity-types-sample.js ${project} ${featurestoreId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List entity types response/); - }); - it('should list the entity types asynchronously', async () => { - const stdout = execSync( - `node ./list-entity-types-async-sample.js ${project} ${featurestoreId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List entity types async response/); - }); - it('should list the entity types in streaming', async () => { - const stdout = execSync( - `node ./list-entity-types-stream-sample.js ${project} ${featurestoreId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List entity types stream response/); - }); - it('should update the entity type', async () => { - const stdout = execSync( - `node ./update-entity-type-sample.js ${project} ${featurestoreId} ${entityTypeId1} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Update entity type response/); - }); - it('should update the entity type monitoring', async () => { - const stdout = execSync( - `node ./update-entity-type-monitoring-sample.js ${project} ${featurestoreId} ${entityTypeId2} ${updatedDuration} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Update entity type monitoring response/); - }); - it('should delete the created entity type', async () => { - const stdout = execSync( - `node ./delete-entity-type-sample.js ${project} ${featurestoreId} ${entityTypeId1} true ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Delete entity type response/); - }); - after('should delete the created featurestore', async () => { - await deleteFeaturestore(); - }); -}); diff --git a/ai-platform/snippets/test/export-model-tabular-classification.test.js b/ai-platform/snippets/test/export-model-tabular-classification.test.js deleted file mode 100644 index c929b4d2d6..0000000000 --- a/ai-platform/snippets/test/export-model-tabular-classification.test.js +++ /dev/null @@ -1,46 +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 gcsDestinationOutputUriPrefix = 'gs://ucaip-samples-test-output'; -const modelId = '6036688272397172736'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform export data tabular classification', () => { - it('should export model', async () => { - const stdout = execSync( - `node ./export-model-tabular-classification.js \ - ${gcsDestinationOutputUriPrefix} \ - ${modelId} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Export model response/); - }); -}); diff --git a/ai-platform/snippets/test/feature-samples.test.js b/ai-platform/snippets/test/feature-samples.test.js deleted file mode 100644 index b2de671b8f..0000000000 --- a/ai-platform/snippets/test/feature-samples.test.js +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2022 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 {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; -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 project = process.env.CAIP_PROJECT_ID; -const featurestoreId = `featurestore_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const fixedNodeCount = 1; -const entityTypeId = `entity_type_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const entityTypeDescription = 'created during create feature sample testing'; -const featureId = `feature_sample_${uuid().replace(/-/g, '_').slice(10, 20)}`; -const featureDescription = 'created during create feature sample testing'; -const valueType = 'STRING'; -const query = 'valueType=STRING'; -const location = 'us-central1'; -const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; - -// Instantiates a featurestore clients -const featurestoreServiceClient = new FeaturestoreServiceClient({ - apiEndpoint: apiEndpoint, -}); - -const createFeaturestore = async () => { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}`; - - const featurestore = { - onlineServingConfig: { - fixedNodeCount: fixedNodeCount, - }, - }; - - const request = { - parent: parent, - featurestore: featurestore, - featurestoreId: featurestoreId, - }; - - // Create Featurestore request - const [operation] = await featurestoreServiceClient.createFeaturestore( - request, - {timeout: 900000} - ); - await operation.promise(); -}; - -const deleteFeaturestore = async () => { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - name: name, - force: true, - }; - - // Delete Featurestore request - const [operation] = await featurestoreServiceClient.deleteFeaturestore( - request, - {timeout: 60000} - ); - await operation.promise(); -}; - -const createEntityType = async () => { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const entityType = { - description: entityTypeDescription, - }; - - const request = { - parent: parent, - entityTypeId: entityTypeId, - entityType: entityType, - }; - - // CreateEntityType request - const [operation] = await featurestoreServiceClient.createEntityType( - request, - {timeout: 300000} - ); - await operation.promise(); -}; - -describe('AI platform feature api samples', async function () { - this.retries(2); - before('should create the featurestore', async () => { - await createFeaturestore(); - }); - before('should create the entity type', async () => { - await createEntityType(); - }); - it('should create feature', async () => { - const stdout = execSync( - `node ./create-feature-sample.js ${project} ${featurestoreId} ${entityTypeId} ${featureId} ${valueType} "${featureDescription}" ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Create feature response/); - }); - it('should batch create features', async () => { - const stdout = execSync( - `node ./batch-create-features-sample.js ${project} ${featurestoreId} ${entityTypeId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Batch create features response/); - }); - it('should get the created feature', async () => { - const stdout = execSync( - `node ./get-feature-sample.js ${project} ${featurestoreId} ${entityTypeId} ${featureId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Get feature response/); - }); - it('should list all the features', async () => { - const stdout = execSync( - `node ./list-features-sample.js ${project} ${featurestoreId} ${entityTypeId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List features response/); - }); - it('should list all the features asynchronously', async () => { - const stdout = execSync( - `node ./list-features-async-sample.js ${project} ${featurestoreId} ${entityTypeId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List features async response/); - }); - it('should list all the features in streaming', async () => { - const stdout = execSync( - `node ./list-features-stream-sample.js ${project} ${featurestoreId} ${entityTypeId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List features stream response/); - }); - it('should search features', async () => { - const stdout = execSync( - `node ./search-features-sample.js ${project} "${query}" ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Search features response/); - }); - it('should search features asynchronously', async () => { - const stdout = execSync( - `node ./search-features-async-sample.js ${project} "${query}" ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Search features async response/); - }); - it('should search features in streaming', async () => { - const stdout = execSync( - `node ./search-features-stream-sample.js ${project} "${query}" ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Search features stream response/); - }); - it('should update the feature', async () => { - const stdout = execSync( - `node ./update-feature-sample.js ${project} ${featurestoreId} ${entityTypeId} ${featureId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Update feature response/); - }); - it('should delete the created feature', async () => { - const stdout = execSync( - `node ./delete-feature-sample.js ${project} ${featurestoreId} ${entityTypeId} ${featureId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Delete feature response/); - }); - after('should delete the created featurestore', async () => { - await deleteFeaturestore(); - }); -}); diff --git a/ai-platform/snippets/test/feature-values-samples.test.js b/ai-platform/snippets/test/feature-values-samples.test.js deleted file mode 100644 index 17ce0946f7..0000000000 --- a/ai-platform/snippets/test/feature-values-samples.test.js +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright 2022 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 {BigQuery} = require('@google-cloud/bigquery'); -const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; -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 project = process.env.CAIP_PROJECT_ID; -const datasetName = `movie_predictions_nodejs_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const batchReadTableName = 'batch_serving_table'; -const exportTableName = 'export_table'; -const exportSnapshotTableName = 'export_snapshot_table'; - -const featurestoreId = `featurestore_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const fixedNodeCount = 1; - -const entityTypeId1 = 'perm_users'; -const entityTypeDescription1 = 'Users Entity'; -const entityTypeId2 = 'perm_movies'; -const entityTypeDescription2 = 'Movies Entity'; -const entityId = 'alice'; - -const avroGcsUri1 = - 'gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/users.avro'; -const entityIdField1 = 'user_id'; - -const avroGcsUri2 = - 'gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/movies.avro'; -const entityIdField2 = 'movie_id'; - -const featureTimeField = 'update_time'; -const workerCount = 2; -const batchReadDestinationTableUri = `bq://${project}.${datasetName}.${batchReadTableName}`; -const inputCsvFile = - 'gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/movie_prediction_perm.csv'; - -const timestamp = 1629493102; -const exportDestinationTableUri = `bq://${project}.${datasetName}.${exportTableName}`; -const exportSnapshotDestinationTableUri = `bq://${project}.${datasetName}.${exportSnapshotTableName}`; - -const location = 'us-central1'; -const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; - -// Instantiates a featurestore and bigquery clients -const featurestoreServiceClient = new FeaturestoreServiceClient({ - apiEndpoint: apiEndpoint, -}); -const bigqueryClient = new BigQuery({projectId: project}); - -const createEntityType = async (entityTypeId, entityTypeDescription) => { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const entityType = { - description: entityTypeDescription, - }; - - const request = { - parent: parent, - entityTypeId: entityTypeId, - entityType: entityType, - }; - - // CreateEntityType request - const [operation] = await featurestoreServiceClient.createEntityType( - request, - {timeout: 300000} - ); - await operation.promise(); -}; - -const createPermUsersFeatures = async () => { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId1}`; - - const ageFeature = { - valueType: 'INT64', - description: 'User age', - }; - - const ageFeatureRequest = { - feature: ageFeature, - featureId: 'age', - }; - - const genderFeature = { - valueType: 'STRING', - description: 'User gender', - }; - - const genderFeatureRequest = { - feature: genderFeature, - featureId: 'gender', - }; - - const likedGenresFeature = { - valueType: 'STRING_ARRAY', - description: 'An array of genres that this user liked', - }; - - const likedGenresFeatureRequest = { - feature: likedGenresFeature, - featureId: 'liked_genres', - }; - - const requests = [ - ageFeatureRequest, - genderFeatureRequest, - likedGenresFeatureRequest, - ]; - - const request = { - parent: parent, - requests: requests, - }; - - // Batch Create Features request - const [operation] = await featurestoreServiceClient.batchCreateFeatures( - request, - {timeout: 300000} - ); - await operation.promise(); -}; - -const createPermMoviesFeatures = async () => { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId2}`; - - const titleFeatureRequest = { - feature: { - valueType: 'STRING', - description: 'The title of the movie', - }, - featureId: 'title', - }; - - const genresFeatureRequest = { - feature: { - valueType: 'STRING', - description: 'The genres of the movie', - }, - featureId: 'genres', - }; - - const averageRatingFeatureRequest = { - feature: { - valueType: 'DOUBLE', - description: 'The average rating for the movie, range is [1.0-5.0]', - }, - featureId: 'average_rating', - }; - - const requests = [ - titleFeatureRequest, - genresFeatureRequest, - averageRatingFeatureRequest, - ]; - - const request = { - parent: parent, - requests: requests, - }; - - // Batch Create Features request - const [operation] = await featurestoreServiceClient.batchCreateFeatures( - request, - {timeout: 300000} - ); - await operation.promise(); -}; - -const importPermMoviesFeatures = async () => { - // Configure the entityType resource - const entityType = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId2}`; - - const avroSource = { - gcsSource: { - uris: [avroGcsUri2], - }, - }; - - const featureSpecs = [{id: 'title'}, {id: 'genres'}, {id: 'average_rating'}]; - - const request = { - entityType: entityType, - avroSource: avroSource, - entityIdField: entityIdField2, - featureSpecs: featureSpecs, - featureTimeField: featureTimeField, - workerCount: workerCount, - }; - - // Import Feature Values Request - const [operation] = await featurestoreServiceClient.importFeatureValues( - request, - {timeout: 300000} - ); - await operation.promise(); -}; - -const deleteFeaturestore = async () => { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const request = { - name: name, - force: true, - }; - - // Delete Featurestore request - const [operation] = await featurestoreServiceClient.deleteFeaturestore( - request, - {timeout: 60000} - ); - await operation.promise(); -}; - -describe('AI platform feature values apis', async function () { - this.retries(2); - before('should create the BigQuery Dataset', async () => { - await bigqueryClient.createDataset(datasetName, location); - }); - before('should create the featurestore', async () => { - execSync( - `node ./create-featurestore-fixed-nodes-sample.js ${project} ${featurestoreId} ${fixedNodeCount} ${location} ${apiEndpoint}` - ); - }); - before('should create the perm_users entity type', async () => { - await createEntityType(entityTypeId1, entityTypeDescription1); - }); - before('should create the perm_movies entity type', async () => { - await createEntityType(entityTypeId2, entityTypeDescription2); - }); - before('should create the perm_movies batch features', async () => { - await createPermMoviesFeatures(); - }); - before('should create the perm_users batch features', async () => { - await createPermUsersFeatures(); - }); - before('should import perm_movies feature values', async () => { - await importPermMoviesFeatures(); - }); - it('should import feature values', async () => { - const stdout = execSync( - `node ./import-feature-values-sample.js ${project} ${featurestoreId} ${entityTypeId1} "${avroGcsUri1}" ${entityIdField1} ${featureTimeField} ${workerCount} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Import feature values response/); - }); - it('should batch read feature values', async () => { - const stdout = execSync( - `node ./batch-read-feature-values-sample.js ${project} ${featurestoreId} ${inputCsvFile} "${batchReadDestinationTableUri}" ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Batch read feature values response/); - }); - it('should read feature values', async () => { - const stdout = execSync( - `node ./read-feature-values-sample.js ${project} ${featurestoreId} ${entityTypeId1} ${entityId} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Read feature values response/); - }); - it('should export feature values', async () => { - const stdout = execSync( - `node ./export-feature-values-sample.js ${project} ${featurestoreId} ${entityTypeId1} "${exportDestinationTableUri}" ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Export feature values response/); - }); - it('should export feature values using snapshot', async () => { - const stdout = execSync( - `node ./export-feature-values-snapshot-sample.js ${project} ${featurestoreId} ${entityTypeId1} "${exportSnapshotDestinationTableUri}" ${timestamp} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Export feature values snapshot response/); - }); - after('should delete the created featurestore', async () => { - await deleteFeaturestore(); - }); - - after('should delete the created dataset', async () => { - // Create a reference to the existing dataset - const dataset = bigqueryClient.dataset(datasetName); - // Delete the dataset and its contents - await dataset.delete({force: true}); - }); -}); diff --git a/ai-platform/snippets/test/featurestore-samples.test.js b/ai-platform/snippets/test/featurestore-samples.test.js deleted file mode 100644 index c759ba53d5..0000000000 --- a/ai-platform/snippets/test/featurestore-samples.test.js +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2022 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 project = process.env.CAIP_PROJECT_ID; -const featurestoreId1 = `featurestore_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; -const featurestoreId2 = `featurestore_sample_${uuid() - .replace(/-/g, '_') - .slice(10, 20)}`; - -const fixedNodeCount = 1; -const updatedFixedNodeCount = 3; -const minNodeCount = 1; -const maxNodeCount = 3; -const updatedMinNodeCount = 2; -const updatedMaxNodeCount = 4; -const location = 'us-central1'; -const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; - -describe('AI platform featurestore api samples test', async function () { - this.retries(2); - before('should create a featurestore with fixed nodes', async () => { - execSync( - `node ./create-featurestore-fixed-nodes-sample.js ${project} ${featurestoreId1} ${fixedNodeCount} ${location} ${apiEndpoint}` - ); - }); - before('should create a featurestore with autoscaling', async () => { - execSync( - `node ./create-featurestore-sample.js ${project} ${featurestoreId2} ${minNodeCount} ${maxNodeCount} ${location} ${apiEndpoint}` - ); - }); - it('should get the featurestore', async () => { - const stdout = execSync( - `node ./get-featurestore-sample.js ${project} ${featurestoreId1} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Get featurestore response/); - }); - it('should list the featurestores', async () => { - const stdout = execSync( - `node ./list-featurestores-sample.js ${project} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List featurestores response/); - }); - it('should list the featurestores asynchronously', async () => { - const stdout = execSync( - `node ./list-featurestores-async-sample.js ${project} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List featurestores async response/); - }); - it('should list the featurestores in streaming', async () => { - const stdout = execSync( - `node ./list-featurestores-stream-sample.js ${project} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /List featurestores stream response/); - }); - it('should update featurestores fixed nodes', async () => { - const stdout = execSync( - `node ./update-featurestore-fixed-nodes-sample.js ${project} ${featurestoreId1} ${updatedFixedNodeCount} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Update featurestore fixed nodes response/); - }); - it('should update featurestore autoscaling', async () => { - const stdout = execSync( - `node ./update-featurestore-sample.js ${project} ${featurestoreId2} ${updatedMinNodeCount} ${updatedMaxNodeCount} ${location} ${apiEndpoint}` - ); - assert.match(stdout, /Update featurestore response/); - }); - it('should delete the created featurestore', async () => { - const stdout = execSync( - `node ./delete-featurestore-sample.js ${project} ${featurestoreId1} true ${location}` - ); - assert.match(stdout, /Delete featurestore response/); - }); - after('should delete the created featurestore 2', async () => { - execSync( - `node ./delete-featurestore-sample.js ${project} ${featurestoreId2} true ${location}` - ); - }); -}); diff --git a/ai-platform/snippets/test/gemma2Prediction.test.js b/ai-platform/snippets/test/gemma2Prediction.test.js deleted file mode 100644 index c761315a2c..0000000000 --- a/ai-platform/snippets/test/gemma2Prediction.test.js +++ /dev/null @@ -1,135 +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 {expect} = require('chai'); -const {afterEach, describe, it} = require('mocha'); -const sinon = require('sinon'); -const gemma2PredictGpu = require('../gemma2PredictGpu.js'); -const gemma2PredictTpu = require('../gemma2PredictTpu.js'); - -const gpuResponse = `The sky appears blue due to a phenomenon called **Rayleigh scattering**. -**Here's how it works:** -1. **Sunlight:** Sunlight is composed of all the colors of the rainbow. -2. **Earth's Atmosphere:** When sunlight enters the Earth's atmosphere, it collides with tiny particles like nitrogen and oxygen molecules. -3. **Scattering:** These particles scatter the sunlight in all directions. However, blue light (which has a shorter wavelength) is scattered more effectively than other colors. -4. **Our Perception:** As a result, we see a blue sky because the scattered blue light reaches our eyes from all directions. -**Why not other colors?** -* **Violet light** has an even shorter wavelength than blue and is scattered even more. However, our eyes are less sensitive to violet light, so we perceive the sky as blue. -* **Longer wavelengths** like red, orange, and yellow are scattered less and travel more directly through the atmosphere. This is why we see these colors during sunrise and sunset, when sunlight has to travel through more of the atmosphere. -`; - -const tpuResponse = - 'The sky appears blue due to a phenomenon called **Rayleigh scattering**.'; - -describe('Gemma2 predictions', async () => { - const gemma2Endpoint = - 'projects/your-project-id/locations/your-vertex-endpoint-region/endpoints/your-vertex-endpoint-id'; - const configValues = { - maxOutputTokens: {kind: 'numberValue', numberValue: 1024}, - temperature: {kind: 'numberValue', numberValue: 0.9}, - topP: {kind: 'numberValue', numberValue: 1}, - topK: {kind: 'numberValue', numberValue: 1}, - }; - const prompt = 'Why is the sky blue?'; - const predictionServiceClientMock = { - predict: sinon.stub().resolves([]), - }; - - afterEach(() => { - sinon.reset(); - }); - - it('should run inference with GPU', async () => { - const expectedGpuRequest = { - endpoint: gemma2Endpoint, - instances: [ - { - kind: 'structValue', - structValue: { - fields: { - inputs: { - kind: 'stringValue', - stringValue: prompt, - }, - parameters: { - kind: 'structValue', - structValue: { - fields: configValues, - }, - }, - }, - }, - }, - ], - }; - - predictionServiceClientMock.predict.resolves([ - { - predictions: [ - { - stringValue: gpuResponse, - }, - ], - }, - ]); - - const output = await gemma2PredictGpu(predictionServiceClientMock); - - expect(output).include('Rayleigh scattering'); - expect(predictionServiceClientMock.predict.calledOnce).to.be.true; - expect(predictionServiceClientMock.predict.calledWith(expectedGpuRequest)) - .to.be.true; - }); - - it('should run inference with TPU', async () => { - const expectedTpuRequest = { - endpoint: gemma2Endpoint, - instances: [ - { - kind: 'structValue', - structValue: { - fields: { - ...configValues, - prompt: { - kind: 'stringValue', - stringValue: prompt, - }, - }, - }, - }, - ], - }; - - predictionServiceClientMock.predict.resolves([ - { - predictions: [ - { - stringValue: tpuResponse, - }, - ], - }, - ]); - - const output = await gemma2PredictTpu(predictionServiceClientMock); - - expect(output).include('Rayleigh scattering'); - expect(predictionServiceClientMock.predict.calledOnce).to.be.true; - expect(predictionServiceClientMock.predict.calledWith(expectedTpuRequest)) - .to.be.true; - }); -}); diff --git a/ai-platform/snippets/test/get-custom-job.test.js b/ai-platform/snippets/test/get-custom-job.test.js deleted file mode 100644 index f51fa2f9a2..0000000000 --- a/ai-platform/snippets/test/get-custom-job.test.js +++ /dev/null @@ -1,41 +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 customJobId = '7980906305281851392'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get custom job', () => { - it('should get the specified custom job', async () => { - const stdout = execSync( - `node ./get-custom-job.js ${customJobId} ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get custom job response/); - }); -}); diff --git a/ai-platform/snippets/test/get-hyperparameter-tuning-job.test.js b/ai-platform/snippets/test/get-hyperparameter-tuning-job.test.js deleted file mode 100644 index a334a8e02c..0000000000 --- a/ai-platform/snippets/test/get-hyperparameter-tuning-job.test.js +++ /dev/null @@ -1,36 +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 {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const tuningJobId = '2216298782247616512'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get hyperparameter tuning job', () => { - it('should get the specified hyperparameter tuning job', async () => { - const stdout = execSync( - `node ./get-hyperparameter-tuning-job.js ${tuningJobId} ${project} ${location}` - ); - assert.match(stdout, /Get hyperparameter tuning job response/); - }); -}); diff --git a/ai-platform/snippets/test/get-model-evaluation-slice.test.js b/ai-platform/snippets/test/get-model-evaluation-slice.test.js deleted file mode 100644 index 85033539c3..0000000000 --- a/ai-platform/snippets/test/get-model-evaluation-slice.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 modelId = '3512561418744365056'; -const evaluationId = '9035588644970168320'; -const sliceId = '6481571820677004173'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get model evaluation slice', () => { - it('should get the evaluation slice from the specified model', async () => { - const stdout = execSync( - `node ./get-model-evaluation-slice.js ${modelId} ${evaluationId} \ - ${sliceId} ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get model evaluation slice/); - }); -}); 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 deleted file mode 100644 index b4ea49e905..0000000000 --- a/ai-platform/snippets/test/get-model-evaluation-tabular-classification.test.js +++ /dev/null @@ -1,48 +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 modelId = '6036688272397172736'; -const evaluationId = '1866113044163962838'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get tabular classification model evaluation', () => { - it('should get the evaluation from the specified model', async () => { - const stdout = execSync( - `node ./get-model-evaluation-tabular-classification.js ${modelId} \ - ${evaluationId} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match( - stdout, - /Get model evaluation tabular classification response/ - ); - }); -}); 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 deleted file mode 100644 index 8bed83613c..0000000000 --- a/ai-platform/snippets/test/get-model-evaluation-tabular-regression.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 modelId = '8842430840248991744'; -const evaluationId = '4944816689650806017'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get tabular regression model evaluation', () => { - it('should get the evaluation from the specified model', async () => { - const stdout = execSync( - `node ./get-model-evaluation-tabular-regression.js ${modelId} \ - ${evaluationId} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get model evaluation tabular regression response/); - }); -}); 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 deleted file mode 100644 index e2c6699595..0000000000 --- a/ai-platform/snippets/test/get-model-evaluation-video-action-recognition.test.js +++ /dev/null @@ -1,43 +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 {describe, it} = require('mocha'); - -const cp = require('child_process'); -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; - -describe('AI platform get video action recognition model evaluation', () => { - it('should get the evaluation from the specified model', async () => { - const stdout = execSync( - `node ./get-model-evaluation-video-action-recognition.js ${modelId} \ - ${evaluationId} \ - ${project} \ - ${location}` - ); - assert.match( - stdout, - /Get model evaluation video action recognition response/ - ); - }); -}); 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 deleted file mode 100644 index 8f0cc4f1ed..0000000000 --- a/ai-platform/snippets/test/get-model-evaluation-video-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 modelId = '8596984660557299712'; -const evaluationId = '7092045712224944128'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get video classification model evaluation', () => { - it('should get the evaluation from the specified model', async () => { - const stdout = execSync( - `node ./get-model-evaluation-video-classification.js ${modelId} \ - ${evaluationId} \ - ${project} \ - ${location} `, - { - cwd, - } - ); - assert.match(stdout, /Get model evaluation video classification response/); - }); -}); 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 deleted file mode 100644 index 01e3cdedb9..0000000000 --- a/ai-platform/snippets/test/get-model-evaluation-video-object-tracking.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 modelId = '8609932509485989888'; -const evaluationId = '6016811301190238208'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get video object tracking model evaluation', () => { - it('should get the evaluation from the specified model', async () => { - const stdout = execSync( - `node ./get-model-evaluation-video-object-tracking.js ${modelId} \ - ${evaluationId} \ - ${project} \ - ${location} `, - { - cwd, - } - ); - assert.match(stdout, /Get model evaluation video object tracking response/); - }); -}); diff --git a/ai-platform/snippets/test/get-model.test.js b/ai-platform/snippets/test/get-model.test.js deleted file mode 100644 index f2fd901df8..0000000000 --- a/ai-platform/snippets/test/get-model.test.js +++ /dev/null @@ -1,41 +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 modelId = '3512561418744365056'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get model', () => { - it('should get the specified model', async () => { - const stdout = execSync( - `node ./get-model.js ${modelId} ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Get model response/); - }); -}); diff --git a/ai-platform/snippets/test/get-training-pipeline.test.js b/ai-platform/snippets/test/get-training-pipeline.test.js deleted file mode 100644 index b7455d90c1..0000000000 --- a/ai-platform/snippets/test/get-training-pipeline.test.js +++ /dev/null @@ -1,36 +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 {describe, it} = require('mocha'); - -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const trainingPipelineId = '1419759782528548864'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform get training pipeline', () => { - it('should get the specified training pipeline', async () => { - const stdout = execSync( - `node ./get-training-pipeline.js ${trainingPipelineId} ${project} ${location}` - ); - assert.match(stdout, /Get training pipeline response/); - }); -}); diff --git a/ai-platform/snippets/test/imagen.test.js b/ai-platform/snippets/test/imagen.test.js deleted file mode 100644 index 7b9f4a1250..0000000000 --- a/ai-platform/snippets/test/imagen.test.js +++ /dev/null @@ -1,88 +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 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 generate and edit an image using Imagen and check for a watermark', () => { - it('should generate an image', async () => { - const stdout = execSync('node ./imagen-generate-image.js', { - cwd, - }); - assert.match(stdout, /Saved image output1.png/); - }); - it('should edit an image without using a mask', async () => { - const stdout = execSync('node ./imagen-edit-image-mask-free.js', { - cwd, - }); - assert.match(stdout, /Saved image output1.png/); - }); - it('should verify that an image contains a watermark', async () => { - const stdout = execSync('node ./imagen-verify-image-watermark.js', { - cwd, - }); - assert.match(stdout, /ACCEPT/); - }); -}); - -describe('AI platform edit image using Imagen inpainting and outpainting', () => { - it('should edit an image using a mask image and inpainting insert', async () => { - const stdout = execSync( - 'node ./imagen-edit-image-inpainting-insert-mask.js', - { - cwd, - } - ); - assert.match(stdout, /Saved image output1.png/); - }); - it('should edit an image using a mask image and inpainting remove', async () => { - const stdout = execSync( - 'node ./imagen-edit-image-inpainting-remove-mask.js', - { - cwd, - } - ); - assert.match(stdout, /Saved image output1.png/); - }); - it('should edit an image using a mask image and outpainting', async () => { - const stdout = execSync('node ./imagen-edit-image-outpainting-mask.js', { - cwd, - }); - assert.match(stdout, /Saved image output1.png/); - }); -}); - -describe('AI platform get image captions and responses using Imagen', () => { - it('should get short form captions for an image', async () => { - const stdout = execSync('node ./imagen-get-short-form-image-captions.js', { - cwd, - }); - assert.match(stdout, /cat/); - }); - it('should get short form responses for an image', async () => { - const stdout = execSync('node ./imagen-get-short-form-image-responses.js', { - cwd, - }); - assert.match(stdout, /tabby/); - }); -}); 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 deleted file mode 100644 index 9c4334f130..0000000000 --- a/ai-platform/snippets/test/import-data-video-classification.test.js +++ /dev/null @@ -1,46 +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 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; - -describe('AI platform import data video classification', () => { - it('should import video classification data to dataset', async () => { - const stdout = execSync( - `node ./import-data-video-classification.js ${datasetId} \ - ${gcsSourceUri} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Import data video classification response/); - }); -}); diff --git a/ai-platform/snippets/test/list-endpoints.test.js b/ai-platform/snippets/test/list-endpoints.test.js deleted file mode 100644 index 7274916692..0000000000 --- a/ai-platform/snippets/test/list-endpoints.test.js +++ /dev/null @@ -1,37 +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 - * - * 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 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 LOCATION = 'us-central1'; -const project = process.env.CAIP_PROJECT_ID; - -describe('AI platform list endpoints', () => { - it('should list all endpoints in a parent resource', async () => { - const stdout = execSync(`node ./list-endpoints.js ${project} ${LOCATION}`, { - cwd, - }); - assert.match(stdout, /Endpoint/); - }); -}); diff --git a/ai-platform/snippets/test/list-model-evaluation-slices.test.js b/ai-platform/snippets/test/list-model-evaluation-slices.test.js deleted file mode 100644 index 10e0ad3af3..0000000000 --- a/ai-platform/snippets/test/list-model-evaluation-slices.test.js +++ /dev/null @@ -1,46 +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 modelId = '3512561418744365056'; -const evaluationId = '9035588644970168320'; -const project = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; - -describe('AI platform list model evaluation slices', () => { - it('should list all the evaluation slices from the \ - specified model', async () => { - const stdout = execSync( - `node ./list-model-evaluation-slices.js ${modelId} \ - ${evaluationId} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /List model evaluation response/); - }); -}); 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-image-and-text.test.js b/ai-platform/snippets/test/predict-image-from-image-and-text.test.js deleted file mode 100644 index ff1eeb2997..0000000000 --- a/ai-platform/snippets/test/predict-image-from-image-and-text.test.js +++ /dev/null @@ -1,55 +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 { - predictImageFromImageAndText, -} = require('../predict-image-from-image-and-text'); - -const project = process.env.CAIP_PROJECT_ID; -const LOCATION = 'us-central1'; -const baseImagePath = 'resources/daisy.jpg'; -const textPrompt = 'an impressionist painting'; - -describe('AI platform generates image from image and 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 predictImageFromImageAndText( - project, - LOCATION, - baseImagePath, - textPrompt - ); - assert.include(console.log.firstCall.args, 'Get image embedding 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-image-object-detection.test.js b/ai-platform/snippets/test/predict-image-object-detection.test.js deleted file mode 100644 index d482ea5564..0000000000 --- a/ai-platform/snippets/test/predict-image-object-detection.test.js +++ /dev/null @@ -1,46 +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/caprese_salad.jpg'; -const endpointId = '2791387344039575552'; -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict image object detection', async function () { - this.retries(2); - it('should make predictions using the image object detection model', async () => { - const stdout = execSync( - `node ./predict-image-object-detection.js ${filename} \ - ${endpointId} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Predict image object detection response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-tabular-classification.test.js b/ai-platform/snippets/test/predict-tabular-classification.test.js deleted file mode 100644 index 1bb90a85a3..0000000000 --- a/ai-platform/snippets/test/predict-tabular-classification.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 endpointId = '4966625964059525120'; -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict tabular classification', () => { - it('should make predictions using the tabular classification model', async () => { - const stdout = execSync( - `node ./predict-tabular-classification.js ${endpointId} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - console.log(stdout); - assert.match(stdout, /Predict tabular classification response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-tabular-regression.test.js b/ai-platform/snippets/test/predict-tabular-regression.test.js deleted file mode 100644 index 6e18ee6afe..0000000000 --- a/ai-platform/snippets/test/predict-tabular-regression.test.js +++ /dev/null @@ -1,42 +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 endpointId = '1014154341088493568'; -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict tabular regression', () => { - it('should make predictions using the tabular regression model', async () => { - const stdout = execSync( - `node ./predict-tabular-regression.js ${endpointId} ${project} ${location}`, - { - cwd, - } - ); - console.log(stdout); - assert.match(stdout, /Predict tabular regression response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-text-classification.test.js b/ai-platform/snippets/test/predict-text-classification.test.js deleted file mode 100644 index c4654b132d..0000000000 --- a/ai-platform/snippets/test/predict-text-classification.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 = - 'My local greasy-spoon diner took way too long' + - 'to get my food. It also costs too much. Good food though.'; -const endpointId = '65372563341049856'; -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict text classification', () => { - it('should make predictions using the text classification model', async () => { - const stdout = execSync( - `node ./predict-text-classification.js "${textInput}" ${endpointId} ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Predict text classification response/); - }); -}); diff --git a/ai-platform/snippets/test/predict-text-embeddings.test.js b/ai-platform/snippets/test/predict-text-embeddings.test.js deleted file mode 100644 index 92cc86fb14..0000000000 --- a/ai-platform/snippets/test/predict-text-embeddings.test.js +++ /dev/null @@ -1,57 +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 dimensionality = 3; -const texts = [ - 'banana bread?', - 'banana muffin?', - 'banana?', - 'recipe?', - 'muffin recipe?', -]; - -describe('predict text embeddings', () => { - it('should get text embeddings using the latest model', async () => { - const stdout = execSync( - `node ./predict-text-embeddings.js ${project} text-embedding-004 '${texts.join(';')}' QUESTION_ANSWERING ${dimensionality}`, - {cwd} - ); - const embeddings = JSON.parse(stdout.trimEnd().split('\n').at(-1)); - assert.equal(texts.length, embeddings.length); - for (const embedding of embeddings) { - assert.equal(dimensionality, embedding.length); - } - }); - it('should get text embeddings using the preview model', async () => { - const stdout = execSync('node ./predict-text-embeddings-preview.js', {cwd}); - const embeddings = JSON.parse(stdout.trimEnd().split('\n').at(-1)); - assert.equal(3, embeddings.length); - for (const embedding of embeddings) { - assert.equal(dimensionality, embedding.length); - } - }); -}); diff --git a/ai-platform/snippets/test/predict-text-entity-extraction.test.js b/ai-platform/snippets/test/predict-text-entity-extraction.test.js deleted file mode 100644 index d2ab4e2637..0000000000 --- a/ai-platform/snippets/test/predict-text-entity-extraction.test.js +++ /dev/null @@ -1,43 +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 = - 'Bipolar depression and anxiety are often hereditary diseases.'; -const endpointId = '6207156555167563776'; -const project = process.env.CAIP_PROJECT_ID; -const location = 'us-central1'; - -describe('AI platform predict text entity extraction', () => { - it('should make predictions using the text extraction model', async () => { - const stdout = execSync( - `node ./predict-text-entity-extraction.js "${textInput}" ${endpointId} ${project} ${location}`, - { - cwd, - } - ); - assert.match(stdout, /Predict text entity extraction 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 deleted file mode 100644 index b06c3eb1a9..0000000000 --- a/ai-platform/snippets/test/upload-model.test.js +++ /dev/null @@ -1,61 +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 modelDisplayName = `temp_upload_model_test${uuid()}`; -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; - -let modelId; - -describe('AI platform upload model', () => { - it('should upload the specified model', async () => { - const stdout = execSync( - `node ./upload-model.js ${modelDisplayName} \ - ${imageUri} \ - ${artifactUri} \ - ${project} \ - ${location}`, - { - cwd, - } - ); - console.log(stdout); - assert.match(stdout, /Upload model response/); - modelId = stdout - .split('/locations/us-central1/models/')[1] - .split('\n')[0] - .split('/')[0]; - }); - after('delete the model', async () => { - execSync(`node ./delete-model.js ${modelId} ${project} ${location}`, { - cwd, - }); - }); -}); 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/ai-platform/snippets/undeploy-model.js b/ai-platform/snippets/undeploy-model.js deleted file mode 100644 index 7081558b63..0000000000 --- a/ai-platform/snippets/undeploy-model.js +++ /dev/null @@ -1,74 +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( - deployedModelId, - endpointId, - project, - location = 'us-central1' -) { - // [START aiplatform_undeploy_model_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const deployedModelId = "YOUR_MODEL_ID"; - // const endpointId = 'YOUR_ENDPOINT_ID'; - // const project = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - - 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 undeployModel() { - // Configure the parent resource - const request = { - deployedModelId, - endpoint, - }; - - // Get and print out a list of all the endpoints for this resource - const [response] = await endpointServiceClient.undeployModel(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - - console.log('Undeploy model response'); - console.log(response); - } - undeployModel(); - // [END aiplatform_undeploy_model_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/update-entity-type-monitoring-sample.js b/ai-platform/snippets/update-entity-type-monitoring-sample.js deleted file mode 100644 index 24d797ea75..0000000000 --- a/ai-platform/snippets/update-entity-type-monitoring-sample.js +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Updates the parameters of a single EntityType with monitoring configuration. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - duration, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_update_entity_type_monitoring_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const duration = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = - require('@google-cloud/aiplatform').v1beta1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function updateEntityTypeMonitoring() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - // Constructing the monitoring configuration - const monitoringConfig = { - snapshotAnalysis: { - monitoringInterval: { - seconds: Number(duration), - }, - }, - }; - - // Constructing the entityType - const entityType = { - name: name, - monitoringConfig: monitoringConfig, - }; - - const request = { - entityType: entityType, - }; - - // Update EntityType request - const [response] = await featurestoreServiceClient.updateEntityType( - request, - {timeout: Number(timeout)} - ); - - console.log('Update entity type monitoring response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - updateEntityTypeMonitoring(); - // [END aiplatform_update_entity_type_monitoring_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/update-entity-type-sample.js b/ai-platform/snippets/update-entity-type-sample.js deleted file mode 100644 index dfb3872c86..0000000000 --- a/ai-platform/snippets/update-entity-type-sample.js +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Updates the parameters of a single EntityType. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_update_entity_type_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function updateEntityType() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`; - - // Constructing the entityType - const entityType = { - name: name, - labels: { - language: 'nodejs', - project: 'vertex-ai-dev', - }, - description: 'updated description', - }; - - const request = { - entityType: entityType, - }; - - // Update EntityType request - const [response] = await featurestoreServiceClient.updateEntityType( - request, - {timeout: Number(timeout)} - ); - - console.log('Update entity type response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - updateEntityType(); - // [END aiplatform_update_entity_type_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/update-feature-sample.js b/ai-platform/snippets/update-feature-sample.js deleted file mode 100644 index a3e960268c..0000000000 --- a/ai-platform/snippets/update-feature-sample.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Updates the parameters of a single Feature. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - entityTypeId, - featureId, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 300000 -) { - // [START aiplatform_update_feature_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const entityTypeId = 'YOUR_ENTITY_TYPE_ID'; - // const featureId = 'YOUR_FEATURE_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function updateFeature() { - // Configure the name resource - const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}/features/${featureId}`; - - const feature = { - name: name, - labels: { - language: 'nodejs', - created_by: 'update_feature', - }, - }; - - const request = { - feature: feature, - }; - - // Update Feature request - const [response] = await featurestoreServiceClient.updateFeature(request, { - timeout: Number(timeout), - }); - - console.log('Update feature response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - updateFeature(); - // [END aiplatform_update_feature_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/update-featurestore-fixed-nodes-sample.js b/ai-platform/snippets/update-featurestore-fixed-nodes-sample.js deleted file mode 100644 index dabf8e7fab..0000000000 --- a/ai-platform/snippets/update-featurestore-fixed-nodes-sample.js +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Updates the parameters of a single Featurestore. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - fixedNodeCount = 1, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 600000 -) { - // [START aiplatform_update_featurestore_fixed_nodes_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const fixedNodeCount = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function updateFeaturestoreFixedNodes() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const featurestore = { - name: parent, - onlineServingConfig: {fixedNodeCount: Number(fixedNodeCount)}, - }; - - const request = { - featurestore: featurestore, - }; - - // Update Featurestore request - const [operation] = await featurestoreServiceClient.updateFeaturestore( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Update featurestore fixed nodes response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - updateFeaturestoreFixedNodes(); - // [END aiplatform_update_featurestore_fixed_nodes_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/update-featurestore-sample.js b/ai-platform/snippets/update-featurestore-sample.js deleted file mode 100644 index 8cf89b93ed..0000000000 --- a/ai-platform/snippets/update-featurestore-sample.js +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2022 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. - */ - -/* - * Updates the parameters of a single Featurestore with autoscaling configuration. - * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running - * the code snippet - */ - -'use strict'; - -async function main( - project, - featurestoreId, - minNodeCount = 1, - maxNodeCount = 3, - location = 'us-central1', - apiEndpoint = 'us-central1-aiplatform.googleapis.com', - timeout = 600000 -) { - // [START aiplatform_update_featurestore_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - - // const project = 'YOUR_PROJECT_ID'; - // const featurestoreId = 'YOUR_FEATURESTORE_ID'; - // const minNodeCount = ; - // const maxNodeCount = ; - // const location = 'YOUR_PROJECT_LOCATION'; - // const apiEndpoint = 'YOUR_API_ENDPOINT'; - // const timeout = ; - - // Imports the Google Cloud Featurestore Service Client library - const {FeaturestoreServiceClient} = - require('@google-cloud/aiplatform').v1beta1; - - // Specifies the location of the api endpoint - const clientOptions = { - apiEndpoint: apiEndpoint, - }; - - // Instantiates a client - const featurestoreServiceClient = new FeaturestoreServiceClient( - clientOptions - ); - - async function updateFeaturestore() { - // Configure the parent resource - const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; - - const featurestore = { - name: parent, - onlineServingConfig: { - scaling: { - minNodeCount: minNodeCount, - maxNodeCount: maxNodeCount, - }, - }, - }; - - const request = { - featurestore: featurestore, - }; - - // Update Featurestore request - const [operation] = await featurestoreServiceClient.updateFeaturestore( - request, - {timeout: Number(timeout)} - ); - const [response] = await operation.promise(); - - console.log('Update featurestore response'); - console.log(`Name : ${response.name}`); - console.log('Raw response:'); - console.log(JSON.stringify(response, null, 2)); - } - updateFeaturestore(); - // [END aiplatform_update_featurestore_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2)); diff --git a/ai-platform/snippets/upload-model.js b/ai-platform/snippets/upload-model.js deleted file mode 100644 index 56e3c01c16..0000000000 --- a/ai-platform/snippets/upload-model.js +++ /dev/null @@ -1,94 +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( - modelDisplayName, - imageUri, - artifactUri, - project, - location = 'us-central1' -) { - // [START aiplatform_upload_model_sample] - /** - * TODO(developer): Uncomment these variables before running the sample.\ - */ - - // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; - // const metadataSchemaUri = 'YOUR_METADATA_SCHEMA_URI'; - // const imageUri = 'YOUR_IMAGE_URI'; - // const artifactUri = 'YOUR_ARTIFACT_URI'; - // 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 uploadModel() { - // Configure the parent resources - const parent = `projects/${project}/locations/${location}`; - // Configure the model resources - const model = { - displayName: modelDisplayName, - metadataSchemaUri: '', - artifactUri: artifactUri, - containerSpec: { - imageUri: imageUri, - command: [], - args: [], - env: [], - ports: [], - predictRoute: '', - healthRoute: '', - }, - }; - const request = { - parent, - model, - }; - - console.log('PARENT AND MODEL'); - console.log(parent, model); - // Upload Model request - const [response] = await modelServiceClient.uploadModel(request); - console.log(`Long running operation : ${response.name}`); - - // Wait for operation to complete - await response.promise(); - const result = response.result; - - console.log('Upload model response '); - console.log(`\tModel : ${result.model}`); - } - uploadModel(); - // [END aiplatform_upload_model_sample] -} - -process.on('unhandledRejection', err => { - console.error(err.message); - process.exitCode = 1; -}); - -main(...process.argv.slice(2));