public virtual async Task <Response <PersonalizerPolicy> > UpdateAsync(PersonalizerPolicy policy, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("PolicyClient.Update");
     scope.Start();
     try
     {
         return(await RestClient.UpdateAsync(policy, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
 public virtual Response <PersonalizerPolicy> Update(PersonalizerPolicy policy, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("PolicyClient.Update");
     scope.Start();
     try
     {
         return(RestClient.Update(policy, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Example #3
0
        public async Task <Response <PersonalizerPolicy> > GetAsync(CancellationToken cancellationToken = default)
        {
            using var message = CreateGetRequest();
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            {
                PersonalizerPolicy value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = PersonalizerPolicy.DeserializePersonalizerPolicy(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }
        /// <summary> Gets the rank processor initiated with live model to use </summary>
        internal virtual RlNetProcessor GetConfigurationForRankProcessor(CancellationToken cancellationToken = default)
        {
            Configuration config = new Configuration();

            // set up the model
            if (azureKeyCredential != null)
            {
                config["http.api.key"] = azureKeyCredential.Key;
            }
            else if (tokenCredential != null)
            {
                var         tokenRequestContext = new TokenRequestContext(scopes);
                AccessToken token = tokenCredential.GetToken(tokenRequestContext, cancellationToken);
                config["http.api.key"]             = "Bearer " + token.Token;
                config["http.api.header.key.name"] = "Authorization";
                tokenExpiry = token.ExpiresOn;
            }
            else
            {
                throw new ApplicationException("PersonalizerClient is neither initalized with Token Credential nor with AzureKey Credential");
            }
            personalizerServiceProperties = ServiceConfigurationRestClient.Get(cancellationToken);
            personalizerPolicy            = PolicyRestClient.Get(cancellationToken);
            //interactions & observations
            config["interaction.http.api.host"]         = stringEndpoint + "personalizer/v1.1-preview.3/logs/interactions";
            config["observation.http.api.host"]         = stringEndpoint + "personalizer/v1.1-preview.3/logs/observations";
            config["interaction.sender.implementation"] = "INTERACTION_HTTP_API_SENDER";
            config["observation.sender.implementation"] = "OBSERVATION_HTTP_API_SENDER";
            config["interaction.subsample.rate"]        = Convert.ToString(this.subsampleRate, CultureInfo.InvariantCulture);
            config["observation.subsample.rate"]        = Convert.ToString(this.subsampleRate, CultureInfo.InvariantCulture);
            //model
            config["model.blob.uri"] = stringEndpoint + "personalizer/v1.1-preview.3/model";
            config["model.source"]   = "HTTP_MODEL_DATA";

            config["model.vw.initial_command_line"] = personalizerPolicy.Arguments;
            config["protocol.version"]            = "2";
            config["initial_exploration.epsilon"] = Convert.ToString(personalizerServiceProperties.ExplorationPercentage, CultureInfo.InvariantCulture);
            config["rank.learning.mode"]          = Convert.ToString(personalizerServiceProperties.LearningMode, CultureInfo.InvariantCulture);
            LiveModel liveModel = new LiveModel(config);

            liveModel.Init();
            LiveModelBase liveModelAdapter = new LiveModelAdapter(liveModel);

            liveModelLastRefresh = DateTimeOffset.UtcNow;
            return(new RlNetProcessor(liveModelAdapter));
        }