From 2357e82ae320532b2f5e0f7b673dd83073c8e029 Mon Sep 17 00:00:00 2001 From: Jacob Dubin Date: Fri, 22 May 2026 07:37:22 -0500 Subject: [PATCH] Randomize how are you replies --- .../Services/ChitchatStateMachine.cs | 17 +++++++++++------ .../InMemoryJiboExperienceContentRepository.cs | 4 +++- .../WebSockets/JiboInteractionServiceTests.cs | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/ChitchatStateMachine.cs b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/ChitchatStateMachine.cs index 134996c..2899bd9 100644 --- a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/ChitchatStateMachine.cs +++ b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/ChitchatStateMachine.cs @@ -399,13 +399,18 @@ internal static class ChitchatStateMachine string? currentEmotion, string? preferredName) { - if (catalog.EmotionReplies.Count == 0) - return PersonalizeHowAreYouReply(randomizer.Choose(catalog.HowAreYouReplies), preferredName); + if (catalog.EmotionReplies.Count > 0) + { + var emotionVariants = ResolveEmotionVariants(currentEmotion); + var matchingReplies = catalog.EmotionReplies + .Where(reply => ConditionMatches(reply.Condition, emotionVariants)) + .Select(reply => reply.Reply) + .Where(reply => !string.IsNullOrWhiteSpace(reply)) + .ToArray(); - var emotionVariants = ResolveEmotionVariants(currentEmotion); - foreach (var reply in catalog.EmotionReplies) - if (ConditionMatches(reply.Condition, emotionVariants)) - return PersonalizeHowAreYouReply(reply.Reply, preferredName); + if (matchingReplies.Length > 0) + return PersonalizeHowAreYouReply(randomizer.Choose(matchingReplies), preferredName); + } return PersonalizeHowAreYouReply(randomizer.Choose(catalog.HowAreYouReplies), preferredName); } diff --git a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Infrastructure/Content/InMemoryJiboExperienceContentRepository.cs b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Infrastructure/Content/InMemoryJiboExperienceContentRepository.cs index 980b02d..45dd475 100644 --- a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Infrastructure/Content/InMemoryJiboExperienceContentRepository.cs +++ b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Infrastructure/Content/InMemoryJiboExperienceContentRepository.cs @@ -137,7 +137,9 @@ public sealed class InMemoryJiboExperienceContentRepository : IJiboExperienceCon "I am feeling bright-eyed and ready to help.", "I am having a pretty good day so far.", "I am feeling lively and ready for the next thing.", - "Things are going nicely. Thanks for checking in." + "Things are going nicely. Thanks for checking in.", + "I am running smoothly and feeling upbeat.", + "I am ready for the next thing. Thanks for asking." ], AgeReplies = [ diff --git a/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboInteractionServiceTests.cs b/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboInteractionServiceTests.cs index 285e785..ab61387 100644 --- a/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboInteractionServiceTests.cs +++ b/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboInteractionServiceTests.cs @@ -1040,6 +1040,21 @@ public sealed class JiboInteractionServiceTests Assert.Equal("All systems are go, Jake.", decision.ReplyText); } + [Fact] + public async Task BuildDecisionAsync_HowAreYou_CanSelectLaterEmotionReplyVariant() + { + var service = CreateService(randomizer: new LastItemRandomizer()); + + var decision = await service.BuildDecisionAsync(new TurnContext + { + RawTranscript = "how are you", + NormalizedTranscript = "how are you" + }); + + Assert.Equal("how_are_you", decision.IntentName); + Assert.Equal("Actually things are looking mostly sunny.", decision.ReplyText); + } + [Theory] [InlineData("what are you up to", "being helpful")] [InlineData("what are you doing", "making people smile")]