From cabbf8891a8c74bc03dbe6db99c1bafaf7a162cd Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Fri, 15 Nov 2024 12:28:38 -0500 Subject: [PATCH] OpenAI-DotNet 8.4.1 (#383) - Fix ChatRequest serialization for Azure OpenAI --- OpenAI-DotNet/Chat/ChatRequest.cs | 28 ++++++++++++++++++++++------ OpenAI-DotNet/OpenAI-DotNet.csproj | 4 +++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/OpenAI-DotNet/Chat/ChatRequest.cs b/OpenAI-DotNet/Chat/ChatRequest.cs index 025cfc2d..cdaa6a6c 100644 --- a/OpenAI-DotNet/Chat/ChatRequest.cs +++ b/OpenAI-DotNet/Chat/ChatRequest.cs @@ -190,7 +190,7 @@ public ChatRequest( } else { - Modalities = Modality.Text; + Modalities = Modality.Text & Modality.Audio; } FrequencyPenalty = frequencyPenalty; @@ -238,12 +238,14 @@ public ChatRequest( /// Whether or not to store the output of this chat completion request for use in our model distillation or evals products. /// [JsonPropertyName("store")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool? Store { get; set; } /// /// Developer-defined tags and values used for filtering completions in the dashboard. /// [JsonPropertyName("metadata")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IReadOnlyDictionary Metadata { get; set; } /// @@ -253,6 +255,7 @@ public ChatRequest( /// Defaults to 0 /// [JsonPropertyName("frequency_penalty")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double? FrequencyPenalty { get; } /// @@ -275,7 +278,7 @@ public ChatRequest( /// This option is currently not available on the gpt-4-vision-preview model. /// [JsonPropertyName("logprobs")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool? LogProbs { get; } /// @@ -286,21 +289,21 @@ public ChatRequest( /// must be set to true if this parameter is used. /// [JsonPropertyName("top_logprobs")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? TopLogProbs { get; } /// /// The maximum number of tokens allowed for the generated answer. /// By default, the number of tokens the model can return will be (4096 - prompt tokens). /// - [JsonPropertyName("max_tokens")] - [Obsolete("Use MaxCompletionTokens instead")] - public int? MaxTokens { get; } + [JsonIgnore] + public int? MaxTokens => MaxCompletionTokens; /// /// An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens. /// [JsonPropertyName("max_completion_tokens")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? MaxCompletionTokens { get; } /// @@ -312,6 +315,7 @@ public ChatRequest( [JsonPropertyName("modalities")] [JsonConverter(typeof(ModalityConverter))] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Modality Modalities { get; } /// @@ -319,6 +323,7 @@ public ChatRequest( /// This is most common when you are regenerating a file with only minor changes to most of the content. /// [JsonPropertyName("prediction")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object Prediction { get; set; } /// @@ -326,6 +331,7 @@ public ChatRequest( /// Required when audio output is requested with modalities: ["audio"]. /// [JsonPropertyName("audio")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public AudioConfig AudioConfig { get; } /// @@ -335,6 +341,7 @@ public ChatRequest( /// Defaults to 0 /// [JsonPropertyName("presence_penalty")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double? PresencePenalty { get; } [JsonPropertyName("response_format")] @@ -363,6 +370,7 @@ public ChatRequest( /// monitor changes in the backend. /// [JsonPropertyName("seed")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? Seed { get; } /// @@ -374,12 +382,14 @@ public ChatRequest( /// When this parameter is set, the response body will include the service_tier utilized. /// [JsonPropertyName("service_tier")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public string ServiceTier { get; set; } /// /// Up to 4 sequences where the API will stop generating further tokens. /// [JsonPropertyName("stop")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[] Stops { get; } /// @@ -403,6 +413,7 @@ public ChatRequest( /// Defaults to 1 /// [JsonPropertyName("temperature")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double? Temperature { get; } /// @@ -413,6 +424,7 @@ public ChatRequest( /// Defaults to 1 /// [JsonPropertyName("top_p")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public double? TopP { get; } /// @@ -420,6 +432,7 @@ public ChatRequest( /// Use this to provide a list of functions the model may generate JSON inputs for. /// [JsonPropertyName("tools")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IReadOnlyList Tools { get; } /// @@ -432,18 +445,21 @@ public ChatRequest( /// 'auto' is the default if functions are present.
///
[JsonPropertyName("tool_choice")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public dynamic ToolChoice { get; } /// /// Whether to enable parallel function calling during tool use. /// [JsonPropertyName("parallel_tool_calls")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool? ParallelToolCalls { get; } /// /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. /// [JsonPropertyName("user")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public string User { get; } /// diff --git a/OpenAI-DotNet/OpenAI-DotNet.csproj b/OpenAI-DotNet/OpenAI-DotNet.csproj index 4e582d68..a47a6de0 100644 --- a/OpenAI-DotNet/OpenAI-DotNet.csproj +++ b/OpenAI-DotNet/OpenAI-DotNet.csproj @@ -29,8 +29,10 @@ More context [on Roger Pincombe's blog](https://rogerpincombe.com/openai-dotnet- OpenAI-DotNet.pfx true true - 8.4.0 + 8.4.1 +Version 8.4.1 +- Fix ChatRequest serialization for Azure OpenAI Version 8.4.0 - Add realtime support - Added o1, o1-mini, gpt-4o-mini, and gpt-4o-realtime, gpt-4o-audio model convenience properties