Generated the JSON contracts of providers, the runtime, and services at compile time (#1150)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-03 07:59:30 +01:00
1 parent e954881fda
commit 24e3c22db3
140 files changed
+1415 -292

No files matched your search

@@ -14,15 +14,25 @@ public record ChatCompletionAPIRequest(
bool Stream
)
{
//
// The properties of the parameters, declared again to be settable. The source generation of System.Text.Json
// sets every init-only property while it creates the object, also one missing in the JSON, so its value from
// the parameterless constructor would get lost. Keep them first and in the order of the parameters, which is
// the order they get written in:
//
public string Model { get; set; } = Model;
public IList<IMessageBase> Messages { get; set; } = Messages;
public bool Stream { get; set; } = Stream;
public ChatCompletionAPIRequest() : this(string.Empty, [], true)
{
}
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IList<object>? Tools { get; init; }
public IList<object>? Tools { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? ParallelToolCalls { get; init; }
public bool? ParallelToolCalls { get; set; }
/// <summary>
/// Asks a streamed request to end with what it cost.
@@ -35,7 +45,10 @@ public record ChatCompletionAPIRequest(
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ChatCompletionStreamOptions? StreamOptions => this.Stream ? ChatCompletionStreamOptions.INCLUDE_USAGE : null;
// Attention: The "required" modifier is not supported for [JsonExtensionData].
//
// Attention: The "required" modifier is not supported for [JsonExtensionData], and neither is init: the source
// generation of System.Text.Json refuses to write the request at all then.
//
[JsonExtensionData]
public IDictionary<string, object> AdditionalApiParameters { get; init; } = new Dictionary<string, object>();
public IDictionary<string, object> AdditionalApiParameters { get; set; } = new Dictionary<string, object>();
}