Skip to content

Commit 7218424

Browse files
nnegreybcoe
authored and
Ace Nassri
committed
docs: move and update beta import samples (#341)
* docs: move and update beta import samples * Update import-dataset.js Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent 406ac4c commit 7218424

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

automl/beta/import-dataset.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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_DISPLAY_ID',
21+
path = 'gs://BUCKET_ID/path_to_training_data.csv'
22+
) {
23+
// [START automl_import_dataset_beta]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const projectId = 'YOUR_PROJECT_ID';
28+
// const location = 'us-central1';
29+
// const datasetId = 'YOUR_DISPLAY_ID';
30+
// const path = 'gs://BUCKET_ID/path_to_training_data.csv';
31+
32+
// Imports the Google Cloud AutoML library
33+
const {AutoMlClient} = require(`@google-cloud/automl`).v1beta1;
34+
35+
// Instantiates a client
36+
const client = new AutoMlClient();
37+
38+
async function importDataset() {
39+
// Construct request
40+
const request = {
41+
name: client.datasetPath(projectId, location, datasetId),
42+
inputConfig: {
43+
gcsSource: {
44+
inputUris: path.split(','),
45+
},
46+
},
47+
};
48+
49+
// Import dataset
50+
console.log(`Proccessing import`);
51+
const [operation] = await client.importData(request);
52+
53+
// Wait for operation to complete.
54+
const [response] = await operation.promise();
55+
console.log(`Dataset imported: ${response}`);
56+
}
57+
58+
importDataset();
59+
// [END automl_import_dataset_beta]
60+
}
61+
62+
main(...process.argv.slice(2));
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
20+
21+
const cp = require('child_process');
22+
23+
const IMPORT_DATASET_REGION_TAG = 'beta/import-dataset';
24+
const LOCATION = 'us-central1';
25+
26+
describe('Automl Import Dataset Test', () => {
27+
const client = new AutoMlClient();
28+
29+
it('should import a dataset', async () => {
30+
// As importing a dataset can take a long time, instead try to import to a
31+
// nonexistent dataset and confirm that the dataset was not found, but
32+
// other elements of the request were valid.
33+
const projectId = await client.getProjectId();
34+
const data = `gs://${projectId}-automl-translate/en-ja-short.csv`;
35+
const args = [IMPORT_DATASET_REGION_TAG, projectId, LOCATION, 'TEN0000000000000000000', data];
36+
const output = cp.spawnSync('node', args, {encoding: 'utf8'});
37+
38+
assert.match(output.stderr, /NOT_FOUND/);
39+
});
40+
});

0 commit comments

Comments
 (0)