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 + diff --git a/swagger_to_sdk_config.json b/swagger_to_sdk_config.json index a4f763911359..0387101043cb 100644 --- a/swagger_to_sdk_config.json +++ b/swagger_to_sdk_config.json @@ -5,7 +5,8 @@ "typescript": "", "license-header": "MICROSOFT_MIT_NO_VERSION", "sdkrel:typescript-sdks-folder": ".", - "use": "@microsoft.azure/autorest.typescript@4.1.1" + "typescript.clear-output-folder": "", + "use": "@microsoft.azure/autorest.typescript@4.2.2" }, "advanced_options": { "clone_dir": "./azure-sdk-for-js",