mirror of
https://kevinblog.sytes.net/Code/Jibo-Revival-Group/JiboExperiments.git
synced 2026-06-16 20:56:07 +00:00
Fix weather, yes/no, and news integrations
This commit is contained in:
@@ -1588,7 +1588,7 @@ public sealed class JiboInteractionServiceTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_ForecastWithoutDate_WithProvider_DefaultsToTomorrow()
|
||||
public async Task BuildDecisionAsync_ForecastWithoutDate_WithProvider_ReturnsFiveDaySummary()
|
||||
{
|
||||
var provider = new CapturingWeatherReportProvider
|
||||
{
|
||||
@@ -1599,14 +1599,21 @@ public sealed class JiboInteractionServiceTests
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "what's the forecast",
|
||||
NormalizedTranscript = "what's the forecast"
|
||||
NormalizedTranscript = "what's the forecast",
|
||||
Attributes = new Dictionary<string, object?>
|
||||
{
|
||||
["context"] = """{"runtime":{"location":{"iso":"2026-04-20T08:00:00-05:00"}}}"""
|
||||
}
|
||||
});
|
||||
|
||||
Assert.Equal("weather", decision.IntentName);
|
||||
Assert.Null(provider.LastRequest?.LocationQuery);
|
||||
Assert.True(provider.LastRequest?.IsTomorrow);
|
||||
Assert.Equal(1, provider.LastRequest?.ForecastDayOffset);
|
||||
Assert.Equal("Tomorrow in Kansas City, U.S., expect clear sky with a high near 79 degrees Fahrenheit and a low around 63 degrees Fahrenheit.", decision.ReplyText);
|
||||
Assert.False(provider.LastRequest?.IsTomorrow);
|
||||
Assert.Equal(5, provider.LastRequest?.ForecastDayOffset);
|
||||
Assert.Equal(5, provider.Requests.Count);
|
||||
Assert.Contains("next five-day forecast", decision.ReplyText, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Tuesday: clear sky, high 79, low 63.", decision.ReplyText, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Saturday: clear sky, high 79, low 63.", decision.ReplyText, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1697,7 +1704,7 @@ public sealed class JiboInteractionServiceTests
|
||||
|
||||
[Theory]
|
||||
[InlineData("how is the weather", null, 0, false)]
|
||||
[InlineData("what's the forecast", null, 1, true)]
|
||||
[InlineData("what's the forecast", null, 5, false)]
|
||||
[InlineData("forecast for new york city", "New York City", 1, true)]
|
||||
[InlineData("what's today's forecast", null, 0, false)]
|
||||
[InlineData("what's the weather in chicago", "Chicago", 0, false)]
|
||||
@@ -1729,6 +1736,11 @@ public sealed class JiboInteractionServiceTests
|
||||
Assert.Equal(expectedIsTomorrow, provider.LastRequest.IsTomorrow);
|
||||
Assert.Equal("chitchat-skill", decision.SkillName);
|
||||
Assert.Equal(true, decision.SkillPayload?["weather_view_enabled"]);
|
||||
|
||||
if (string.Equals(transcript, "what's the forecast", StringComparison.Ordinal))
|
||||
{
|
||||
Assert.Equal(5, provider.Requests.Count);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -2151,6 +2163,48 @@ public sealed class JiboInteractionServiceTests
|
||||
Assert.Equal("No.", decision.ReplyText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_SurprisesDateOfferPrompt_WithNoisyAffirmation_MapsToSurpriseIntent()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "- Thank you. - Yes.",
|
||||
NormalizedTranscript = "- Thank you. - Yes.",
|
||||
Attributes = new Dictionary<string, object?>
|
||||
{
|
||||
["listenRules"] = (string[])["surprises-date/offer_date_fact", "globals/gui_nav", "globals/global_commands_launch"],
|
||||
["listenAsrHints"] = (string[])["$YESNO"],
|
||||
["context"] = """{"runtime":{"location":{"iso":"2026-04-20T08:00:00-05:00"}}}"""
|
||||
}
|
||||
});
|
||||
|
||||
Assert.Equal("proactive_offer_pizza_fact", decision.IntentName);
|
||||
Assert.Equal("Do you want to hear a fun pizza fact?", decision.ReplyText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_WordOfDayOfferPrompt_WithNoisyAffirmation_MapsToWordOfDayLaunch()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "- Me. - Yes.",
|
||||
NormalizedTranscript = "- Me. - Yes.",
|
||||
Attributes = new Dictionary<string, object?>
|
||||
{
|
||||
["listenRules"] = (string[])["word-of-the-day/surprise", "globals/gui_nav", "globals/global_commands_launch"],
|
||||
["listenAsrHints"] = (string[])["$YESNO"]
|
||||
}
|
||||
});
|
||||
|
||||
Assert.Equal("word_of_the_day", decision.IntentName);
|
||||
Assert.Equal("Starting word of the day.", decision.ReplyText);
|
||||
Assert.Equal("@be/word-of-the-day", decision.SkillName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_SettingsDownloadPrompt_MapsShortDenialToNoIntent()
|
||||
{
|
||||
@@ -2171,7 +2225,7 @@ public sealed class JiboInteractionServiceTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_SurprisesDateOfferPrompt_MapsShortAffirmationToYesIntent()
|
||||
public async Task BuildDecisionAsync_SurprisesDateOfferPrompt_MapsShortAffirmationToSurpriseFlow()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
@@ -2186,8 +2240,8 @@ public sealed class JiboInteractionServiceTests
|
||||
}
|
||||
});
|
||||
|
||||
Assert.Equal("yes", decision.IntentName);
|
||||
Assert.Equal("Yes.", decision.ReplyText);
|
||||
Assert.Equal("proactive_offer_pizza_fact", decision.IntentName);
|
||||
Assert.Equal("Do you want to hear a fun pizza fact?", decision.ReplyText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1932,14 +1932,53 @@ public sealed class JiboWebSocketServiceTests
|
||||
Assert.Equal(3, replies.Count);
|
||||
|
||||
using var listenPayload = JsonDocument.Parse(replies[0].Text!);
|
||||
Assert.Equal("yes", listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
|
||||
Assert.Equal("proactive_offer_pizza_fact", listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
|
||||
var rules = listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("rules");
|
||||
Assert.Single(rules.EnumerateArray());
|
||||
Assert.Equal("surprises-date/offer_date_fact", rules[0].GetString());
|
||||
Assert.Equal("surprises-date/offer_date_fact", listenPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("rule").GetString());
|
||||
var selectedRule = rules[0].GetString();
|
||||
Assert.True(
|
||||
string.Equals(selectedRule, "surprises-date/offer_date_fact", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(selectedRule, "shared/yes_no", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.Equal(selectedRule, listenPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("rule").GetString());
|
||||
Assert.Empty(listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("entities").EnumerateObject());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClientAsr_WordOfDayOfferPrompt_MapsYesToWordOfDayLaunch()
|
||||
{
|
||||
await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = "hub-wod-offer-yesno-token",
|
||||
Text = """{"type":"LISTEN","transID":"trans-wod-offer-yes","data":{"rules":["word-of-the-day/surprise","globals/gui_nav","globals/mim_repeat","globals/global_commands_launch"],"asr":{"hints":["$YESNO"]}}}"""
|
||||
});
|
||||
|
||||
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = "hub-wod-offer-yesno-token",
|
||||
Text = """{"type":"CLIENT_ASR","transID":"trans-wod-offer-yes","data":{"text":"Yes!"}}"""
|
||||
});
|
||||
|
||||
Assert.True(replies.Count >= 3);
|
||||
|
||||
using var listenPayload = JsonDocument.Parse(replies[0].Text!);
|
||||
var rules = listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("rules");
|
||||
Assert.Single(rules.EnumerateArray());
|
||||
var selectedRule = rules[0].GetString();
|
||||
Assert.True(
|
||||
string.Equals(selectedRule, "word-of-the-day/surprise", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(selectedRule, "word-of-the-day/menu", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.Equal(selectedRule, listenPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("rule").GetString());
|
||||
Assert.Equal(
|
||||
"word-of-the-day",
|
||||
listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("entities").GetProperty("domain").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResponsePlanMapper_EscapesSpeechWithoutEncodingApostrophes()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user