mirror of
https://kevinblog.sytes.net/Code/Jibo-Revival-Group/JiboExperiments.git
synced 2026-06-16 22:36:43 +00:00
Fix weather forecast routing and Hi/Lo rendering
This commit is contained in:
@@ -419,6 +419,12 @@ public sealed class JiboInteractionService(
|
||||
{
|
||||
var referenceLocalTime = TryResolveReferenceLocalTime(turn);
|
||||
var weatherDate = ResolveWeatherDateEntity(turn, transcript, referenceLocalTime);
|
||||
var normalizedTranscript = NormalizeCommandPhrase(transcript);
|
||||
if (ShouldDefaultForecastToTomorrow(normalizedTranscript, weatherDate))
|
||||
{
|
||||
weatherDate = new WeatherDateEntity("tomorrow", 1, "Tomorrow");
|
||||
}
|
||||
|
||||
if (weatherReportProvider is null)
|
||||
{
|
||||
return new JiboInteractionDecision(
|
||||
@@ -434,7 +440,9 @@ public sealed class JiboInteractionService(
|
||||
}
|
||||
|
||||
var locationQuery = TryResolveWeatherLocationQuery(transcript);
|
||||
var weatherCoordinates = TryResolveWeatherCoordinates(turn);
|
||||
var weatherCoordinates = string.IsNullOrWhiteSpace(locationQuery)
|
||||
? TryResolveWeatherCoordinates(turn)
|
||||
: null;
|
||||
var useCelsius = ShouldUseCelsius(turn, transcript);
|
||||
WeatherReportSnapshot? snapshot;
|
||||
try
|
||||
@@ -504,6 +512,26 @@ public sealed class JiboInteractionService(
|
||||
return $"Right now in {location}, it is {summary} and {snapshot.Temperature} degrees {unit}.";
|
||||
}
|
||||
|
||||
private static bool ShouldDefaultForecastToTomorrow(string normalizedTranscript, WeatherDateEntity weatherDate)
|
||||
{
|
||||
if (weatherDate.ForecastDayOffset > 0 ||
|
||||
string.IsNullOrWhiteSpace(normalizedTranscript) ||
|
||||
!normalizedTranscript.Contains("forecast", StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !MatchesAny(
|
||||
normalizedTranscript,
|
||||
"today",
|
||||
"today s",
|
||||
"today's",
|
||||
"tonight",
|
||||
"right now",
|
||||
"current weather",
|
||||
"currently");
|
||||
}
|
||||
|
||||
private static IDictionary<string, object?> BuildWeatherSkillPayload(
|
||||
string spokenReply,
|
||||
WeatherReportSnapshot snapshot,
|
||||
|
||||
@@ -824,20 +824,42 @@ public sealed class ResponsePlanToSocketMessagesMapper
|
||||
var weatherHiLoView = BuildWeatherHiLoView(skillPayload);
|
||||
if (weatherHiLoView is not null)
|
||||
{
|
||||
var guiConfig = new
|
||||
var resolvedGuiConfig = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["type"] = "Javascript",
|
||||
["data"] = weatherHiLoView,
|
||||
["pause"] = true
|
||||
};
|
||||
|
||||
var legacyGuiConfig = new
|
||||
{
|
||||
type = "Javascript",
|
||||
data = "views.weatherHiLo",
|
||||
pause = true
|
||||
};
|
||||
jcpConfig["gui"] = guiConfig;
|
||||
playConfig["gui"] = guiConfig;
|
||||
|
||||
jcpConfig["gui"] = legacyGuiConfig;
|
||||
jcpConfig["display"] = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["view"] = resolvedGuiConfig
|
||||
};
|
||||
|
||||
playConfig["gui"] = resolvedGuiConfig;
|
||||
playConfig["no_matches_for_gui"] = 0;
|
||||
playConfig["no_inputs_for_gui"] = 0;
|
||||
|
||||
var weatherViews = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["weatherHiLo"] = weatherHiLoView
|
||||
};
|
||||
jcpConfig["views"] = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["weatherHiLo"] = weatherHiLoView
|
||||
};
|
||||
jcpConfig["local"] = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["views"] = weatherViews
|
||||
};
|
||||
}
|
||||
|
||||
return new
|
||||
|
||||
@@ -53,14 +53,20 @@ public sealed class OpenWeatherReportProvider(
|
||||
WeatherReportRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (request is { Latitude: not null, Longitude: not null })
|
||||
var query = string.IsNullOrWhiteSpace(request.LocationQuery)
|
||||
? null
|
||||
: request.LocationQuery.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
return new LocationPoint(request.Latitude.Value, request.Longitude.Value, null);
|
||||
if (request is { Latitude: not null, Longitude: not null })
|
||||
{
|
||||
return new LocationPoint(request.Latitude.Value, request.Longitude.Value, null);
|
||||
}
|
||||
|
||||
query = options.DefaultLocation;
|
||||
}
|
||||
|
||||
var query = string.IsNullOrWhiteSpace(request.LocationQuery)
|
||||
? options.DefaultLocation
|
||||
: request.LocationQuery.Trim();
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user