mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-03 19:27:21 +00:00
Generated the JSON contracts of the stored data at compile time (#1148)
This commit is contained in:
1 parent
fc7399e81b
commit
e954881fda
75 files changed
+5437
-298
No files matched your search
@@ -10,13 +10,22 @@ internal static class SwotAnalysisContentPresentation
|
||||
/// Fails the reading of stored data which holds a null where the result expects a value, so that
|
||||
/// the result view never meets one.
|
||||
/// </summary>
|
||||
private static readonly JsonSerializerOptions JSON_OPTIONS = new()
|
||||
internal static readonly JsonSerializerOptions JSON_OPTIONS = new JsonSerializerOptions
|
||||
{
|
||||
RespectNullableAnnotations = true,
|
||||
};
|
||||
TypeInfoResolver = SwotAnalysisJsonContext.Default,
|
||||
}.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// Writes the analysis with the defaults of System.Text.Json, which let a null pass, unlike the reading.
|
||||
/// </summary>
|
||||
internal static readonly JsonSerializerOptions WRITE_OPTIONS = new JsonSerializerOptions
|
||||
{
|
||||
TypeInfoResolver = SwotAnalysisJsonContext.Default,
|
||||
}.AsReadOnly();
|
||||
|
||||
public static ContentPresentation Create(SwotAnalysisResult result) =>
|
||||
ContentPresentation.Create(ContentPresentationKind.SWOT_ANALYSIS, result);
|
||||
ContentPresentation.Create(ContentPresentationKind.SWOT_ANALYSIS, result, WRITE_OPTIONS);
|
||||
|
||||
/// <summary>
|
||||
/// Reads the SWOT analysis stored as the presentation of a text, so it can be shown as a matrix.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AIStudio.Assistants.SWOTAnalysis;
|
||||
|
||||
/// <summary>
|
||||
/// The contracts with which System.Text.Json reads and writes a SWOT analysis which a chat stores, built at
|
||||
/// compile time.
|
||||
/// </summary>
|
||||
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
||||
[JsonSerializable(typeof(SwotAnalysisResult))]
|
||||
internal sealed partial class SwotAnalysisJsonContext : JsonSerializerContext;
|
||||
Reference in new issue
Block a user