PersonalizerClient Library with typescript type definitions for node.js and browser.
npm install @azure/cognitiveservices-personalizerThis package contains an isomorphic SDK for PersonalizerClient.
- Node.js version 6.x.x or higher
- Browser JavaScript
``bash`
npm install @azure/cognitiveservices-personalizer
#### nodejs - Authentication, client creation and reward events as an example written in TypeScript.
##### Install @azure/ms-rest-azure-js
`bash`
npm install @azure/ms-rest-azure-js
##### Sample code
The following sample ranks a personalized request object. To know more, refer to the Azure Documentation on Personalizer
`javascript
const { PersonalizerClient } = require("@azure/cognitiveservices-personalizer");
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");
async function main() {
const personalizerKey = process.env["personalizerKey"] || "
const personalizerEndPoint =
process.env["personalizerEndPoint"] || "
const cognitiveServiceCredentials = new CognitiveServicesCredentials(
personalizerKey
);
const client = new PersonalizerClient(
cognitiveServiceCredentials,
personalizerEndPoint
);
const 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
};
client
.rank(rankRequest)
.then(result => {
console.log("The result is: ");
console.log(result);
})
.catch(err => {
console.log("An error occurred:");
console.error(err);
});
}
main();
`
#### browser - Authentication, client creation and reward events as an example written in JavaScript.
##### Sample code
- index.html
`html``