Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
feat: adds enhancements to library (#22)
Browse files Browse the repository at this point in the history
* feat: adds enhancements to library

* chore: changes to synth.py

* fix: broken pack n' play test

* fix: add enhanced types to ts compiler

* fix: project enabled

* fix: adds docstrings to toValue(), fromValue() functions

* fix: removing any

* fix: edits to synth.py per reviewer

* fix: add more test coverage

* chore: added comment about conversion interface

Co-authored-by: Sofia Leon <sofialeon@google.com>
  • Loading branch information
telpirion and sofisl authored Dec 18, 2020
1 parent 4f7318b commit b697a38
Show file tree
Hide file tree
Showing 25 changed files with 1,274 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ system-test/*key.json
.DS_Store
package-lock.json
__pycache__
.vscode
3 changes: 1 addition & 2 deletions .kokoro/samples-test.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .kokoro/system-test.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ has instructions for running the samples.

| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
| Create-training-pipeline-image-classification | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/create-training-pipeline-image-classification.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/create-training-pipeline-image-classification.js,samples/README.md) |
| List-endpoints | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/list-endpoints.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-endpoints.js,samples/README.md) |
| Predict-image-classification | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/predict-image-classification.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/predict-image-classification.js,samples/README.md) |
| Quickstart | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |


Expand Down
5 changes: 4 additions & 1 deletion linkinator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"skip": [
"https://codecov.io/gh/googleapis/",
"www.googleapis.com",
"img.shields.io"
"img.shields.io",
"https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/list-endpoints.js",
"https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/create-training-pipeline-image-classification.js",
"https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/predict-image-classification.js"
],
"silent": true,
"concurrency": 10
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"test": "c8 mocha build/test"
},
"dependencies": {
"google-gax": "^2.9.2"
"google-gax": "^2.9.2",
"protobuf.js": "^1.1.2"
},
"devDependencies": {
"@types/mocha": "^8.0.3",
Expand Down
54 changes: 42 additions & 12 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `python -m synthtool`."
[//]: # 'This README.md file is auto-generated, all changes to this file will be lost.'
[//]: # 'To regenerate it, use `python -m synthtool`.'

<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [AI Platform: Node.js Samples](https://github.com/googleapis/nodejs-ai-platform)

[![Open in Cloud Shell][shell_img]][shell_link]



## Table of Contents

* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Quickstart](#quickstart)
- [Before you begin](#before-you-begin)
- [Samples](#samples)
- [Create-training-pipeline-image-classification](#create-training-pipeline-image-classification)
- [List-endpoints](#list-endpoints)
- [Predict-image-classification](#predict-image-classification)
- [Quickstart](#quickstart)

## Before you begin

Expand All @@ -27,23 +29,51 @@ Before running the samples, make sure you've followed the steps outlined in

## Samples

### Create-training-pipeline-image-classification

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/create-training-pipeline-image-classification.js).

### Quickstart
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/create-training-pipeline-image-classification.js,samples/README.md)

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/quickstart.js).
**Usage:**

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)
`node samples/create-training-pipeline-image-classification.js`

__Usage:__
---

### List-endpoints

`node samples/quickstart.js`
View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/list-endpoints.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-endpoints.js,samples/README.md)

**Usage:**

`node samples/list-endpoints.js`

---

### Predict-image-classification

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/predict-image-classification.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/predict-image-classification.js,samples/README.md)

**Usage:**

`node samples/predict-image-classification.js`

---

### Quickstart

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/master/samples/quickstart.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)

**Usage:**

`node samples/quickstart.js`

[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/README.md
Expand Down
135 changes: 135 additions & 0 deletions samples/create-training-pipeline-image-classification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(
datasetId,
modelDisplayName,
trainingPipelineDisplayName,
project,
location = 'us-central1'
) {
// [START aiplatform_create_training_pipeline_image_classification]
/**
* TODO(developer): Uncomment these variables before running the sample.
* (Not necessary if passing values as arguments)
*/
/*
const datasetId = 'YOUR DATASET';
const modelDisplayName = 'NEW MODEL NAME;
const trainingPipelineDisplayName = 'NAME FOR TRAINING PIPELINE';
const project = 'YOUR PROJECT ID';
const location = 'us-central1';
*/
// Imports the Google Cloud Pipeline Service Client library
const aiplatform = require('@google-cloud/aiplatform');

const {
definition,
} = aiplatform.protos.google.cloud.aiplatform.v1beta1.schema.trainingjob;
const ModelType = definition.AutoMlImageClassificationInputs.ModelType;

// Specifies the location of the api endpoint
const clientOptions = {
apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};

// Instantiates a client
const pipelineServiceClient = new aiplatform.PipelineServiceClient(
clientOptions
);

async function createTrainingPipelineImageClassification() {
// Configure the parent resource
const parent = `projects/${project}/locations/${location}`;

// Values should match the input expected by your model.
const trainingTaskInputsMessage = new definition.AutoMlImageClassificationInputs(
{
multiLabel: true,
modelType: ModelType.CLOUD,
budgetMilliNodeHours: 8000,
disableEarlyStopping: false,
}
);

const trainingTaskInputs = trainingTaskInputsMessage.toValue();

const trainingTaskDefinition =
'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_image_classification_1.0.0.yaml';

const modelToUpload = {displayName: modelDisplayName};
const inputDataConfig = {datasetId: datasetId};
const trainingPipeline = {
displayName: trainingPipelineDisplayName,
trainingTaskDefinition,
trainingTaskInputs,
inputDataConfig: inputDataConfig,
modelToUpload: modelToUpload,
};
const request = {
parent,
trainingPipeline,
};

// Create training pipeline request
const [response] = await pipelineServiceClient.createTrainingPipeline(
request
);

console.log('Create training pipeline image classification response');
console.log(`\tName : ${response.name}`);
console.log(`\tDisplay Name : ${response.displayName}`);
console.log(
`\tTraining task definition : ${response.trainingTaskDefinition}`
);
console.log(
`\tTraining task inputs : \
${JSON.stringify(response.trainingTaskInputs)}`
);
console.log(
`\tTraining task metadata : \
${JSON.stringify(response.trainingTaskMetadata)}`
);
console.log(`\tState ; ${response.state}`);
console.log(`\tCreate time : ${JSON.stringify(response.createTime)}`);
console.log(`\tStart time : ${JSON.stringify(response.startTime)}`);
console.log(`\tEnd time : ${JSON.stringify(response.endTime)}`);
console.log(`\tUpdate time : ${JSON.stringify(response.updateTime)}`);
console.log(`\tLabels : ${JSON.stringify(response.labels)}`);

const error = response.error;
console.log('\tError');
if (error === null) {
console.log('\t\tCode : {}');
console.log('\t\tMessage : {}');
} else {
console.log(`\t\tCode : ${error.code}`);
console.log(`\t\tMessage : ${error.message}`);
}
}

createTrainingPipelineImageClassification();
// [END aiplatform_create_training_pipeline_image_classification]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});

main(...process.argv.slice(2));
61 changes: 61 additions & 0 deletions samples/list-endpoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2020, Google, LLC.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location = 'us-central1') {
// [START aiplatform_list_endpoints]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';

const {EndpointServiceClient} = require('@google-cloud/aiplatform');

// Specifies the location of the api endpoint
const clientOptions = {
apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};
const client = new EndpointServiceClient(clientOptions);

async function listEndpoints() {
// Configure the parent resource
const parent = `projects/${projectId}/locations/${location}`;
const request = {
parent,
};

// Get and print out a list of all the endpoints for this resource
const [result] = await client.listEndpoints(request);
for (const endpoint of result) {
console.log(`\nEndpoint name: ${endpoint.name}`);
console.log(`Display name: ${endpoint.displayName}`);
if (endpoint.deployedModels[0]) {
console.log(
`First deployed model: ${endpoint.deployedModels[0].model}`
);
}
}
}

listEndpoints();
// [END aiplatform_list_endpoints]
}

main(...process.argv.slice(2)).catch(err => {
console.error(err);
process.exitCode = 1;
});
4 changes: 3 additions & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"@google-cloud/aiplatform": "^1.0.0"
},
"devDependencies": {
"mocha": "^8.0.0"
"chai": "^4.2.0",
"mocha": "^8.0.0",
"uuid": "^8.3.1"
}
}
Loading

0 comments on commit b697a38

Please sign in to comment.