From 384ea1b3cf2c012ce5c2b57745b0014986f6c5f8 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Thu, 26 Nov 2020 03:46:32 +0000 Subject: [PATCH] CodeGen from PR 11826 in Azure/azure-rest-api-specs Merge b2b0dbf9de5cd4710ff1822373527da75073514e into bd9c2010c4165f1e792d6fec1e40c5fde49d063e --- .../README.md | 112 +++++++++--------- .../rollup.config.js | 4 +- .../src/models/index.ts | 4 +- .../src/models/mappers.ts | 4 +- .../src/models/parameters.ts | 5 +- .../src/predictionAPIClient.ts | 5 +- .../src/predictionAPIClientContext.ts | 5 +- 7 files changed, 67 insertions(+), 72 deletions(-) diff --git a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/README.md b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/README.md index c77450f79c73..f4c349fe4f12 100644 --- a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/README.md +++ b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/README.md @@ -15,48 +15,50 @@ npm install @azure/cognitiveservices-customvision-prediction ### How to use -#### nodejs - Authentication, client creation and classifyImageUrl as an example written in TypeScript. +#### nodejs - client creation and classifyImage as an example written in TypeScript. + +##### Install @azure/ms-rest-nodeauth + +- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. +```bash +npm install @azure/ms-rest-nodeauth@"^3.0.0" +``` ##### Sample code -The following sample predicts and classifies the given image based on your custom vision training. To know more, refer to the [Azure Documentation on Custom Vision Services](https://docs.microsoft.com/azure/cognitive-services/custom-vision-service/home). -```javascript +While the below sample uses the interactive login, other authentication options can be found in the [README.md file of @azure/ms-rest-nodeauth](https://www.npmjs.com/package/@azure/ms-rest-nodeauth) package +```typescript +const msRestNodeAuth = require("@azure/ms-rest-nodeauth"); const { PredictionAPIClient } = require("@azure/cognitiveservices-customvision-prediction"); -const { ApiKeyCredentials } = require("@azure/ms-rest-js"); - -async function main() { - const customVisionPredictionKey = - process.env["customVisionPredictionKey"] || ""; - const customVisionPredictionEndPoint = - process.env["customVisionPredictionEndPoint"] || - ""; - const projectId = process.env["projectId"] || ""; - - const credentials = new ApiKeyCredentials({ inHeader: {"Prediction-key": customVisionPredictionKey } }); - const client = new PredictionAPIClient(credentials, customVisionPredictionEndPoint); - - const imageURL = - "https://www.atlantatrails.com/wp-content/uploads/2019/02/north-georgia-waterfalls-1024x683.jpg"; - - client - .classifyImageUrl(projectId, "Iteration1", { url: imageURL }) - .then(result => { - console.log("The result is: "); - console.log(result); - }) - .catch(err => { - console.log("An error occurred:"); - console.error(err); - }); -} - -main(); +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new PredictionAPIClient(creds, subscriptionId); + const projectId = ec7b1657-199d-4d8a-bbb2-89a11a42e02a; + const publishedName = "testpublishedName"; + const imageData = new require("stream").Readable(); + const application = "testapplication"; + client.classifyImage(projectId, publishedName, imageData, application).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); ``` -#### browser - Authentication, client creation and classifyImageUrl as an example written in JavaScript. +#### browser - Authentication, client creation and classifyImage as an example written in JavaScript. + +##### Install @azure/ms-rest-browserauth + +```bash +npm install @azure/ms-rest-browserauth +``` ##### Sample code +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. + - index.html ```html @@ -64,36 +66,32 @@ main(); @azure/cognitiveservices-customvision-prediction sample + @@ -104,4 +102,4 @@ main(); - [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcognitiveservices%2Fcognitiveservices-customvision-prediction%2FREADME.png) +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-customvision-prediction/README.png) diff --git a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/rollup.config.js b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/rollup.config.js index b9905172f2fa..dac68d12166e 100644 --- a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/rollup.config.js +++ b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/rollup.config.js @@ -21,8 +21,8 @@ const config = { "@azure/ms-rest-azure-js": "msRestAzure" }, banner: `/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. diff --git a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/index.ts b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/index.ts index 3a91aef5977a..83fcf58bee73 100644 --- a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/index.ts +++ b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/index.ts @@ -1,6 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. diff --git a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/mappers.ts b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/mappers.ts index 1f29c89bbd55..34ec5fec6595 100644 --- a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/mappers.ts +++ b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/mappers.ts @@ -1,6 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. diff --git a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/parameters.ts b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/parameters.ts index fb1197c68e3a..9d7a2e385644 100644 --- a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/parameters.ts +++ b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/models/parameters.ts @@ -1,7 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is diff --git a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/predictionAPIClient.ts b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/predictionAPIClient.ts index c7fd6975a6e8..4e0e7c9110d1 100644 --- a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/predictionAPIClient.ts +++ b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/predictionAPIClient.ts @@ -1,7 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is diff --git a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/predictionAPIClientContext.ts b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/predictionAPIClientContext.ts index 8ccfe5091ad2..bc83bbb8c80d 100644 --- a/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/predictionAPIClientContext.ts +++ b/sdk/cognitiveservices/cognitiveservices-customvision-prediction/src/predictionAPIClientContext.ts @@ -1,7 +1,6 @@ /* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is