first stab at solving for menus and real STT
This commit is contained in:
@@ -8,22 +8,30 @@ public sealed class DemoConversationBroker : IConversationBroker
|
||||
{
|
||||
var transcript = (turn.NormalizedTranscript ?? turn.RawTranscript ?? string.Empty).Trim();
|
||||
var lowered = transcript.ToLowerInvariant();
|
||||
var clientIntent = turn.Attributes.TryGetValue("clientIntent", out var rawClientIntent)
|
||||
? rawClientIntent?.ToString()
|
||||
: null;
|
||||
var semanticIntent = ResolveSemanticIntent(lowered, clientIntent);
|
||||
|
||||
var reply = transcript.Length == 0
|
||||
var reply = semanticIntent switch
|
||||
{
|
||||
"time" => $"It is {DateTime.Now:hh:mm tt}.",
|
||||
"date" => $"Today is {DateTime.Now:dddd, MMMM d}.",
|
||||
"dance" => "Okay. Watch this.",
|
||||
_ => transcript.Length == 0
|
||||
? "I am listening."
|
||||
: lowered.Contains("time")
|
||||
? $"It is {DateTime.Now:hh:mm tt}."
|
||||
: lowered.Contains("hello") || lowered.Contains("hi")
|
||||
? "Hello from the OpenJibo cloud."
|
||||
: lowered.Contains("joke")
|
||||
? "Why did the robot bring a ladder? Because it wanted to reach the cloud."
|
||||
: $"I heard: {transcript}";
|
||||
: lowered.Contains("hello") || lowered.Contains("hi")
|
||||
? "Hello from the OpenJibo cloud."
|
||||
: lowered.Contains("joke")
|
||||
? "Why did the robot bring a ladder? Because it wanted to reach the cloud."
|
||||
: $"I heard: {transcript}"
|
||||
};
|
||||
|
||||
var plan = new ResponsePlan
|
||||
{
|
||||
SessionId = turn.SessionId,
|
||||
Status = ResponseStatus.Succeeded,
|
||||
IntentName = lowered.Contains("joke") ? "joke" : lowered.Contains("time") ? "time" : "chat",
|
||||
IntentName = semanticIntent,
|
||||
Topic = "conversation",
|
||||
DeviceId = turn.DeviceId,
|
||||
TargetHost = turn.HostName,
|
||||
@@ -72,4 +80,39 @@ public sealed class DemoConversationBroker : IConversationBroker
|
||||
|
||||
return Task.FromResult(plan);
|
||||
}
|
||||
|
||||
private static string ResolveSemanticIntent(string loweredTranscript, string? clientIntent)
|
||||
{
|
||||
if (string.Equals(clientIntent, "askForTime", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return "time";
|
||||
}
|
||||
|
||||
if (string.Equals(clientIntent, "askForDate", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return "date";
|
||||
}
|
||||
|
||||
if (loweredTranscript.Contains("joke", StringComparison.Ordinal))
|
||||
{
|
||||
return "joke";
|
||||
}
|
||||
|
||||
if (loweredTranscript.Contains("dance", StringComparison.Ordinal))
|
||||
{
|
||||
return "dance";
|
||||
}
|
||||
|
||||
if (loweredTranscript.Contains("time", StringComparison.Ordinal))
|
||||
{
|
||||
return "time";
|
||||
}
|
||||
|
||||
if (loweredTranscript.Contains("date", StringComparison.Ordinal) || loweredTranscript.Contains("day", StringComparison.Ordinal))
|
||||
{
|
||||
return "date";
|
||||
}
|
||||
|
||||
return "chat";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user