Skip to content

Commit 42e987d

Browse files
nirupa-kumarAce Nassri
authored and
Ace Nassri
committed
docs(samples): automl tables beta samples (#155)
* Automl Tables beta samples * skipping tests * skipping tests * skipping tests * skipping tests
1 parent ecd192d commit 42e987d

35 files changed

+2786
-8
lines changed

automl/package.json

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
{
22
"name": "@google-cloud/automl-samples",
33
"description": "Samples for the Cloud AutoML Client Library for Node.js.",
4+
"version": "0.0.1",
45
"license": "Apache-2.0",
56
"author": "Google LLC",
67
"engines": {
78
"node": ">=8"
89
},
9-
"files": [
10-
"!test/*"
11-
],
1210
"repository": "googleapis/nodejs-automl",
1311
"private": true,
12+
"nyc": {
13+
"exclude": [
14+
"**/*.test.js"
15+
]
16+
},
1417
"scripts": {
15-
"test": "mocha --timeout 600000 --recursive"
18+
"test": "mocha --timeout 600000"
1619
},
1720
"dependencies": {
1821
"@google-cloud/automl": "^0.2.0",
22+
"chai": "^4.2.0",
23+
"execa": "^1.0.0",
1924
"mathjs": "^5.5.0",
20-
"yargs": "^13.2.1",
21-
"execa":"^1.0.0"
25+
"yargs": "^13.2.1"
2226
},
2327
"devDependencies": {
24-
"mocha": "^6.0.1",
25-
"chai": "^4.2.0"
28+
"mocha": "^6.0.1"
2629
}
2730
}
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
datasetName = 'YOUR_DATASET_NAME'
21+
) {
22+
// [START automl_tables_create_dataset]
23+
const automl = require(`@google-cloud/automl`);
24+
const util = require(`util`);
25+
const client = new automl.v1beta1.AutoMlClient();
26+
27+
/**
28+
* Demonstrates using the AutoML client to create a dataset
29+
* TODO(developer): Uncomment the following lines before running the sample.
30+
*/
31+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
32+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
33+
// const datasetName = '[DATASET_NAME]' e.g., “myDataset”;
34+
35+
// A resource that represents Google Cloud Platform location.
36+
const projectLocation = client.locationPath(projectId, computeRegion);
37+
38+
// Set dataset name and metadata.
39+
const myDataset = {
40+
displayName: datasetName,
41+
tablesDatasetMetadata: {},
42+
};
43+
44+
// Create a dataset with the dataset metadata in the region.
45+
client
46+
.createDataset({parent: projectLocation, dataset: myDataset})
47+
.then(responses => {
48+
const dataset = responses[0];
49+
// Display the dataset information.
50+
console.log(`Dataset name: ${dataset.name}`);
51+
console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`);
52+
console.log(`Dataset display name: ${dataset.displayName}`);
53+
console.log(`Dataset example count: ${dataset.exampleCount}`);
54+
console.log(
55+
`Tables dataset metadata: ${util.inspect(
56+
dataset.tablesDatasetMetadata,
57+
false,
58+
null
59+
)}`
60+
);
61+
})
62+
.catch(err => {
63+
console.error(err);
64+
});
65+
// [END automl_tables_create_dataset]
66+
}
67+
main(...process.argv.slice(2)).catch(console.error());

automl/tables/create-model.v1beta1.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
datasetId = 'YOUR_DATASET_ID',
21+
tableId = 'TABLE_ID',
22+
columnId = 'COLUMN_ID',
23+
modelName = 'MODEL_NAME',
24+
trainBudget = 'TRAIN_BUDGET'
25+
) {
26+
// [START automl_tables_create_model]
27+
const automl = require(`@google-cloud/automl`);
28+
const client = new automl.v1beta1.AutoMlClient();
29+
30+
/**
31+
* Demonstrates using the AutoML client to create a model.
32+
* TODO(developer): Uncomment the following lines before running the sample.
33+
*/
34+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
35+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
36+
// const datasetId = '[DATASET_ID]' e.g., "TBL2246891593778855936";
37+
// const tableId = '[TABLE_ID]' e.g., "1991013247762825216";
38+
// const columnId = '[COLUMN_ID]' e.g., "773141392279994368";
39+
// const modelName = '[MODEL_NAME]' e.g., "testModel";
40+
// const trainBudget = '[TRAIN_BUDGET]' e.g., "1000",
41+
// `Train budget in milli node hours`;
42+
43+
// A resource that represents Google Cloud Platform location.
44+
const projectLocation = client.locationPath(projectId, computeRegion);
45+
46+
// Get the full path of the column.
47+
const columnSpecId = client.columnSpecPath(
48+
projectId,
49+
computeRegion,
50+
datasetId,
51+
tableId,
52+
columnId
53+
);
54+
55+
// Set target column to train the model.
56+
const targetColumnSpec = {name: columnSpecId};
57+
58+
// Set tables model metadata.
59+
const tablesModelMetadata = {
60+
targetColumnSpec: targetColumnSpec,
61+
trainBudgetMilliNodeHours: trainBudget,
62+
};
63+
64+
// Set datasetId, model name and model metadata for the dataset.
65+
const myModel = {
66+
datasetId: datasetId,
67+
displayName: modelName,
68+
tablesModelMetadata: tablesModelMetadata,
69+
};
70+
71+
// Create a model with the model metadata in the region.
72+
client
73+
.createModel({parent: projectLocation, model: myModel})
74+
.then(responses => {
75+
const initialApiResponse = responses[1];
76+
console.log(`Training operation name: ${initialApiResponse.name}`);
77+
console.log(`Training started...`);
78+
})
79+
.catch(err => {
80+
console.error(err);
81+
});
82+
// [END automl_tables_create_model]
83+
}
84+
main(...process.argv.slice(2)).catch(console.error());
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
datasetId = 'YOUR_DATASET_ID'
21+
) {
22+
// [START automl_tables_delete_dataset]
23+
const automl = require(`@google-cloud/automl`);
24+
const client = new automl.v1beta1.AutoMlClient();
25+
26+
/**
27+
* Demonstrates using the AutoML client to delete a dataset.
28+
* TODO(developer): Uncomment the following lines before running the sample.
29+
*/
30+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
31+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
32+
// const datasetId = '[DATASET_ID]' e.g., "TBL2246891593778855936";
33+
34+
// Get the full path of the dataset.
35+
const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId);
36+
37+
// Delete a dataset.
38+
client
39+
.deleteDataset({name: datasetFullId})
40+
.then(responses => {
41+
const operation = responses[0];
42+
return operation.promise();
43+
})
44+
.then(responses => {
45+
// The final result of the operation.
46+
const operationDetails = responses[2];
47+
48+
// Get the dataset delete details.
49+
console.log('Dataset delete details:');
50+
console.log(`\tOperation details:`);
51+
console.log(`\t\tName: ${operationDetails.name}`);
52+
console.log(`\t\tDone: ${operationDetails.done}`);
53+
})
54+
.catch(err => {
55+
console.error(err);
56+
});
57+
// [END automl_tables_delete_dataset]
58+
}
59+
main(...process.argv.slice(2)).catch(console.error());

automl/tables/delete-model.v1beta1.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
modelId = 'MODEL_ID'
21+
) {
22+
// [START automl_tables_delete_model]
23+
const automl = require(`@google-cloud/automl`);
24+
const client = new automl.v1beta1.AutoMlClient();
25+
26+
/**
27+
* Demonstrates using the AutoML client to delete a model.
28+
* TODO(developer): Uncomment the following lines before running the sample.
29+
*/
30+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
31+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
32+
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";
33+
34+
// Get the full path of the model.
35+
const modelFullId = client.modelPath(projectId, computeRegion, modelId);
36+
37+
// Delete a model.
38+
client
39+
.deleteModel({name: modelFullId})
40+
.then(responses => {
41+
const operation = responses[0];
42+
return operation.promise();
43+
})
44+
.then(responses => {
45+
// The final result of the operation.
46+
const operationDetails = responses[2];
47+
48+
// Get the Model delete details.
49+
console.log('Model delete details:');
50+
console.log(`\tOperation details:`);
51+
console.log(`\t\tName: ${operationDetails.name}`);
52+
console.log(`\tDone: ${operationDetails.done}`);
53+
})
54+
.catch(err => {
55+
console.error(err);
56+
});
57+
// [END automl_tables_delete_model]
58+
}
59+
main(...process.argv.slice(2)).catch(console.error());

automl/tables/deploy-model.v1beta1.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
modelId = 'MODEL_ID'
21+
) {
22+
// [START automl_tables_deploy_model]
23+
const automl = require(`@google-cloud/automl`);
24+
const client = new automl.v1beta1.AutoMlClient();
25+
26+
/**
27+
* Demonstrates using the AutoML client to deploy model.
28+
* TODO(developer): Uncomment the following lines before running the sample.
29+
*/
30+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
31+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
32+
// const modelId = '[MODEL_ID]' e.g., "TBL4704590352927948800";
33+
34+
// Get the full path of the model.
35+
const modelFullId = client.modelPath(projectId, computeRegion, modelId);
36+
37+
// Deploy a model with the deploy model request.
38+
client
39+
.deployModel({name: modelFullId})
40+
.then(responses => {
41+
const response = responses[0];
42+
console.log(`Deployment Details:`);
43+
console.log(`\tName: ${response.name}`);
44+
console.log(`\tMetadata:`);
45+
console.log(`\t\tType Url: ${response.metadata.typeUrl}`);
46+
console.log(`\tDone: ${response.done}`);
47+
})
48+
.catch(err => {
49+
console.error(err);
50+
});
51+
// [END automl_tables_deploy_model]
52+
}
53+
main(...process.argv.slice(2)).catch(console.error());

0 commit comments

Comments
 (0)