Skip to content

Commit d3a13c1

Browse files
author
ace-n
committed
Merge remote-tracking branch 'migration/main' into nodejs-automl-migration
2 parents 47d6fd1 + f3931af commit d3a13c1

File tree

128 files changed

+7480
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+7480
-0
lines changed

automl/snippets/.eslintrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
rules:
3+
no-console: off

automl/snippets/batch_predict.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
// https://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+
'use strict';
16+
17+
function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
location = 'us-central1',
20+
modelId = 'YOUR_MODEL_ID',
21+
inputUri = 'gs://YOUR_BUCKET_ID/path_to_your_input_csv_or_jsonl',
22+
outputUri = 'gs://YOUR_BUCKET_ID/path_to_save_results/'
23+
) {
24+
// [START automl_batch_predict]
25+
/**
26+
* TODO(developer): Uncomment these variables before running the sample.
27+
*/
28+
// const projectId = 'YOUR_PROJECT_ID';
29+
// const location = 'us-central1';
30+
// const modelId = 'YOUR_MODEL_ID';
31+
// const inputUri = 'gs://YOUR_BUCKET_ID/path_to_your_input_csv_or_jsonl';
32+
// const outputUri = 'gs://YOUR_BUCKET_ID/path_to_save_results/';
33+
34+
// Imports the Google Cloud AutoML library
35+
const {PredictionServiceClient} = require('@google-cloud/automl').v1;
36+
37+
// Instantiates a client
38+
const client = new PredictionServiceClient();
39+
40+
async function batchPredict() {
41+
// Construct request
42+
const request = {
43+
name: client.modelPath(projectId, location, modelId),
44+
inputConfig: {
45+
gcsSource: {
46+
inputUris: [inputUri],
47+
},
48+
},
49+
outputConfig: {
50+
gcsDestination: {
51+
outputUriPrefix: outputUri,
52+
},
53+
},
54+
};
55+
56+
const [operation] = await client.batchPredict(request);
57+
58+
console.log('Waiting for operation to complete...');
59+
// Wait for operation to complete.
60+
const [response] = await operation.promise();
61+
console.log(
62+
`Batch Prediction results saved to Cloud Storage bucket. ${response}`
63+
);
64+
}
65+
66+
batchPredict();
67+
// [END automl_batch_predict]
68+
}
69+
70+
process.on('unhandledRejection', err => {
71+
console.error(err.message);
72+
process.exitCode = 1;
73+
});
74+
main(...process.argv.slice(2));

automl/snippets/beta/batch_predict.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
// https://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+
'use strict';
16+
17+
function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
location = 'us-central1',
20+
modelId = 'YOUR_MODEL_ID',
21+
inputUri = 'gs://YOUR_BUCKET_ID/path_to_your_input_csv_or_jsonl',
22+
outputUri = 'gs://YOUR_BUCKET_ID/path_to_save_results/'
23+
) {
24+
// [START automl_batch_predict_beta]
25+
/**
26+
* TODO(developer): Uncomment these variables before running the sample.
27+
*/
28+
// const projectId = 'YOUR_PROJECT_ID';
29+
// const location = 'us-central1';
30+
// const modelId = 'YOUR_MODEL_ID';
31+
// const inputUri = 'gs://YOUR_BUCKET_ID/path_to_your_input_csv_or_jsonl';
32+
// const outputUri = 'gs://YOUR_BUCKET_ID/path_to_save_results/';
33+
34+
// Imports the Google Cloud AutoML library
35+
const {PredictionServiceClient} = require('@google-cloud/automl').v1beta1;
36+
37+
// Instantiates a client
38+
const client = new PredictionServiceClient();
39+
40+
async function batchPredict() {
41+
// Construct request
42+
const request = {
43+
name: client.modelPath(projectId, location, modelId),
44+
inputConfig: {
45+
gcsSource: {
46+
inputUris: [inputUri],
47+
},
48+
},
49+
outputConfig: {
50+
gcsDestination: {
51+
outputUriPrefix: outputUri,
52+
},
53+
},
54+
};
55+
56+
const [operation] = await client.batchPredict(request);
57+
58+
console.log('Waiting for operation to complete...');
59+
// Wait for operation to complete.
60+
const [response] = await operation.promise();
61+
console.log(
62+
`Batch Prediction results saved to Cloud Storage bucket. ${response}`
63+
);
64+
}
65+
66+
batchPredict();
67+
// [END automl_batch_predict_beta]
68+
}
69+
70+
process.on('unhandledRejection', err => {
71+
console.error(err.message);
72+
process.exitCode = 1;
73+
});
74+
main(...process.argv.slice(2));
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
'use strict';
16+
17+
async function main(operationFullId) {
18+
// [START automl_cancel_operation_beta]
19+
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// const operationFullId = 'projects/YOUR_PROJECT_ID/locations/YOUR_LOCATIOIN/operations/OPERATION_ID';
24+
25+
// Imports the Google Cloud AutoML library
26+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
27+
28+
// Instantiates a client
29+
const client = new AutoMlClient();
30+
31+
async function cancelOperation() {
32+
client.operationsClient.cancelOperation({
33+
name: operationFullId,
34+
});
35+
36+
// Wait for operation to complete.
37+
console.log('Cancelled operation');
38+
}
39+
40+
cancelOperation();
41+
// [END automl_cancel_operation_beta]
42+
}
43+
44+
main(...process.argv.slice(2)).catch(err => {
45+
console.error(err.message);
46+
process.exitCode = 1;
47+
});
48+
process.on('unhandledRejection', err => {
49+
console.error(err.message);
50+
process.exitCode = 1;
51+
});
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
'use strict';
16+
17+
function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
location = 'us-central1',
20+
datasetId = 'YOUR_DATASET_ID'
21+
) {
22+
// [START automl_delete_dataset_beta]
23+
/**
24+
* TODO(developer): Uncomment these variables before running the sample.
25+
*/
26+
// const projectId = 'YOUR_PROJECT_ID';
27+
// const location = 'us-central1';
28+
// const datasetId = 'YOUR_DATASET_ID';
29+
30+
// Imports the Google Cloud AutoML library
31+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
32+
33+
// Instantiates a client
34+
const client = new AutoMlClient();
35+
36+
async function deleteDataset() {
37+
// Construct request
38+
const request = {
39+
name: client.datasetPath(projectId, location, datasetId),
40+
};
41+
42+
const [operation] = await client.deleteDataset(request);
43+
44+
// Wait for operation to complete.
45+
const [response] = await operation.promise();
46+
console.log(`Dataset deleted: ${response}`);
47+
}
48+
49+
deleteDataset();
50+
// [END automl_delete_dataset_beta]
51+
}
52+
53+
process.on('unhandledRejection', err => {
54+
console.error(err.message);
55+
process.exitCode = 1;
56+
});
57+
main(...process.argv.slice(2));

automl/snippets/beta/delete-model.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
// https://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+
'use strict';
16+
17+
function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
location = 'us-central1',
20+
modelId = 'YOUR_MODEL_ID'
21+
) {
22+
// [START automl_delete_model_beta]
23+
/**
24+
* TODO(developer): Uncomment these variables before running the sample.
25+
*/
26+
// const projectId = 'YOUR_PROJECT_ID';
27+
// const location = 'us-central1';
28+
// const modelId = 'YOUR_MODEL_ID';
29+
30+
// Imports the Google Cloud AutoML library
31+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
32+
33+
// Instantiates a client
34+
const client = new AutoMlClient();
35+
36+
async function deleteModel() {
37+
// Construct request
38+
const request = {
39+
name: client.modelPath(projectId, location, modelId),
40+
};
41+
42+
const [response] = await client.deleteModel(request);
43+
console.log(`Model deleted: ${response}`);
44+
}
45+
46+
deleteModel();
47+
// [END automl_delete_model_beta]
48+
}
49+
50+
process.on('unhandledRejection', err => {
51+
console.error(err.message);
52+
process.exitCode = 1;
53+
});
54+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)