Add chitchat state machine routing
This commit is contained in:
@@ -17,6 +17,9 @@ public sealed class JiboInteractionServiceTests
|
||||
private const string PersonalReportCalendarEnabledKey = "personalReportCalendarEnabled";
|
||||
private const string PersonalReportCommuteEnabledKey = "personalReportCommuteEnabled";
|
||||
private const string PersonalReportNewsEnabledKey = "personalReportNewsEnabled";
|
||||
private const string ChitchatStateKey = "chitchatState";
|
||||
private const string ChitchatRouteKey = "chitchatRoute";
|
||||
private const string ChitchatEmotionKey = "chitchatEmotion";
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_Joke_UsesCatalogBackedRandomContent()
|
||||
@@ -147,6 +150,76 @@ public sealed class JiboInteractionServiceTests
|
||||
Assert.Equal("I do. I am curious, playful, and always up for a new experiment.", decision.ReplyText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_Hello_RoutesThroughChitchatScriptedResponse()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "hello",
|
||||
NormalizedTranscript = "hello"
|
||||
});
|
||||
|
||||
Assert.Equal("hello", decision.IntentName);
|
||||
Assert.NotNull(decision.ContextUpdates);
|
||||
Assert.Equal("complete", decision.ContextUpdates![ChitchatStateKey]);
|
||||
Assert.Equal("ScriptedResponse", decision.ContextUpdates[ChitchatRouteKey]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_AreYouHappy_RoutesThroughEmotionQuerySplit()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "are you happy",
|
||||
NormalizedTranscript = "are you happy"
|
||||
});
|
||||
|
||||
Assert.Equal("emotion_query", decision.IntentName);
|
||||
Assert.NotNull(decision.ContextUpdates);
|
||||
Assert.Equal("EmotionQuery", decision.ContextUpdates![ChitchatRouteKey]);
|
||||
Assert.Equal(string.Empty, decision.ContextUpdates[ChitchatEmotionKey]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_Smile_RoutesThroughEmotionCommandSplit()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "smile",
|
||||
NormalizedTranscript = "smile"
|
||||
});
|
||||
|
||||
Assert.Equal("emotion_command", decision.IntentName);
|
||||
Assert.Equal("chitchat-skill", decision.SkillName);
|
||||
Assert.NotNull(decision.SkillPayload);
|
||||
Assert.Contains("cat='happy'", decision.SkillPayload!["esml"]?.ToString(), StringComparison.Ordinal);
|
||||
Assert.NotNull(decision.ContextUpdates);
|
||||
Assert.Equal("EmotionCommand", decision.ContextUpdates![ChitchatRouteKey]);
|
||||
Assert.Equal("happy", decision.ContextUpdates[ChitchatEmotionKey]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_UnhandledChat_RoutesThroughErrorResponseSplit()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "blargh",
|
||||
NormalizedTranscript = "blargh"
|
||||
});
|
||||
|
||||
Assert.Equal("chat", decision.IntentName);
|
||||
Assert.NotNull(decision.ContextUpdates);
|
||||
Assert.Equal("ErrorResponse", decision.ContextUpdates![ChitchatRouteKey]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_BirthdayMemory_SetThenRecallWithinTenant()
|
||||
{
|
||||
|
||||
@@ -3241,6 +3241,36 @@ public sealed class JiboWebSocketServiceTests
|
||||
Assert.Equal("idle", stateValue?.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClientAsrChitchatEmotionCommand_PersistsSplitRouteMetadata()
|
||||
{
|
||||
const string routeKey = "chitchatRoute";
|
||||
const string emotionKey = "chitchatEmotion";
|
||||
var token = _store.IssueRobotToken("chitchat-emotion-device-a");
|
||||
|
||||
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = token,
|
||||
Text = """{"type":"CLIENT_ASR","transID":"trans-chitchat-emotion","data":{"text":"smile"}}"""
|
||||
});
|
||||
|
||||
Assert.Equal(3, replies.Count);
|
||||
using (var listenPayload = JsonDocument.Parse(replies[0].Text!))
|
||||
{
|
||||
Assert.Equal("emotion_command", listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
|
||||
}
|
||||
|
||||
var session = _store.FindSessionByToken(token);
|
||||
Assert.NotNull(session);
|
||||
Assert.True(session.Metadata.TryGetValue(routeKey, out var routeValue));
|
||||
Assert.Equal("EmotionCommand", routeValue?.ToString());
|
||||
Assert.True(session.Metadata.TryGetValue(emotionKey, out var emotionValue));
|
||||
Assert.Equal("happy", emotionValue?.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FollowUpTurn_UsesNewTurnStateWithoutLeakingBufferedAudio()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user