Ejemplo n.º 1
0
        // </classVariables>

        // <mainLoop>
        static void Main(string[] args)
        {
            Console.WriteLine($"Welcome to this Personalizer Quickstart!\n" +
                              $"This code will help you understand how to use the Personalizer APIs (multislot rank and multislot reward).\n" +
                              $"Each iteration represents a user interaction and will demonstrate how context, actions, slots, and rewards work.\n" +
                              $"Note: Personalizer AI models learn from a large number of user interactions:\n" +
                              $"You won't be able to tell the difference in what Personalizer returns by simulating a few events by hand.\n" +
                              $"If you want a sample that focuses on seeing how Personalizer learns, see the Python Notebook sample.");

            int  iteration = 1;
            bool runLoop   = true;

            IList <PersonalizerRankableAction> actions = GetActions();
            IList <PersonalizerSlotOptions>    slots   = GetSlots();
            PersonalizerClient client = InitializePersonalizerClient(new Uri(ServiceEndpoint));

            do
            {
                Console.WriteLine("\nIteration: " + iteration++);

                string timeOfDayFeature = GetTimeOfDayForContext();
                string deviceFeature    = GetDeviceForContext();

                IList <object> currentContext = GetContext(timeOfDayFeature, deviceFeature);

                string eventId = Guid.NewGuid().ToString();

                var multiSlotRankOptions = new PersonalizerRankMultiSlotOptions(actions, slots, currentContext, eventId);
                PersonalizerMultiSlotRankResult multiSlotRankResult = client.RankMultiSlot(multiSlotRankOptions);

                for (int i = 0; i < multiSlotRankResult.Slots.Count(); ++i)
                {
                    string slotId = multiSlotRankResult.Slots[i].SlotId;
                    Console.WriteLine($"\nPersonalizer service decided you should display: { multiSlotRankResult.Slots[i].RewardActionId} in slot {slotId}. Is this correct? (y/n)");

                    string answer = GetKey();

                    if (answer == "Y")
                    {
                        client.RewardMultiSlot(eventId, slotId, 1f);
                        Console.WriteLine("\nGreat! The application will send Personalizer a reward of 1 so it learns from this choice of action for this slot.");
                    }
                    else if (answer == "N")
                    {
                        client.RewardMultiSlot(eventId, slotId, 0f);
                        Console.WriteLine("\nYou didn't like the recommended item. The application will send Personalizer a reward of 0 for this choice of action for this slot.");
                    }
                    else
                    {
                        client.RewardMultiSlot(eventId, slotId, 0f);
                        Console.WriteLine("\nEntered choice is invalid. Service assumes that you didn't like the recommended item.");
                    }
                }

                Console.WriteLine("\nPress q to break, any other key to continue:");
                runLoop = !(GetKey() == "Q");
            } while (runLoop);
        }
Ejemplo n.º 2
0
        public void ExtractBaselineActionsFromRankRequestTest()
        {
            PersonalizerRankMultiSlotOptions request = new PersonalizerRankMultiSlotOptions(
                MultiSlotTests.actions, MultiSlotTests.slots, MultiSlotTests.contextFeatures, "testEventId");

            int[] baselineActions = RlObjectConverter.ExtractBaselineActionsFromRankRequest(request);
            Assert.AreEqual(2, baselineActions.Length);
            Assert.AreEqual(0, baselineActions[0]);
            Assert.AreEqual(1, baselineActions[1]);
        }
Ejemplo n.º 3
0
        private async Task RankMultiSlotNullParameters(PersonalizerClient client)
        {
            PersonalizerRankMultiSlotOptions request = new PersonalizerRankMultiSlotOptions(actions, slots);
            // Action
            PersonalizerMultiSlotRankResult response = await client.RankMultiSlotAsync(request);

            // Assert
            Assert.AreEqual(slots.Count, response.Slots.Count);
            // Assertions for first slot
            PersonalizerSlotResult responseSlot1 = response.Slots[0];

            Assert.AreEqual(slot1.Id, responseSlot1.SlotId);
            Assert.AreEqual("NewsArticle", responseSlot1.RewardActionId);
            // Assertions for second slot
            PersonalizerSlotResult responseSlot2 = response.Slots[1];

            Assert.AreEqual(slot2.Id, responseSlot2.SlotId);
            Assert.AreEqual("SportsArticle", responseSlot2.RewardActionId);
        }
Ejemplo n.º 4
0
        private async Task RankMultiSlot(PersonalizerClient client)
        {
            string eventId = "sdkTestEventId";
            PersonalizerRankMultiSlotOptions request = new PersonalizerRankMultiSlotOptions(actions, slots, contextFeatures, eventId);
            // Action
            PersonalizerMultiSlotRankResult response = await client.RankMultiSlotAsync(request);

            // Assert
            Assert.AreEqual(slots.Count, response.Slots.Count);
            // Assertions for first slot
            PersonalizerSlotResult responseSlot1 = response.Slots[0];

            Assert.AreEqual(slot1.Id, responseSlot1.SlotId);
            Assert.AreEqual("NewsArticle", responseSlot1.RewardActionId);
            // Assertions for second slot
            PersonalizerSlotResult responseSlot2 = response.Slots[1];

            Assert.AreEqual(slot2.Id, responseSlot2.SlotId);
            Assert.AreEqual("SportsArticle", responseSlot2.RewardActionId);
        }