diff --git a/sdk/cognitiveservices/cognitiveservices-personalizer/README.md b/sdk/cognitiveservices/cognitiveservices-personalizer/README.md index 481ecb1aaff0..a4750c3ab1de 100644 --- a/sdk/cognitiveservices/cognitiveservices-personalizer/README.md +++ b/sdk/cognitiveservices/cognitiveservices-personalizer/README.md @@ -17,91 +17,48 @@ npm install @azure/cognitiveservices-personalizer #### nodejs - Authentication, client creation and reward events 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 ranks a personalized request object. To know more, refer to the [Azure Documentation on Personalizer](https://docs.microsoft.com/en-us/azure/cognitive-services/personalizer/) ```typescript -import { - PersonalizerClient, - PersonalizerModels -} from "@azure/cognitiveservices-personalizer"; -import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js"; - -async function main(): Promise { - const personalizerKey = process.env["personalizerKey"] || ""; - const personalizerEndPoint = - process.env["personalizerEndPoint"] || ""; - const cognitiveServiceCredentials = new CognitiveServicesCredentials( - personalizerKey - ); - - const client = new PersonalizerClient( - cognitiveServiceCredentials, - personalizerEndPoint - ); - - const rankRequest: PersonalizerModels.RankRequest = { - contextFeatures: [ - { - timeOfDay: "Morning" - } - ], - actions: [ - { - id: "NewsArticle", - features: [ - { - type: "News" - } - ] - }, - { - id: "SportsArticle", - features: [ - { - type: "Sports" - } - ] - }, - { - id: "EntertainmentArticle", - features: [ - { - type: "Entertainment" - } - ] - } - ], - excludedActions: ["SportsArticle"], - eventId: "75269AD0-BFEE-4598-8196-C57383D38E10", - deferActivation: false +import * as msRest from "@azure/ms-rest-js"; +import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; +import { PersonalizerClient, PersonalizerModels, PersonalizerMappers } from "@azure/cognitiveservices-personalizer"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new PersonalizerClient(creds, subscriptionId); + const eventId = "testeventId"; + const rewardParameter: PersonalizerModels.RewardRequest = { + value: 1.01 }; - - client - .rank(rankRequest) - .then(result => { - console.log("The result is: "); - console.log(result); - }) - .catch(err => { - console.log("An error occurred:"); - console.error(err); - }); -} - -main(); + client.events.reward(eventId, rewardParameter).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); ``` #### browser - Authentication, client creation and reward events 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 @@ -109,67 +66,32 @@ main(); @azure/cognitiveservices-personalizer 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",