Skip to content

Commit 66ff554

Browse files
lucaswadedavistelpirionbcoe
authored
feat(samples): add additional samples to library (#25)
* Add samples * Fix linter errors * Remove unnecessary samples and tests * Fix minor linter error * Remove unnecessary comments and other small updates * Update project id * Add samples * Fix linter errors * Remove unnecessary samples and tests * Fix minor linter error * Remove unnecessary comments and other small updates * Update project id * Remove terminal await calls * Fix configuration issues * Fix parsing error * Update samples/package.json * Update samples/predict-custom-trained-model.js * Fix async file access for Node 10 * Ensmallify the example image Co-authored-by: Eric Schmidt <[email protected]> Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent a35f497 commit 66ff554

File tree

77 files changed

+5304
-16
lines changed

Some content is hidden

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

77 files changed

+5304
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(batchPredictionJobId, project, location = 'us-central1') {
20+
// [START aiplatform_cancel_batch_prediction_job]
21+
/**
22+
* TODO(developer): Uncomment these variables before running the sample.\
23+
* (Not necessary if passing values as arguments)
24+
*/
25+
26+
// const batchPredictionJobId = 'YOUR_BATCH_PREDICTION_JOB_ID';
27+
// const project = 'YOUR_PROJECT_ID';
28+
// const location = 'YOUR_PROJECT_LOCATION';
29+
30+
// Imports the Google Cloud Job Service Client library
31+
const {JobServiceClient} = require('@google-cloud/aiplatform');
32+
33+
// Specifies the location of the api endpoint
34+
const clientOptions = {
35+
apiEndpoint: 'us-central1-aiplatform.googleapis.com',
36+
};
37+
38+
// Instantiates a client
39+
const jobServiceClient = new JobServiceClient(clientOptions);
40+
41+
async function cancelBatchPredictionJob() {
42+
// Configure the name resource
43+
const name = `projects/${project}/locations/${location}/batchPredictionJobs/${batchPredictionJobId}`;
44+
const request = {
45+
name,
46+
};
47+
48+
// Cancel batch prediction job request
49+
await jobServiceClient.cancelBatchPredictionJob(request);
50+
console.log('Cancel batch prediction job response :');
51+
}
52+
53+
cancelBatchPredictionJob();
54+
// [END aiplatform_cancel_batch_prediction_job]
55+
}
56+
57+
process.on('unhandledRejection', err => {
58+
console.error(err.message);
59+
process.exitCode = 1;
60+
});
61+
62+
main(...process.argv.slice(2));
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(customJobId, project, location = 'us-central1') {
20+
// [START aiplatform_cancel_custom_job]
21+
/**
22+
* TODO(developer): Uncomment these variables before running the sample.\
23+
*/
24+
25+
// const customJobId = 'YOUR_CUSTOM_JOB_ID';
26+
// const project = 'YOUR_PROJECT_ID';
27+
// const location = 'YOUR_PROJECT_LOCATION';
28+
29+
// Imports the Google Cloud Job Service Client library
30+
const {JobServiceClient} = require('@google-cloud/aiplatform');
31+
32+
// Specifies the location of the api endpoint
33+
const clientOptions = {
34+
apiEndpoint: 'us-central1-aiplatform.googleapis.com',
35+
};
36+
37+
// Instantiates a client
38+
const jobServiceClient = new JobServiceClient(clientOptions);
39+
40+
async function cancelCustomJob() {
41+
// Configure the name resource
42+
const name = jobServiceClient.customJobPath(project, location, customJobId);
43+
const request = {
44+
name,
45+
};
46+
47+
// Cancel custom job request
48+
const [response] = await jobServiceClient.cancelCustomJob(request);
49+
50+
console.log('Cancel custom job response');
51+
console.log(`${response}`);
52+
}
53+
cancelCustomJob();
54+
// [END aiplatform_cancel_custom_job]
55+
}
56+
57+
process.on('unhandledRejection', err => {
58+
console.error(err.message);
59+
process.exitCode = 1;
60+
});
61+
62+
main(...process.argv.slice(2));
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(
20+
customJobDisplayName,
21+
containerImageUri,
22+
project,
23+
location = 'us-central1'
24+
) {
25+
// [START aiplatform_create_custom_job]
26+
/**
27+
* TODO(developer): Uncomment these variables before running the sample.\
28+
* (Not necessary if passing values as arguments)
29+
*/
30+
31+
// const customJobDisplayName = 'YOUR_CUSTOM_JOB_DISPLAY_NAME';
32+
// const containerImageUri = 'YOUR_CONTAINER_IMAGE_URI';
33+
// const project = 'YOUR_PROJECT_ID';
34+
// const location = 'YOUR_PROJECT_LOCATION';
35+
36+
// Imports the Google Cloud Job Service Client library
37+
const {JobServiceClient} = require('@google-cloud/aiplatform');
38+
39+
// Specifies the location of the api endpoint
40+
const clientOptions = {
41+
apiEndpoint: 'us-central1-aiplatform.googleapis.com',
42+
};
43+
44+
// Instantiates a client
45+
const jobServiceClient = new JobServiceClient(clientOptions);
46+
47+
async function createCustomJob() {
48+
// Configure the parent resource
49+
const parent = `projects/${project}/locations/${location}`;
50+
const customJob = {
51+
displayName: customJobDisplayName,
52+
jobSpec: {
53+
workerPoolSpecs: [
54+
{
55+
machineSpec: {
56+
machineType: 'n1-standard-4',
57+
acceleratorType: 'NVIDIA_TESLA_K80',
58+
acceleratorCount: 1,
59+
},
60+
replicaCount: 1,
61+
containerSpec: {
62+
imageUri: containerImageUri,
63+
command: [],
64+
args: [],
65+
},
66+
},
67+
],
68+
},
69+
};
70+
const request = {parent, customJob};
71+
72+
// Create custom job request
73+
const [response] = await jobServiceClient.createCustomJob(request);
74+
75+
console.log('Create custom job response');
76+
console.log(`${JSON.stringify(response)}`);
77+
}
78+
createCustomJob();
79+
// [END aiplatform_create_custom_job]
80+
}
81+
82+
process.on('unhandledRejection', err => {
83+
console.error(err.message);
84+
process.exitCode = 1;
85+
});
86+
87+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(datasetDisplayName, project, location = 'us-central1') {
20+
// [START aiplatform_create_dataset_image]
21+
/**
22+
* TODO(developer): Uncomment these variables before running the sample.\
23+
* (Not necessary if passing values as arguments)
24+
*/
25+
26+
// const datasetDisplayName = "YOUR_DATASTE_DISPLAY_NAME";
27+
// const project = 'YOUR_PROJECT_ID';
28+
// const location = 'YOUR_PROJECT_LOCATION';
29+
30+
// Imports the Google Cloud Dataset Service Client library
31+
const {DatasetServiceClient} = require('@google-cloud/aiplatform');
32+
33+
// Specifies the location of the api endpoint
34+
const clientOptions = {
35+
apiEndpoint: 'us-central1-aiplatform.googleapis.com',
36+
};
37+
38+
// Instantiates a client
39+
const datasetServiceClient = new DatasetServiceClient(clientOptions);
40+
41+
async function createDatasetImage() {
42+
// Configure the parent resource
43+
const parent = `projects/${project}/locations/${location}`;
44+
// Configure the dataset resource
45+
const dataset = {
46+
displayName: datasetDisplayName,
47+
metadataSchemaUri:
48+
'gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml',
49+
};
50+
const request = {
51+
parent,
52+
dataset,
53+
};
54+
55+
// Create Dataset Request
56+
const [response] = await datasetServiceClient.createDataset(request);
57+
console.log(`Long running operation: ${response.name}`);
58+
59+
// Wait for operation to complete
60+
await response.promise();
61+
const result = response.result;
62+
63+
console.log('Create dataset image response');
64+
console.log(`Name : ${result.name}`);
65+
console.log(`Display name : ${result.displayName}`);
66+
console.log(`Metadata schema uri : ${result.metadataSchemaUri}`);
67+
console.log(`Metadata : ${JSON.stringify(result.metadata)}`);
68+
console.log(`Labels : ${JSON.stringify(result.labels)}`);
69+
}
70+
createDatasetImage();
71+
// [END aiplatform_create_dataset_image]
72+
}
73+
74+
process.on('unhandledRejection', err => {
75+
console.error(err.message);
76+
process.exitCode = 1;
77+
});
78+
79+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)