/// <summary> Report reward that resulted from using the action specified in rewardActionId for the slot. </summary>
        /// <param name="eventId"> The event id this reward applies to. </param>
        /// <param name="slotId"> Slot id for which we are sending the reward. </param>
        /// <param name="reward"> Reward to be assigned to slotId. Value should be between -1 and 1 inclusive. </param>
        /// <param name="cancellationToken"> The cancellation token to use. </param>
        public virtual async Task <Response> RewardMultiSlotAsync(string eventId, string slotId, float reward, CancellationToken cancellationToken = default)
        {
            PersonalizerRewardMultiSlotOptions options = new PersonalizerRewardMultiSlotOptions(new List <PersonalizerSlotReward> {
                new PersonalizerSlotReward(slotId, reward)
            });

            return(await RewardMultiSlotAsync(eventId, options, cancellationToken).ConfigureAwait(false));
        }
        /// <summary> Report reward that resulted from using the action specified in rewardActionId for the slot. </summary>
        /// <param name="eventId"> The event id this reward applies to. </param>
        /// <param name="slotId"> Slot id for which we are sending the reward. </param>
        /// <param name="reward"> Reward to be assigned to slotId. Value should be between -1 and 1 inclusive. </param>
        /// <param name="cancellationToken"> The cancellation token to use. </param>
        public virtual Response RewardMultiSlot(string eventId, string slotId, float reward, CancellationToken cancellationToken = default)
        {
            PersonalizerRewardMultiSlotOptions options = new PersonalizerRewardMultiSlotOptions(new List <PersonalizerSlotReward> {
                new PersonalizerSlotReward(slotId, reward)
            });

            return(RewardMultiSlot(eventId, options, cancellationToken));
        }
Ejemplo n.º 3
0
 public virtual async Task <Response> RewardAsync(string eventId, PersonalizerRewardMultiSlotOptions body, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("MultiSlotEventsClient.Reward");
     scope.Start();
     try
     {
         return(await RestClient.RewardAsync(eventId, body, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Ejemplo n.º 4
0
 public virtual Response Reward(string eventId, PersonalizerRewardMultiSlotOptions body, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("MultiSlotEventsClient.Reward");
     scope.Start();
     try
     {
         return(RestClient.Reward(eventId, body, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
 /// <summary> Report reward that resulted from using the action specified in rewardActionId for the slot. </summary>
 /// <param name="eventId"> The event id this reward applies to. </param>
 /// <param name="options"> List of slot id and reward values. The reward should be a floating point number, typically between 0 and 1. </param>
 /// <param name="cancellationToken"> The cancellation token to use. </param>
 public virtual Response RewardMultiSlot(string eventId, PersonalizerRewardMultiSlotOptions options, CancellationToken cancellationToken = default)
 {
     using var scope = clientDiagnostics.CreateScope("PersonalizerClient.RewardMultiSlot");
     scope.Start();
     try
     {
         if (useLocalInference)
         {
             validateAndUpdateLiveModelConfig();
             return(rlNetProcessor.Value.RewardMultiSlot(eventId, options.Reward));
         }
         else
         {
             return(MultiSlotEventsRestClient.Reward(eventId, options, cancellationToken));
         }
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
        public Response Reward(string eventId, PersonalizerRewardMultiSlotOptions body, CancellationToken cancellationToken = default)
        {
            if (eventId == null)
            {
                throw new ArgumentNullException(nameof(eventId));
            }
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            using var message = CreateRewardRequest(eventId, body);
            _pipeline.Send(message, cancellationToken);
            switch (message.Response.Status)
            {
            case 204:
                return(message.Response);

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
        internal HttpMessage CreateRewardRequest(string eventId, PersonalizerRewardMultiSlotOptions body)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Post;
            var uri = new RawRequestUriBuilder();

            uri.AppendRaw(endpoint, false);
            uri.AppendRaw("/personalizer/v1.1-preview.3", false);
            uri.AppendPath("/multislot/events/", false);
            uri.AppendPath(eventId, true);
            uri.AppendPath("/reward", false);
            request.Uri = uri;
            request.Headers.Add("Accept", "application/json");
            request.Headers.Add("Content-Type", "application/json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteObjectValue(body);
            request.Content = content;
            return(message);
        }