diff --git a/sdk/cognitiveservices/cognitiveservices-autosuggest/README.md b/sdk/cognitiveservices/cognitiveservices-autosuggest/README.md index 5f920fb23e91..53e74903e5a2 100644 --- a/sdk/cognitiveservices/cognitiveservices-autosuggest/README.md +++ b/sdk/cognitiveservices/cognitiveservices-autosuggest/README.md @@ -15,105 +15,99 @@ npm install @azure/cognitiveservices-autosuggest ### How to use -#### nodejs - Authentication, client creation and autoSuggest as an example written in TypeScript. +#### nodejs - Authentication, client creation and autoSuggest 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 gets suggestions from Bing for the given query **Microsoft Azure**. To know more, refer to the [Azure Documentation on Bing Auto Suggest](https://docs.microsoft.com/en-us/azure/cognitive-services/bing-autosuggest/) ```typescript -import { AutoSuggestClient, AutoSuggestModels } from "@azure/cognitiveservices-autosuggest"; -import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js"; - -async function main(): Promise { - const autoSuggestKey = process.env["autoSuggestKey"] || ""; - const cognitiveServiceCredentials = new CognitiveServicesCredentials(autoSuggestKey); - const client = new AutoSuggestClient(cognitiveServiceCredentials); - - const query = "Microsoft Azure"; - const options: AutoSuggestModels.AutoSuggestClientAutoSuggestOptionalParams = { - acceptLanguage: "en-US", - pragma: "no-cache", - clientId: "testclientId", - location: "westus2", - countryCode: "en-US" - }; - - client - .autoSuggest(query, options) - .then((result) => { - console.log("The result is:"); - result.suggestionGroups.forEach((suggestionGroup) => { - suggestionGroup.searchSuggestions.forEach((searchSuggestion) => { - console.log(`URL: ${searchSuggestion.url}`); - console.log(`Display Text: ${searchSuggestion.displayText}`); - }); - }); - }) - .catch((err) => { - console.log("An error occurred:"); - console.error(err); - }); -} - -main(); +import * as msRest from "@azure/ms-rest-js"; +import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; +import { AutoSuggestClient, AutoSuggestModels, AutoSuggestMappers } from "@azure/cognitiveservices-autosuggest"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new AutoSuggestClient(creds, subscriptionId); + const query = "testquery"; + const acceptLanguage = "testacceptLanguage"; + const pragma = "testpragma"; + const userAgent = "testuserAgent"; + const clientId = "testclientId"; + const clientIp = "testclientIp"; + const location = "westus"; + const countryCode = "testcountryCode"; + const market = "testmarket"; + const safeSearch = "Off"; + const setLang = "testsetLang"; + const responseFormat = ["Json"]; + client.autoSuggest(query, acceptLanguage, pragma, userAgent, clientId, clientIp, location, countryCode, market, safeSearch, setLang, responseFormat).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); ``` -#### browser - Authentication, client creation and autoSuggest as an example written in JavaScript. +#### browser - Authentication, client creation and autoSuggest 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 @azure/cognitiveservices-autosuggest sample +