Skip to content

Commit

Permalink
docs(samples): automl tables beta samples (#155)
Browse files Browse the repository at this point in the history
* Automl Tables beta samples

* skipping tests

* skipping tests

* skipping tests

* skipping tests
  • Loading branch information
nirupa-kumar authored and Ace Nassri committed Nov 17, 2022
1 parent 14de2b9 commit 12e5ac3
Show file tree
Hide file tree
Showing 35 changed files with 2,786 additions and 8 deletions.
19 changes: 11 additions & 8 deletions automl/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{
"name": "@google-cloud/automl-samples",
"description": "Samples for the Cloud AutoML Client Library for Node.js.",
"version": "0.0.1",
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=8"
},
"files": [
"!test/*"
],
"repository": "googleapis/nodejs-automl",
"private": true,
"nyc": {
"exclude": [
"**/*.test.js"
]
},
"scripts": {
"test": "mocha --timeout 600000 --recursive"
"test": "mocha --timeout 600000"
},
"dependencies": {
"@google-cloud/automl": "^0.2.0",
"chai": "^4.2.0",
"execa": "^1.0.0",
"mathjs": "^5.5.0",
"yargs": "^13.2.1",
"execa":"^1.0.0"
"yargs": "^13.2.1"
},
"devDependencies": {
"mocha": "^6.0.1",
"chai": "^4.2.0"
"mocha": "^6.0.1"
}
}
67 changes: 67 additions & 0 deletions automl/tables/create-dataset.v1beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
datasetName = 'YOUR_DATASET_NAME'
) {
// [START automl_tables_create_dataset]
const automl = require(`@google-cloud/automl`);
const util = require(`util`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to create a dataset
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const datasetName = '[DATASET_NAME]' e.g., “myDataset”;

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);

// Set dataset name and metadata.
const myDataset = {
displayName: datasetName,
tablesDatasetMetadata: {},
};

// Create a dataset with the dataset metadata in the region.
client
.createDataset({parent: projectLocation, dataset: myDataset})
.then(responses => {
const dataset = responses[0];
// Display the dataset information.
console.log(`Dataset name: ${dataset.name}`);
console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`);
console.log(`Dataset display name: ${dataset.displayName}`);
console.log(`Dataset example count: ${dataset.exampleCount}`);
console.log(
`Tables dataset metadata: ${util.inspect(
dataset.tablesDatasetMetadata,
false,
null
)}`
);
})
.catch(err => {
console.error(err);
});
// [END automl_tables_create_dataset]
}
main(...process.argv.slice(2)).catch(console.error());
84 changes: 84 additions & 0 deletions automl/tables/create-model.v1beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
datasetId = 'YOUR_DATASET_ID',
tableId = 'TABLE_ID',
columnId = 'COLUMN_ID',
modelName = 'MODEL_NAME',
trainBudget = 'TRAIN_BUDGET'
) {
// [START automl_tables_create_model]
const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to create a model.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const datasetId = '[DATASET_ID]' e.g., "TBL2246891593778855936";
// const tableId = '[TABLE_ID]' e.g., "1991013247762825216";
// const columnId = '[COLUMN_ID]' e.g., "773141392279994368";
// const modelName = '[MODEL_NAME]' e.g., "testModel";
// const trainBudget = '[TRAIN_BUDGET]' e.g., "1000",
// `Train budget in milli node hours`;

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);

// Get the full path of the column.
const columnSpecId = client.columnSpecPath(
projectId,
computeRegion,
datasetId,
tableId,
columnId
);

// Set target column to train the model.
const targetColumnSpec = {name: columnSpecId};

// Set tables model metadata.
const tablesModelMetadata = {
targetColumnSpec: targetColumnSpec,
trainBudgetMilliNodeHours: trainBudget,
};

// Set datasetId, model name and model metadata for the dataset.
const myModel = {
datasetId: datasetId,
displayName: modelName,
tablesModelMetadata: tablesModelMetadata,
};

// Create a model with the model metadata in the region.
client
.createModel({parent: projectLocation, model: myModel})
.then(responses => {
const initialApiResponse = responses[1];
console.log(`Training operation name: ${initialApiResponse.name}`);
console.log(`Training started...`);
})
.catch(err => {
console.error(err);
});
// [END automl_tables_create_model]
}
main(...process.argv.slice(2)).catch(console.error());
59 changes: 59 additions & 0 deletions automl/tables/delete-dataset.v1beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
datasetId = 'YOUR_DATASET_ID'
) {
// [START automl_tables_delete_dataset]
const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to delete a dataset.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const datasetId = '[DATASET_ID]' e.g., "TBL2246891593778855936";

// Get the full path of the dataset.
const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId);

// Delete a dataset.
client
.deleteDataset({name: datasetFullId})
.then(responses => {
const operation = responses[0];
return operation.promise();
})
.then(responses => {
// The final result of the operation.
const operationDetails = responses[2];

// Get the dataset delete details.
console.log('Dataset delete details:');
console.log(`\tOperation details:`);
console.log(`\t\tName: ${operationDetails.name}`);
console.log(`\t\tDone: ${operationDetails.done}`);
})
.catch(err => {
console.error(err);
});
// [END automl_tables_delete_dataset]
}
main(...process.argv.slice(2)).catch(console.error());
59 changes: 59 additions & 0 deletions automl/tables/delete-model.v1beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
modelId = 'MODEL_ID'
) {
// [START automl_tables_delete_model]
const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to delete a model.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";

// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);

// Delete a model.
client
.deleteModel({name: modelFullId})
.then(responses => {
const operation = responses[0];
return operation.promise();
})
.then(responses => {
// The final result of the operation.
const operationDetails = responses[2];

// Get the Model delete details.
console.log('Model delete details:');
console.log(`\tOperation details:`);
console.log(`\t\tName: ${operationDetails.name}`);
console.log(`\tDone: ${operationDetails.done}`);
})
.catch(err => {
console.error(err);
});
// [END automl_tables_delete_model]
}
main(...process.argv.slice(2)).catch(console.error());
53 changes: 53 additions & 0 deletions automl/tables/deploy-model.v1beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
modelId = 'MODEL_ID'
) {
// [START automl_tables_deploy_model]
const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to deploy model.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";

// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);

// Deploy a model with the deploy model request.
client
.deployModel({name: modelFullId})
.then(responses => {
const response = responses[0];
console.log(`Deployment Details:`);
console.log(`\tName: ${response.name}`);
console.log(`\tMetadata:`);
console.log(`\t\tType Url: ${response.metadata.typeUrl}`);
console.log(`\tDone: ${response.done}`);
})
.catch(err => {
console.error(err);
});
// [END automl_tables_deploy_model]
}
main(...process.argv.slice(2)).catch(console.error());
Loading

0 comments on commit 12e5ac3

Please sign in to comment.