mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 22:47:21 +00:00
Generated the JSON contracts of visual briefings and model answers at compile time (#1151)
This commit is contained in:
1 parent
24e3c22db3
commit
770c16e20a
101 files changed
+2333
-392
No files matched your search
@@ -0,0 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AIStudio.Tools.PowerPoint;
|
||||
|
||||
/// <summary>
|
||||
/// The contracts with which System.Text.Json reads the slides a model plans, built at compile time.
|
||||
/// </summary>
|
||||
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
||||
[JsonSerializable(typeof(SlideDeckSpec.DeckDto))]
|
||||
internal sealed partial class SlideDeckJsonContext : JsonSerializerContext;
|
||||
@@ -7,7 +7,7 @@ namespace AIStudio.Tools.PowerPoint;
|
||||
|
||||
internal sealed partial record SlideDeckSpec
|
||||
{
|
||||
private static readonly JsonSerializerOptions JSON_OPTIONS = new()
|
||||
internal static readonly JsonSerializerOptions JSON_OPTIONS = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
||||
PropertyNameCaseInsensitive = true,
|
||||
@@ -15,7 +15,8 @@ internal sealed partial record SlideDeckSpec
|
||||
AllowTrailingCommas = true,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip,
|
||||
MaxDepth = 16,
|
||||
};
|
||||
TypeInfoResolver = SlideDeckJsonContext.Default,
|
||||
}.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// The deepest list level a paragraph may have; PowerPoint knows nine, starting at 0.
|
||||
@@ -158,17 +159,18 @@ internal sealed partial record SlideDeckSpec
|
||||
private static string Clean(string? text) => text?.Trim() ?? string.Empty;
|
||||
|
||||
//
|
||||
// What the model writes, before anything is checked. Every value may be missing or null.
|
||||
// What the model writes, before anything is checked. Every value may be missing or null. Internal
|
||||
// rather than private, so that the JSON context of the deck can name them:
|
||||
//
|
||||
|
||||
private sealed class DeckDto
|
||||
internal sealed class DeckDto
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
|
||||
public List<SlideDto?>? Slides { get; set; }
|
||||
}
|
||||
|
||||
private sealed class SlideDto
|
||||
internal sealed class SlideDto
|
||||
{
|
||||
public int? TemplateSlide { get; set; }
|
||||
|
||||
@@ -191,7 +193,7 @@ internal sealed partial record SlideDeckSpec
|
||||
public JsonElement? Remove { get; set; }
|
||||
}
|
||||
|
||||
private sealed class TableDto
|
||||
internal sealed class TableDto
|
||||
{
|
||||
public List<JsonElement>? Headers { get; set; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user