Skip to content

Latest commit

 

History

History

HttpRequestFeatures

About this sample

This sample extracts HTTP request features and adds them as context features to a Rank request that can be sent to an Azure Personalizer instance. After this request is sent, the user has the option to send a followup Reward request and then generate a new Rank request.

This is a ASP.NET Core MVC with Knockout.js solution. When run, it displays a single page with the Rank request, Reward request, and HTTP request features shown. Pressing the Send Rank Request button sends a rank request to your Personalizer instance with HTTP information gathered from the featurizer as part of the context features. Once sent, the Send Reward Request button can be pressed in order to send a corresponding reward. At any time, you can press the Generate new Rank Request button to create a new Rank request.

To try this sample

Prerequisites

Set up the sample

  • Clone the Azure Personalizer Samples repo.

    git clone https://github.com/Azure-Samples/cognitive-services-personalizer-samples.git
  • Navigate to samples/HttpRequestFeatures.

  • Open HttpRequestFeaturesExample.sln.

Set up Azure Personalizer Service

  • Create a Personalizer instance in the Azure portal.

  • In the Azure portal, find the Endpoint and either Key1 or Key2 (either will work) in the Keys and Endpoints tab. These are your PersonalizerServiceEndpoint and your PersonalizerApiKey, respectively. Fill in the PersonalizerServiceEndpoint in appsettings.json. Configure the PersonalizerApiKey as an app secrets in one of the following ways:

    If you are using the .NET Core CLI, you can use the dotnet user-secrets set "PersonalizerApiKey" "<API Key>" command. If you are using Visual Studio, you can right-click the project and select the Manage User Secrets menu option to configure the Personalizer keys. By doing this, Visual Studio will open a secrets.json file where you can add the keys as follows:

{
  "PersonalizerApiKey": "<your personalizer key here>",
}

Run the sample

Build and run HttpRequestFeaturesExample. Press F5 if using Visual Studio, or dotnet build then dotnet run if using .NET Core CLI. Through the UI, you will be able to send a Rank request and a Reward request and see their responses, as well as the http request features extracted from your environment.