Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(dotnet): return rendered criterion text in score legends

kevin-gatimu2d7a307b74dc
diff --git a/laya-dotnet/src/Laya/Answers.cs b/laya-dotnet/src/Laya/Answers.cs
index 45cb8251..9ed97df7 100644
--- a/laya-dotnet/src/Laya/Answers.cs
+++ b/laya-dotnet/src/Laya/Answers.cs
@@ -115,7 +115,7 @@ public sealed class ScoreAnswer : Answer
/// </summary>
public double Score { get; }
- /// <summary>What each level index means, as supplied on the question.</summary>
+ /// <summary>Rendered text for each level index, including JSON text for structured criteria.</summary>
public IReadOnlyList<object?> Legend { get; }
/// <summary>Probability per level index. Rounded to 4 decimals.</summary>
diff --git a/laya-dotnet/src/Laya/LayaEngine.cs b/laya-dotnet/src/Laya/LayaEngine.cs
index 1b60766e..42d5e2d5 100644
--- a/laya-dotnet/src/Laya/LayaEngine.cs
+++ b/laya-dotnet/src/Laya/LayaEngine.cs
@@ -275,7 +275,8 @@ public sealed class LayaEngine : IDisposable, ILayaPredictor
var probabilities = new double[p.Length];
for (var i = 0; i < p.Length; i++) probabilities[i] = Calibration.Round4(p[i]);
return new ScoreAnswer(Calibration.Round4(Calibration.ExpectedScore(p)),
- score.Levels, probabilities, confidence, answerConfidence, action);
+ score.Levels.Select(PythonJson.Criterion).Cast<object?>().ToArray(),
+ probabilities, confidence, answerConfidence, action);
}
default:
diff --git a/laya-dotnet/tests/Laya.Tests/PredictParityTests.cs b/laya-dotnet/tests/Laya.Tests/PredictParityTests.cs
index a68cbe48..767b3035 100644
--- a/laya-dotnet/tests/Laya.Tests/PredictParityTests.cs
+++ b/laya-dotnet/tests/Laya.Tests/PredictParityTests.cs
@@ -53,8 +53,20 @@ public sealed class PredictParityTests(AllEnginesFixture fixture)
/// </summary>
public static IEnumerable<object[]> AllSuccessCasesSplit() => AllSuccessCases();
+ /// <summary>Structured score levels whose legend must retain the exact rendered JSON text.</summary>
+ public static IEnumerable<object[]> StructuredScoreCases() =>
+ AllSuccessCases().Where(values => ((GoldenCaseInfo)values[1]).Name == "criterion_shapes");
+
// ── theory tests ──────────────────────────────────────────────────────────
+ [Theory]
+ [MemberData(nameof(StructuredScoreCases))]
+ public void StructuredScoreLegendsAreRenderedText(LayaCheckpoint checkpoint, GoldenCaseInfo info)
+ {
+ ReproducesTheRecordedAnswers(checkpoint, info);
+ ReproducesTheRecordedAnswersSplit(checkpoint, info);
+ }
+
[Theory]
[MemberData(nameof(AllSuccessCases))]
public void ReproducesTheRecordedAnswers(LayaCheckpoint checkpoint, GoldenCaseInfo info)
@@ -248,7 +260,7 @@ public sealed class PredictParityTests(AllEnginesFixture fixture)
for (var i = 0; i < got.Legend.Count; i++)
{
var level = legend.GetProperty(i.ToString(CultureInfo.InvariantCulture));
- Assert.Equal(PythonJson.Criterion(GoldenData.ToClr(level)), PythonJson.Criterion(got.Legend[i]));
+ Assert.Equal(level.GetString(), Assert.IsType<string>(got.Legend[i]));
}
var probabilities = want.GetProperty("probabilities");