azure.ai.personalizer package

class azure.ai.personalizer.PersonalizerAdministrationClient(endpoint: str, credential: Union[azure.core.credentials.AzureKeyCredential, azure.core.credentials.TokenCredential], **kwargs: Any)[source]

This client contains the operations that apply to Azure Personalizer. Operations allowed by the client are viewing and editing the properties, policy, model, running evaluations.

Parameters
  • endpoint (str) – Supported Cognitive Services endpoint. Required.

  • credential (AzureKeyCredential or TokenCredential) – Credential needed for the client to connect to Azure. Required.

Keyword Arguments

api_version (str) – Api Version. Default value is “2022-09-01-preview”. Note that overriding this default value may result in unsupported behavior.

apply_from_evaluation(body: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)None[source]

Apply Learning Settings and Model.

Apply Learning Settings and model from a pre-existing Offline Evaluation, making them the current online Learning Settings and model and replacing the previous ones.

Parameters

body (JSON or IO) – Reference to the policy within the evaluation. Required.

Keyword Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

None

Return type

None

Raises

HttpResponseError

Example

# JSON input template you can fill out and use as your body input.
body = {
    "evaluationId": "str",  # Evaluation Id of the evaluation. Required.
    "policyName": "str"  # Name of the learning settings. Required.
}
close()None[source]
create_evaluation(evaluation_id: str, evaluation: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)None[source]

Create Offline Evaluation.

Submit a new Offline Evaluation job.

Parameters
  • evaluation_id (str) – Id of the Offline Evaluation to create. Required.

  • evaluation (JSON or IO) – The Offline Evaluation job definition. Required.

Keyword Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

None

Return type

None

Raises

HttpResponseError

Example

# JSON input template you can fill out and use as your body input.
evaluation = {
    "endTime": "2020-02-20 00:00:00",  # The end time of the evaluation.
      Required.
    "name": "str",  # The name of the evaluation. Required.
    "startTime": "2020-02-20 00:00:00",  # The start time of the evaluation.
      Required.
    "enablePolicyOptimization": bool,  # Optional. True if the evaluation should
      explore for a more optimal learning settings.
    "policies": [
        {
            "arguments": "str",  # Arguments of the learning settings.
              Required.
            "name": "str"  # Name of the learning settings. Required.
        }
    ]
}
create_feature_importance(feature_importance_id: str, feature_importance: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)None[source]

Create Feature Importance.

Submit a new Feature Importance job.

Parameters
  • feature_importance_id (str) – Id of the Feature Importance to create. Required.

  • feature_importance (JSON or IO) – The Feature Importance job definition. Required.

Keyword Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

None

Return type

None

Raises

HttpResponseError

Example

# JSON input template you can fill out and use as your body input.
feature_importance = {
    "endTime": "2020-02-20 00:00:00",  # The end time of the feature importance.
      Required.
    "name": "str",  # The name of the feature importance. Required.
    "startTime": "2020-02-20 00:00:00"  # The start time of the feature
      importance. Required.
}
delete_evaluation(evaluation_id: str, **kwargs: Any)None[source]

Offline Evaluation.

Delete the Offline Evaluation associated with the Id.

Parameters

evaluation_id (str) – Id of the Offline Evaluation to delete. Required.

Returns

None

Return type

None

Raises

HttpResponseError

delete_feature_importance(feature_importance_id: str, **kwargs: Any)None[source]

Feature Importance.

Delete the Feature Importance associated with the Id.

Parameters

feature_importance_id (str) – Id of the Feature Importance to delete. Required.

Returns

None

Return type

None

Raises

HttpResponseError

delete_logs(**kwargs: Any)None[source]

Logs.

Delete all logs of Rank and Reward calls stored by Personalizer.

Returns

None

Return type

None

Raises

HttpResponseError

export_model(*, signed: bool = False, **kwargs: Any)Iterator[bytes][source]

Model.

Get the model file generated by Personalizer service.

Keyword Arguments

signed (bool) – True if requesting signed model zip archive, false otherwise. Default value is False.

Returns

Iterator of the response bytes

Return type

Iterator[bytes]

Raises

HttpResponseError

get_evaluation(evaluation_id: str, *, start_time: datetime.datetime, end_time: datetime.datetime, interval_in_minutes: Optional[int] = None, window: Optional[str] = None, **kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Offline Evaluation.

Get the Offline Evaluation associated with the Id.

Parameters

evaluation_id (str) – Id of the Offline Evaluation. Required.

Keyword Arguments
  • start_time (datetime) – Start of aggregation time interval. Required.

  • end_time (datetime) – End of aggregation time interval. Required.

  • interval_in_minutes (int) – “Time interval for aggregation of events in minutes. Allowed intervals: 5 minutes, 60 minutes, 360 minutes, 720 minutes and 1440 minutes. Defaults to 5 minutes. Default value is None.

  • window (str) – Rolling or Expanding time. Rolling compatible with 60 minutes, 360 minutes, 720 minutes and 1440 minutes intervals. Expanding compatible with 5 minute time interval only. Defaults to Expanding. Known values are: “Expanding” and “Rolling”. Default value is None.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "creationTime": "2020-02-20 00:00:00",  # The creation time of the
      evaluation. Required.
    "endTime": "2020-02-20 00:00:00",  # The end time of the evaluation.
      Required.
    "evaluationType": "str",  # The type of evaluation. Required. Known values
      are: "Manual" and "Auto".
    "id": "str",  # The ID of the evaluation. Required.
    "name": "str",  # The name of the evaluation. Required.
    "startTime": "2020-02-20 00:00:00",  # The start time of the evaluation.
      Required.
    "status": "str",  # The status of the job processing the evaluation.
      Required. Known values are: "Succeeded", "Running", "Failed", "NotSubmitted",
      "Timeout", "OptimalPolicyApplied", "OnlinePolicyRetained", and "Canceled".
    "content": {
        "endTime": "2020-02-20 00:00:00",  # Optional. End time of the time
          series.
        "intervalInMinutes": 0,  # Optional. Aggregation window.
        "startTime": "2020-02-20 00:00:00",  # Optional. Start time of the
          time series.
        "value": [
            {
                "arguments": "str",  # Optional. The arguments of the
                  Learning Settings.
                "name": "str",  # Optional. The name of the Learning
                  Settings.
                "policySource": "str",  # Optional. The source of the
                  Learning Settings. Known values are: "Online", "Baseline", "Random",
                  "Custom", and "OfflineExperimentation".
                "slotId": "str",  # Optional. Slot id. Empty for
                  overall results and single slot results.
                "summary": {
                    "confidenceInterval": [
                        0.0  # Optional. Confidence interval.
                    ],
                    "expectedReward": 0.0  # Optional. Average
                      reward.
                },
                "timeseries": {
                    "data": [
                        {
                            "confidenceInterval": [
                                0.0  # Optional.
                                  Confidence interval.
                            ],
                            "expectedReward": 0.0,  #
                              Optional. Average reward.
                            "timeStamp": "2020-02-20
                              00:00:00"  # Optional. Timestamp of the aggregation.
                        }
                    ]
                }
            }
        ]
    },
    "description": "str",  # Optional. Description of the evaluation job.
    "optimalPolicy": "str"  # Optional. Optimal policy found by the evaluation
      job.
}
get_feature_importance(feature_importance_id: str, **kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Feature Importance.

Get the Feature Importance associated with the Id.

Parameters

feature_importance_id (str) – Id of the Feature Importance. Required.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "creationTime": "2020-02-20 00:00:00",  # Optional. The creation time of the
      feature importance.
    "description": "str",  # Optional. Description of the feature importance job.
    "endTime": "2020-02-20 00:00:00",  # Optional. The end time of the feature
      importance.
    "featureScores": [
        {
            "featureName": "str",  # Optional. Feature name.
            "namespace": "str",  # Optional. Feature namespace.
            "score": 0.0  # Optional. Feature score.
        }
    ],
    "id": "str",  # Optional. The ID of the feature importance.
    "name": "str",  # Optional. The name of the feature importance.
    "startTime": "2020-02-20 00:00:00",  # Optional. The start time of the
      feature importance.
    "status": "str"  # Optional. The status of the job processing the feature
      importance. Known values are: "Succeeded", "Running", "Failed", "NotSubmitted",
      "Timeout", and "Canceled".
}
get_log_properties(**kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Log Properties.

Get properties of the Personalizer logs.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "dateRange": {
        "from": "2020-02-20 00:00:00",  # Optional. Start date for the range.
        "to": "2020-02-20 00:00:00"  # Optional. End date for the range.
    }
}
get_model_properties(**kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Model Properties.

Get properties of the model file generated by Personalizer service.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "creationTime": "2020-02-20 00:00:00",  # Optional. Creation time of the
      model.
    "lastModifiedTime": "2020-02-20 00:00:00"  # Optional. Last time the model
      was modified.
}
get_policy(**kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Policy.

Get the Learning Settings currently used by the Personalizer service.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "arguments": "str",  # Arguments of the learning settings. Required.
    "name": "str"  # Name of the learning settings. Required.
}
get_service_configuration(**kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Service Configuration.

Get the Personalizer service configuration.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "defaultReward": 0.0,  # The reward given if a reward is not received within
      the specified wait time. Required.
    "explorationPercentage": 0.0,  # The percentage of rank responses that will
      use exploration. Required.
    "logRetentionDays": 0,  # Number of days historical logs are to be
      maintained. -1 implies the logs will never be deleted. Required.
    "modelExportFrequency": "1 day, 0:00:00",  # Personalizer will start using
      the most updated trained model for online ranks automatically every specified
      time period."nFor example, PT5M (5 mins). For information about the time
      format,"nsee http://en.wikipedia.org/wiki/ISO_8601#Durations. Required.
    "modelRetrainDays": 0,  # Default value is 0. Number of days of historical
      logs used when a model retrain is triggered. Required.
    "rewardAggregation": "str",  # The function used to process rewards, if
      multiple reward scores are received before rewardWaitTime is over. Required.
    "rewardWaitTime": "1 day, 0:00:00",  # The time span waited until a request
      is marked with the default reward"nand should be between 5 seconds and 2
      days."nFor example, PT5M (5 mins). For information about the time format,"nsee
      http://en.wikipedia.org/wiki/ISO_8601#Durations. Required.
    "autoOptimizationFrequency": "1 day, 0:00:00",  # Optional. Frequency of
      automatic optimization. Only relevant if IsAutoOptimizationEnabled is true."nFor
      example, PT5M (5 mins). For information about the time format,"n""r""nsee
      http://en.wikipedia.org/wiki/ISO_8601#Durations.
    "autoOptimizationStartDate": "2020-02-20 00:00:00",  # Optional. Date when
      the first automatic optimization evaluation must be performed. Only relevant if
      IsAutoOptimizationEnabled is true.
    "isAutoOptimizationEnabled": bool,  # Optional. Flag indicating whether
      Personalizer will automatically optimize Learning Settings by running Offline
      Evaluations periodically.
    "lastConfigurationEditDate": "2020-02-20 00:00:00",  # Optional. Last time
      model training configuration was updated.
    "latestApprenticeModeMetrics": {
        "lastProcessedEventTime": "2020-02-20 00:00:00",  # Required.
        "numberOfEvents": 0,  # Required.
        "numberOfImitatedEvents": 0,  # Required.
        "startTime": "2020-02-20 00:00:00",  # Required.
        "sumOfImitatedRewards": 0.0,  # Required.
        "sumOfRewards": 0.0,  # Required.
        "lastBatchMetrics": {
            "numberOfEvents": 0,  # Required.
            "numberOfImitatedEvents": 0,  # Required.
            "sumOfImitatedRewards": 0.0,  # Required.
            "sumOfRewards": 0.0  # Required.
        }
    },
    "learningMode": "str",  # Optional. Learning Modes for Personalizer. Known
      values are: "Online", "Apprentice", and "LoggingOnly".
    "logMirrorEnabled": bool,  # Optional. Flag indicates whether log mirroring
      is enabled.
    "logMirrorSasUri": "str"  # Optional. Azure storage account container SAS URI
      for log mirroring.
}
import_model(body: IO, **kwargs: Any)None[source]

Model File.

Replace the existing model file for the Personalizer service.

Parameters

body (IO) – The digitally signed model file obtained from getting the model. Required.

Returns

None

Return type

None

Raises

HttpResponseError

list_evaluations(*, filter_expression: Optional[str] = None, top: Optional[int] = None, skip: int = 0, **kwargs: Any)Iterable[collections.abc.MutableMapping[str, Any]][source]

All Offline Evaluations.

List of all Offline Evaluations.

Keyword Arguments
  • filter_expression (str) – An expression to filter the evaluations against evaluation metadata. Only evaluations where the expression evaluates to true are included in the response. Here is an example, metadata=evaluationType eq ‘Manual’. Default value is None.

  • top (int) – The maximum number of resources to return from the collection. Defaults to maximum value of integer. Default value is None.

  • skip (int) – An offset into the collection of the first resource to be returned. Defaults to 0. Default value is 0.

Returns

An iterator like instance of JSON object

Return type

ItemPaged[JSON]

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "creationTime": "2020-02-20 00:00:00",  # The creation time of the
      evaluation. Required.
    "endTime": "2020-02-20 00:00:00",  # The end time of the evaluation.
      Required.
    "evaluationType": "str",  # Type of evaluation. Required. Known values are:
      "Manual" and "Auto".
    "id": "str",  # The ID of the evaluation. Required.
    "name": "str",  # The name of the evaluation. Required.
    "startTime": "2020-02-20 00:00:00",  # The start time of the evaluation.
      Required.
    "status": "str"  # The status of the job processing the evaluation. Required.
      Known values are: "Succeeded", "Running", "Failed", "NotSubmitted", "Timeout",
      "OptimalPolicyApplied", "OnlinePolicyRetained", and "Canceled".
}
list_feature_importances(*, top: Optional[int] = None, skip: int = 0, **kwargs: Any)Iterable[collections.abc.MutableMapping[str, Any]][source]

All Feature Importances.

List of all Feature Importances.

Keyword Arguments
  • top (int) – The maximum number of resources to return from the collection. Defaults to maximum value of integer. Default value is None.

  • skip (int) – An offset into the collection of the first resource to be returned. Defaults to 0. Default value is 0.

Returns

An iterator like instance of JSON object

Return type

ItemPaged[JSON]

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "creationTime": "2020-02-20 00:00:00",  # Required.
    "endTime": "2020-02-20 00:00:00",  # Required.
    "id": "str",  # Required.
    "name": "str",  # Required.
    "startTime": "2020-02-20 00:00:00",  # Required.
    "status": "str"  # The status of the feature importance job. Required. Known
      values are: "Succeeded", "Running", "Failed", "NotSubmitted", "Timeout", and
      "Canceled".
}
reset_model(**kwargs: Any)None[source]

Reset Model.

Resets the model file generated by Personalizer service.

Returns

None

Return type

None

Raises

HttpResponseError

reset_policy(**kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Reset Policy.

Resets the learning settings of the Personalizer service to default.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# response body for status code(s): 200
response == {
    "arguments": "str",  # Arguments of the learning settings. Required.
    "name": "str"  # Name of the learning settings. Required.
}
send_request(request: azure.core.rest._rest_py3.HttpRequest, **kwargs: Any)azure.core.rest._rest_py3.HttpResponse[source]

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

Parameters

request (HttpRequest) – The network request you want to make. Required.

Keyword Arguments

stream (bool) – Whether the response payload will be streamed. Defaults to False.

Returns

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

Return type

HttpResponse

update_policy(policy: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Update Policy.

Update the Learning Settings that the Personalizer service will use to train models.

Parameters

policy (JSON or IO) – The learning settings. Required.

Keyword Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# JSON input template you can fill out and use as your body input.
policy = {
    "arguments": "str",  # Arguments of the learning settings. Required.
    "name": "str"  # Name of the learning settings. Required.
}

# response body for status code(s): 200
response == {
    "arguments": "str",  # Arguments of the learning settings. Required.
    "name": "str"  # Name of the learning settings. Required.
}
update_service_configuration(config: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)collections.abc.MutableMapping[str, Any][source]

Update Service Configuration.

Update the Personalizer service configuration.

Parameters

config (JSON or IO) – The personalizer service configuration. Required.

Keyword Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# JSON input template you can fill out and use as your body input.
config = {
    "defaultReward": 0.0,  # The reward given if a reward is not received within
      the specified wait time. Required.
    "explorationPercentage": 0.0,  # The percentage of rank responses that will
      use exploration. Required.
    "logRetentionDays": 0,  # Number of days historical logs are to be
      maintained. -1 implies the logs will never be deleted. Required.
    "modelExportFrequency": "1 day, 0:00:00",  # Personalizer will start using
      the most updated trained model for online ranks automatically every specified
      time period."nFor example, PT5M (5 mins). For information about the time
      format,"nsee http://en.wikipedia.org/wiki/ISO_8601#Durations. Required.
    "modelRetrainDays": 0,  # Default value is 0. Number of days of historical
      logs used when a model retrain is triggered. Required.
    "rewardAggregation": "str",  # The function used to process rewards, if
      multiple reward scores are received before rewardWaitTime is over. Required.
    "rewardWaitTime": "1 day, 0:00:00",  # The time span waited until a request
      is marked with the default reward"nand should be between 5 seconds and 2
      days."nFor example, PT5M (5 mins). For information about the time format,"nsee
      http://en.wikipedia.org/wiki/ISO_8601#Durations. Required.
    "autoOptimizationFrequency": "1 day, 0:00:00",  # Optional. Frequency of
      automatic optimization. Only relevant if IsAutoOptimizationEnabled is true."nFor
      example, PT5M (5 mins). For information about the time format,"n""r""nsee
      http://en.wikipedia.org/wiki/ISO_8601#Durations.
    "autoOptimizationStartDate": "2020-02-20 00:00:00",  # Optional. Date when
      the first automatic optimization evaluation must be performed. Only relevant if
      IsAutoOptimizationEnabled is true.
    "isAutoOptimizationEnabled": bool,  # Optional. Flag indicating whether
      Personalizer will automatically optimize Learning Settings by running Offline
      Evaluations periodically.
    "lastConfigurationEditDate": "2020-02-20 00:00:00",  # Optional. Last time
      model training configuration was updated.
    "latestApprenticeModeMetrics": {
        "lastProcessedEventTime": "2020-02-20 00:00:00",  # Required.
        "numberOfEvents": 0,  # Required.
        "numberOfImitatedEvents": 0,  # Required.
        "startTime": "2020-02-20 00:00:00",  # Required.
        "sumOfImitatedRewards": 0.0,  # Required.
        "sumOfRewards": 0.0,  # Required.
        "lastBatchMetrics": {
            "numberOfEvents": 0,  # Required.
            "numberOfImitatedEvents": 0,  # Required.
            "sumOfImitatedRewards": 0.0,  # Required.
            "sumOfRewards": 0.0  # Required.
        }
    },
    "learningMode": "str",  # Optional. Learning Modes for Personalizer. Known
      values are: "Online", "Apprentice", and "LoggingOnly".
    "logMirrorEnabled": bool,  # Optional. Flag indicates whether log mirroring
      is enabled.
    "logMirrorSasUri": "str"  # Optional. Azure storage account container SAS URI
      for log mirroring.
}

# response body for status code(s): 200
response == {
    "defaultReward": 0.0,  # The reward given if a reward is not received within
      the specified wait time. Required.
    "explorationPercentage": 0.0,  # The percentage of rank responses that will
      use exploration. Required.
    "logRetentionDays": 0,  # Number of days historical logs are to be
      maintained. -1 implies the logs will never be deleted. Required.
    "modelExportFrequency": "1 day, 0:00:00",  # Personalizer will start using
      the most updated trained model for online ranks automatically every specified
      time period."nFor example, PT5M (5 mins). For information about the time
      format,"nsee http://en.wikipedia.org/wiki/ISO_8601#Durations. Required.
    "modelRetrainDays": 0,  # Default value is 0. Number of days of historical
      logs used when a model retrain is triggered. Required.
    "rewardAggregation": "str",  # The function used to process rewards, if
      multiple reward scores are received before rewardWaitTime is over. Required.
    "rewardWaitTime": "1 day, 0:00:00",  # The time span waited until a request
      is marked with the default reward"nand should be between 5 seconds and 2
      days."nFor example, PT5M (5 mins). For information about the time format,"nsee
      http://en.wikipedia.org/wiki/ISO_8601#Durations. Required.
    "autoOptimizationFrequency": "1 day, 0:00:00",  # Optional. Frequency of
      automatic optimization. Only relevant if IsAutoOptimizationEnabled is true."nFor
      example, PT5M (5 mins). For information about the time format,"n""r""nsee
      http://en.wikipedia.org/wiki/ISO_8601#Durations.
    "autoOptimizationStartDate": "2020-02-20 00:00:00",  # Optional. Date when
      the first automatic optimization evaluation must be performed. Only relevant if
      IsAutoOptimizationEnabled is true.
    "isAutoOptimizationEnabled": bool,  # Optional. Flag indicating whether
      Personalizer will automatically optimize Learning Settings by running Offline
      Evaluations periodically.
    "lastConfigurationEditDate": "2020-02-20 00:00:00",  # Optional. Last time
      model training configuration was updated.
    "latestApprenticeModeMetrics": {
        "lastProcessedEventTime": "2020-02-20 00:00:00",  # Required.
        "numberOfEvents": 0,  # Required.
        "numberOfImitatedEvents": 0,  # Required.
        "startTime": "2020-02-20 00:00:00",  # Required.
        "sumOfImitatedRewards": 0.0,  # Required.
        "sumOfRewards": 0.0,  # Required.
        "lastBatchMetrics": {
            "numberOfEvents": 0,  # Required.
            "numberOfImitatedEvents": 0,  # Required.
            "sumOfImitatedRewards": 0.0,  # Required.
            "sumOfRewards": 0.0  # Required.
        }
    },
    "learningMode": "str",  # Optional. Learning Modes for Personalizer. Known
      values are: "Online", "Apprentice", and "LoggingOnly".
    "logMirrorEnabled": bool,  # Optional. Flag indicates whether log mirroring
      is enabled.
    "logMirrorSasUri": "str"  # Optional. Azure storage account container SAS URI
      for log mirroring.
}
class azure.ai.personalizer.PersonalizerClient(endpoint: str, credential: Union[azure.core.credentials.AzureKeyCredential, azure.core.credentials.TokenCredential], **kwargs: Any)[source]

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.

Parameters
  • endpoint (str) – Supported Cognitive Services endpoint. Required.

  • credential (AzureKeyCredential or TokenCredential) – Credential needed for the client to connect to Azure. Required.

Keyword Arguments

api_version (str) – Api Version. Default value is “2022-09-01-preview”. Note that overriding this default value may result in unsupported behavior.

activate(event_id: str, **kwargs: Any)None[source]

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.

Parameters

event_id (str) – The event ID to be activated. Required.

Returns

None

Return type

None

Raises

HttpResponseError

activate_multi_slot(event_id: str, **kwargs: Any)None[source]

Activate Event (MultiSlot).

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

Parameters

event_id (str) – The event ID this activation applies to. Required.

Returns

None

Return type

None

Raises

HttpResponseError

close()None[source]
rank(rank_request: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)collections.abc.MutableMapping[str, Any][source]

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.

Parameters

rank_request (JSON or IO) – A Personalizer Rank request. Required.

Keyword Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# 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(body: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)collections.abc.MutableMapping[str, Any][source]

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.

Parameters

body (JSON or IO) – A Personalizer multi-slot Rank request. Required.

Keyword Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

JSON object

Return type

JSON

Raises

HttpResponseError

Example

# 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(event_id: str, reward: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)None[source]

Reward.

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

Parameters
  • event_id (str) – The event id this reward applies to. Required.

  • reward (JSON or IO) – The reward should be a floating point number, typically between 0 and 1. Required.

Keyword Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

None

Return type

None

Raises

HttpResponseError

Example

# 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(event_id: str, body: Union[collections.abc.MutableMapping[str, Any], IO], **kwargs: Any)None[source]

Reward (MultiSlot).

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

Parameters
  • event_id (str) – The event id this reward applies to. Required.

  • body (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 Arguments

content_type (str) – Body Parameter content-type. Content type parameter for JSON body. Default value is “application/json”.

Returns

None

Return type

None

Raises

HttpResponseError

Example

# 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(request: azure.core.rest._rest_py3.HttpRequest, **kwargs: Any)azure.core.rest._rest_py3.HttpResponse[source]

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

Parameters

request (HttpRequest) – The network request you want to make. Required.

Keyword Arguments

stream (bool) – Whether the response payload will be streamed. Defaults to False.

Returns

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

Return type

HttpResponse