PersonalizerClient Class

Personalizer Service is an Azure Cognitive Service that makes it easy to target content and experiences without complex pre-analysis or cleanup of past data. Given a context and featurized content, the Personalizer Service returns which content item to show to users in rewardActionId. As rewards are sent in response to the use of rewardActionId, the reinforcement learning algorithm will improve the model and improve performance of future rank calls.

Inheritance
builtins.object
PersonalizerClient

Constructor

PersonalizerClient(endpoint: str, credential: AzureKeyCredential | TokenCredential, **kwargs: Any)

Parameters

Name Description
endpoint
Required
str

Supported Cognitive Services endpoint. Required.

credential
Required

Credential needed for the client to connect to Azure. Required.

Keyword-Only Parameters

Name Description
api_version
str

Api Version. Default value is "2022-09-01-preview". Note that overriding this default value may result in unsupported behavior.

Methods

activate

Activate Event.

Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be expected for it.

activate_multi_slot

Activate Event (MultiSlot).

Report that the specified event was actually used or displayed to the user and a rewards should be expected for it.

close
rank

Rank.

Submit a Personalizer rank request. Receives a context and a list of actions. Returns which of the provided actions should be used by your application, in rewardActionId.

rank_multi_slot

Rank (MultiSlot).

Submit a Personalizer multi-slot rank request. Receives a context, a list of actions, and a list of slots. Returns which of the provided actions should be used in each slot, in each rewardActionId.

reward

Reward.

Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the specified event.

reward_multi_slot

Reward (MultiSlot).

Report reward that resulted from using the action specified in rewardActionId for the slot.

send_request

Runs the network request through the client's chained policies.


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

activate

Activate Event.

Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be expected for it.

activate(event_id: str, **kwargs: Any) -> None

Parameters

Name Description
event_id
Required
str

The event ID to be activated. Required.

Returns

Type Description

None

Exceptions

Type Description

activate_multi_slot

Activate Event (MultiSlot).

Report that the specified event was actually used or displayed to the user and a rewards should be expected for it.

activate_multi_slot(event_id: str, **kwargs: Any) -> None

Parameters

Name Description
event_id
Required
str

The event ID this activation applies to. Required.

Returns

Type Description

None

Exceptions

Type Description

close

close() -> None

Exceptions

Type Description

rank

Rank.

Submit a Personalizer rank request. Receives a context and a list of actions. Returns which of the provided actions should be used by your application, in rewardActionId.

rank(rank_request: MutableMapping[str, Any] | IO, **kwargs: Any) -> MutableMapping[str, Any]

Parameters

Name Description
rank_request
Required
<xref:JSON> or IO

A Personalizer Rank request. Required.

Keyword-Only Parameters

Name Description
content_type
str

Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json".

Returns

Type Description
<xref:JSON>

JSON object

Exceptions

Type Description

Examples


   # JSON input template you can fill out and use as your body input.
   rank_request = {
       "actions": [
           {
               "features": [
                   {}  # List of dictionaries containing features.
                     Required.
               ],
               "id": "str"  # Id of the action. Required.
           }
       ],
       "contextFeatures": [
           {}  # Optional. Features of the context used for Personalizer as
             a"ndictionary of dictionaries. This is determined by your application,
             and"ntypically includes features about the current user, their"ndevice,
             profile information, aggregated data about time and date, etc."nFeatures
             should not include personally identifiable information (PII),"nunique
             UserIDs, or precise timestamps.
       ],
       "deferActivation": False,  # Optional. Default value is False. Send false if
         it is certain the rewardActionId in rank results will be shown to the user,
         therefore"nPersonalizer will expect a Reward call, otherwise it will assign the
         default"nReward to the event. Send true if it is possible the user will not see
         the action specified in the rank results,"n(e.g. because the page is rendering
         later, or the Rank results may be overridden by code further downstream)."nYou
         must call the Activate Event API if the event output is shown to users, otherwise
         Rewards will be ignored.
       "eventId": "str",  # Optional. Optionally pass an eventId that uniquely
         identifies this Rank event."nIf null, the service generates a unique eventId. The
         eventId will be used for"nassociating this request with its reward, as well as
         seeding the pseudo-random"ngenerator when making a Personalizer call.
       "excludedActions": [
           "str"  # Optional. The set of action ids to exclude from
             ranking."nPersonalizer will consider the first non-excluded item in the array
             as the Baseline action when performing Offline Evaluations.
       ]
   }

   # response body for status code(s): 201
   response == {
       "eventId": "str",  # The eventId for the round trip from request to response.
         Required.
       "ranking": [
           {
               "id": "str",  # Optional. Id of the action.
               "probability": 0.0  # Optional. Probability of the action.
           }
       ],
       "rewardActionId": "str"  # Optional. The action chosen by the Personalizer
         service."nThis is the action your application should display, and for which to
         report the reward."nThis might not be the first found in 'ranking'.
   }

rank_multi_slot

Rank (MultiSlot).

Submit a Personalizer multi-slot rank request. Receives a context, a list of actions, and a list of slots. Returns which of the provided actions should be used in each slot, in each rewardActionId.

rank_multi_slot(body: MutableMapping[str, Any] | IO, **kwargs: Any) -> MutableMapping[str, Any]

Parameters

Name Description
body
Required
<xref:JSON> or IO

A Personalizer multi-slot Rank request. Required.

Keyword-Only Parameters

Name Description
content_type
str

Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json".

Returns

Type Description
<xref:JSON>

JSON object

Exceptions

Type Description

Examples


   # JSON input template you can fill out and use as your body input.
   body = {
       "actions": [
           {
               "features": [
                   {}  # List of dictionaries containing features.
                     Required.
               ],
               "id": "str"  # Id of the action. Required.
           }
       ],
       "slots": [
           {
               "baselineAction": "str",  # The 'baseline action' ID for the
                 slot."nThe BaselineAction is the Id of the Action your application would
                 use in that slot if Personalizer didn't exist."nBaselineAction must be
                 defined for every slot."nBaselineAction should never be part of
                 ExcludedActions."nEach slot must have a unique BaselineAction which
                 corresponds to an an action from the event's Actions list. Required.
               "id": "str",  # Slot ID. Required.
               "excludedActions": [
                   "str"  # Optional. List of excluded action Ids.
               ],
               "features": [
                   {}  # Optional. List of dictionaries containing slot
                     features.
               ]
           }
       ],
       "contextFeatures": [
           {}  # Optional. Features of the context used for Personalizer as
             a"ndictionary of dictionaries. This is determined by your application,
             and"ntypically includes features about the current user, their"ndevice,
             profile information, aggregated data about time and date, etc."nFeatures
             should not include personally identifiable information (PII),"nunique
             UserIDs, or precise timestamps.
       ],
       "deferActivation": False,  # Optional. Default value is False. Send false if
         it is certain the rewardActionId in rank results will be shown to the user,
         therefore"nPersonalizer will expect a Reward call, otherwise it will assign the
         default"nReward to the event. Send true if it is possible the user will not see
         the action specified in the rank results,"n(e.g. because the page is rendering
         later, or the Rank results may be overridden by code further downstream)."nYou
         must call the Activate Event API if the event output is shown to users, otherwise
         Rewards will be ignored.
       "eventId": "str"  # Optional. Optionally pass an eventId that uniquely
         identifies this Rank event."nIf null, the service generates a unique eventId. The
         eventId will be used for"nassociating this request with its reward, as well as
         seeding the pseudo-random"ngenerator when making a Personalizer call.
   }

   # response body for status code(s): 201
   response == {
       "eventId": "str",  # The eventId for the round trip from request to response.
         Required.
       "slots": [
           {
               "id": "str",  # Id is the slot ID. Required.
               "rewardActionId": "str"  # Optional. RewardActionID is the
                 action ID recommended by Personalizer.
           }
       ]
   }

reward

Reward.

Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the specified event.

reward(event_id: str, reward: MutableMapping[str, Any] | IO, **kwargs: Any) -> None

Parameters

Name Description
event_id
Required
str

The event id this reward applies to. Required.

reward
Required
<xref:JSON> or IO

The reward should be a floating point number, typically between 0 and 1. Required.

Keyword-Only Parameters

Name Description
content_type
str

Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json".

Returns

Type Description

None

Exceptions

Type Description

Examples


   # JSON input template you can fill out and use as your body input.
   reward = {
       "value": 0.0  # Reward to be assigned to an action. Value is a float
         calculated by your application, typically between 0 and 1, and must be between -1
         and 1. Required.
   }

reward_multi_slot

Reward (MultiSlot).

Report reward that resulted from using the action specified in rewardActionId for the slot.

reward_multi_slot(event_id: str, body: MutableMapping[str, Any] | IO, **kwargs: Any) -> None

Parameters

Name Description
event_id
Required
str

The event id this reward applies to. Required.

body
Required
<xref:JSON> or IO

List of slot id and reward values. The reward should be a floating point number, typically between 0 and 1. Required.

Keyword-Only Parameters

Name Description
content_type
str

Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json".

Returns

Type Description

None

Exceptions

Type Description

Examples


   # JSON input template you can fill out and use as your body input.
   body = {
       "reward": [
           {
               "slotId": "str",  # Slot id for which we are sending the
                 reward. Required.
               "value": 0.0  # Reward to be assigned to slotId. Value should
                 be between -1 and 1 inclusive. Required.
           }
       ]
   }

send_request

Runs the network request through the client's chained policies.


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

send_request(request: HttpRequest, **kwargs: Any) -> HttpResponse

Parameters

Name Description
request
Required

The network request you want to make. Required.

Keyword-Only Parameters

Name Description
stream

Whether the response payload will be streamed. Defaults to False.

Returns

Type Description

The response of your network call. Does not do error handling on your response.

Exceptions

Type Description