From bdd6c332eae937a0c8c4ac4a2809816447567a2f Mon Sep 17 00:00:00 2001 From: Phoenix He Date: Thu, 24 Oct 2019 13:28:45 +0800 Subject: [PATCH 1/4] Update swagger_to_sdk_config.json --- swagger_to_sdk_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger_to_sdk_config.json b/swagger_to_sdk_config.json index a4f763911359..399fe6789da5 100644 --- a/swagger_to_sdk_config.json +++ b/swagger_to_sdk_config.json @@ -5,7 +5,7 @@ "typescript": "", "license-header": "MICROSOFT_MIT_NO_VERSION", "sdkrel:typescript-sdks-folder": ".", - "use": "@microsoft.azure/autorest.typescript@4.1.1" + "use": "@microsoft.azure/autorest.typescript@4.2.2" }, "advanced_options": { "clone_dir": "./azure-sdk-for-js", From be583e41b9d1d90a0302d8468afacd475bada73c Mon Sep 17 00:00:00 2001 From: Phoenix He Date: Thu, 24 Oct 2019 14:40:18 +0800 Subject: [PATCH 2/4] Update swagger_to_sdk_config.json --- swagger_to_sdk_config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/swagger_to_sdk_config.json b/swagger_to_sdk_config.json index 399fe6789da5..b8a4c993ce88 100644 --- a/swagger_to_sdk_config.json +++ b/swagger_to_sdk_config.json @@ -5,6 +5,7 @@ "typescript": "", "license-header": "MICROSOFT_MIT_NO_VERSION", "sdkrel:typescript-sdks-folder": ".", + "go.clear-output-folder": "", "use": "@microsoft.azure/autorest.typescript@4.2.2" }, "advanced_options": { From c9511411cee2cb98d6bd53a8deae2c47a3e7c284 Mon Sep 17 00:00:00 2001 From: Phoenix He Date: Thu, 24 Oct 2019 14:49:49 +0800 Subject: [PATCH 3/4] Update swagger_to_sdk_config.json --- swagger_to_sdk_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger_to_sdk_config.json b/swagger_to_sdk_config.json index b8a4c993ce88..0387101043cb 100644 --- a/swagger_to_sdk_config.json +++ b/swagger_to_sdk_config.json @@ -5,7 +5,7 @@ "typescript": "", "license-header": "MICROSOFT_MIT_NO_VERSION", "sdkrel:typescript-sdks-folder": ".", - "go.clear-output-folder": "", + "typescript.clear-output-folder": "", "use": "@microsoft.azure/autorest.typescript@4.2.2" }, "advanced_options": { From 23e4800b8e354da1f1677abaf325c2ab64dbb0b2 Mon Sep 17 00:00:00 2001 From: SDK Automation Date: Fri, 25 Oct 2019 09:47:40 +0000 Subject: [PATCH 4/4] Generated from a71df15a587ec060147aaef2dcfc12d19500fdc8 Fix json format by prettier --- .../cognitiveservices-visualsearch/README.md | 135 ++++++++---------- 1 file changed, 59 insertions(+), 76 deletions(-) diff --git a/sdk/cognitiveservices/cognitiveservices-visualsearch/README.md b/sdk/cognitiveservices/cognitiveservices-visualsearch/README.md index 019a6d80b15f..8a8836cf2be6 100644 --- a/sdk/cognitiveservices/cognitiveservices-visualsearch/README.md +++ b/sdk/cognitiveservices/cognitiveservices-visualsearch/README.md @@ -17,66 +17,55 @@ npm install @azure/cognitiveservices-visualsearch #### nodejs - Authentication, client creation and visualSearch images as an example written in TypeScript. -##### Install @azure/ms-rest-azure-js +##### Install @azure/ms-rest-nodeauth +- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. ```bash -npm install @azure/ms-rest-azure-js +npm install @azure/ms-rest-nodeauth@"^3.0.0" ``` ##### Sample code -The following sample performs a visual search, i.e. perform a search with a image. To know more, refer to the [Azure Documentation on Bing Visual Search](https://docs.microsoft.com/en-us/azure/cognitive-services/bing-visual-search/). ```typescript -import { - VisualSearchClient, - VisualSearchModels -} from "@azure/cognitiveservices-visualsearch"; -import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js"; - -async function main(): Promise { - const visualSearchKey = process.env["visualSearchKey"] || ""; - const visualSearchEndPoint = - process.env["visualSearchEndPoint"] || ""; - const cognitiveServiceCredentials = new CognitiveServicesCredentials( - visualSearchKey - ); - const client = new VisualSearchClient(cognitiveServiceCredentials, { - endpoint: visualSearchEndPoint +import * as msRest from "@azure/ms-rest-js"; +import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; +import { VisualSearchClient, VisualSearchModels, VisualSearchMappers } from "@azure/cognitiveservices-visualsearch"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new VisualSearchClient(creds, subscriptionId); + const acceptLanguage = "testacceptLanguage"; + const contentType = "testcontentType"; + const userAgent = "testuserAgent"; + const clientId = "testclientId"; + const clientIp = "testclientIp"; + const location = "westus"; + const market = "testmarket"; + const safeSearch = "Off"; + const setLang = "testsetLang"; + const knowledgeRequest = "testknowledgeRequest"; + const image = new require("stream").Readable(); + client.images.visualSearch(acceptLanguage, contentType, userAgent, clientId, clientIp, location, market, safeSearch, setLang, knowledgeRequest, image).then((result) => { + console.log("The result is:"); + console.log(result); }); +}).catch((err) => { + console.error(err); +}); +``` - const insightsToken = - process.env["insights_token"] || "";; +#### browser - Authentication, client creation and visualSearch images as an example written in JavaScript. - const knowledgeRequest = JSON.stringify({ - imageInfo: { - imageInsightsToken: insightsToken - } - }); +##### Install @azure/ms-rest-browserauth - const options: VisualSearchModels.ImagesVisualSearchOptionalParams = { - acceptLanguage: "en-US", - knowledgeRequest: knowledgeRequest - }; - - client.images - .visualSearch(options) - .then(result => { - console.log("The result is: "); - console.log(result); - }) - .catch(err => { - console.log("An error occurred:"); - console.error(err); - }); -} - -main(); +```bash +npm install @azure/ms-rest-browserauth ``` -#### browser - Authentication, client creation and visualSearch images as an example written in JavaScript. - ##### Sample code +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. + - index.html ```html @@ -84,45 +73,39 @@ main(); @azure/cognitiveservices-visualsearch sample +