Skip to content

Commit a9957a0

Browse files
nnegreyJustinBeckwith
authored and
Ace Nassri
committed
docs: update beta delete samples for video (#342)
* docs: update beta delete samples for video * Update delete-dataset.js * Update delete-dataset.beta.test.js Co-authored-by: Justin Beckwith <[email protected]>
1 parent f39e5c9 commit a9957a0

File tree

4 files changed

+210
-0
lines changed

4 files changed

+210
-0
lines changed

automl/beta/delete-dataset.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
main(...process.argv.slice(2));

automl/beta/delete-model.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
main(...process.argv.slice(2));
+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+
const {assert} = require('chai');
18+
const {describe, it, before} = require('mocha');
19+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
20+
21+
const cp = require('child_process');
22+
const uuid = require('uuid');
23+
24+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
25+
26+
const DELETE_DATASET_REGION_TAG = 'beta/delete-dataset';
27+
const LOCATION = 'us-central1';
28+
29+
describe('Automl Translate Delete Dataset Tests', () => {
30+
const client = new AutoMlClient();
31+
let datasetId;
32+
33+
before('should create a dataset', async () => {
34+
const projectId = await client.getProjectId();
35+
const displayName = `test_${uuid
36+
.v4()
37+
.replace(/-/g, '_')
38+
.substring(0, 26)}`;
39+
const request = {
40+
parent: client.locationPath(projectId, LOCATION),
41+
dataset: {
42+
displayName: displayName,
43+
translationDatasetMetadata: {
44+
sourceLanguageCode: 'en',
45+
targetLanguageCode: 'ja',
46+
},
47+
},
48+
};
49+
const [response] = await client.createDataset(request);
50+
datasetId = response.name
51+
.split('/')
52+
[response.name.split('/').length - 1].split('\n')[0];
53+
});
54+
55+
it('should delete a dataset', async () => {
56+
const projectId = await client.getProjectId();
57+
const delete_output = execSync(
58+
`node ${DELETE_DATASET_REGION_TAG}.js ${projectId} ${LOCATION} ${datasetId}`
59+
);
60+
assert.match(delete_output, /Dataset deleted/);
61+
});
62+
});

automl/test/delete-model.beta.test.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
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 DELETE_MODEL_REGION_TAG = 'beta/delete-model.js';
24+
const LOCATION = 'us-central1';
25+
26+
describe('Automl Delete Model Tests', () => {
27+
const client = new AutoMlClient();
28+
29+
it('should delete a model', async () => {
30+
// As model creation can take many hours, instead try to delete a
31+
// nonexistent model and confirm that the model was not found, but other
32+
// elements of the request were valid.
33+
const projectId = await client.getProjectId();
34+
const args = [
35+
DELETE_MODEL_REGION_TAG,
36+
projectId,
37+
LOCATION,
38+
'TRL0000000000000000000',
39+
];
40+
const output = cp.spawnSync('node', args, {encoding: 'utf8'});
41+
42+
assert.match(output.stderr, /NOT_FOUND/);
43+
assert.match(output.stderr, /The model does not exist./);
44+
});
45+
});

0 commit comments

Comments
 (0)