From a7dab77dbdbc257b2723a9abbeade75998f343b5 Mon Sep 17 00:00:00 2001 From: Benjamin Stern <1266727+benjamin-stern@users.noreply.github.com> Date: Mon, 19 May 2025 13:08:36 +0300 Subject: [PATCH 1/4] Update image generation quality and size options - Changed `Quality` from `High` to `Hd` across multiple files. - Added new quality levels: `Hd`, `High`, `Medium`, `Low`, and `Auto` in `GeneratedImageQuality.cs`. - Introduced new sizes `W1536xH1024` and `W1024xH1536` in `GeneratedImageSize.cs`. - Enhanced `ImageEditOptions` with a new `Quality` property and updated documentation for `Size`. - Implemented checks for the `Quality` property in `ImageEditOptions`. - Overall improvements for better control over image generation in the OpenAI API. --- examples/CombinationExamples.cs | 4 +- .../Images/Example01_SimpleImageGeneration.cs | 2 +- .../Example01_SimpleImageGenerationAsync.cs | 2 +- src/Custom/Images/GeneratedImageQuality.cs | 48 ++++++++++++++++++- src/Custom/Images/GeneratedImageSize.cs | 20 +++++++- src/Custom/Images/ImageEditOptions.cs | 33 ++++++++++++- src/Generated/Models/GeneratedImageQuality.cs | 5 ++ src/Generated/Models/GeneratedImageSize.cs | 2 + 8 files changed, 108 insertions(+), 8 deletions(-) diff --git a/examples/CombinationExamples.cs b/examples/CombinationExamples.cs index 4fd692c3..f69a395d 100644 --- a/examples/CombinationExamples.cs +++ b/examples/CombinationExamples.cs @@ -21,7 +21,7 @@ public void AlpacaArtAssessor() new() { Style = GeneratedImageStyle.Vivid, - Quality = GeneratedImageQuality.High, + Quality = GeneratedImageQuality.Hd, Size = GeneratedImageSize.W1792xH1024, }); GeneratedImage imageGeneration = imageResult.Value; @@ -109,7 +109,7 @@ public async Task CuriousCreatureCreator() new ImageGenerationOptions() { Size = GeneratedImageSize.W1792xH1024, - Quality = GeneratedImageQuality.High, + Quality = GeneratedImageQuality.Hd, }); Uri imageLocation = imageGenerationResult.Value.ImageUri; Console.WriteLine($"Creature image available at:\n{imageLocation.AbsoluteUri}"); diff --git a/examples/Images/Example01_SimpleImageGeneration.cs b/examples/Images/Example01_SimpleImageGeneration.cs index f194348a..df107a73 100644 --- a/examples/Images/Example01_SimpleImageGeneration.cs +++ b/examples/Images/Example01_SimpleImageGeneration.cs @@ -22,7 +22,7 @@ public void Example01_SimpleImageGeneration() ImageGenerationOptions options = new() { - Quality = GeneratedImageQuality.High, + Quality = GeneratedImageQuality.Hd, Size = GeneratedImageSize.W1792xH1024, Style = GeneratedImageStyle.Vivid, ResponseFormat = GeneratedImageFormat.Bytes diff --git a/examples/Images/Example01_SimpleImageGenerationAsync.cs b/examples/Images/Example01_SimpleImageGenerationAsync.cs index 20487d3a..5e07ff63 100644 --- a/examples/Images/Example01_SimpleImageGenerationAsync.cs +++ b/examples/Images/Example01_SimpleImageGenerationAsync.cs @@ -23,7 +23,7 @@ public async Task Example01_SimpleImageGenerationAsync() ImageGenerationOptions options = new() { - Quality = GeneratedImageQuality.High, + Quality = GeneratedImageQuality.Hd, Size = GeneratedImageSize.W1792xH1024, Style = GeneratedImageStyle.Vivid, ResponseFormat = GeneratedImageFormat.Bytes diff --git a/src/Custom/Images/GeneratedImageQuality.cs b/src/Custom/Images/GeneratedImageQuality.cs index b68ef487..f5e68ebe 100644 --- a/src/Custom/Images/GeneratedImageQuality.cs +++ b/src/Custom/Images/GeneratedImageQuality.cs @@ -2,12 +2,58 @@ namespace OpenAI.Images; // CUSTOM: Renamed. /// -/// The quality of the image that will be generated. creates images with finer details and +/// The quality of the image that will be generated. creates images with finer details and /// greater consistency across the image. +/// +/// High, medium and low qualities are only supported for gpt-image-1. +/// +/// +/// dall-e-2 only supports standard quality. +/// +/// +/// Defaults to auto. +/// /// [CodeGenType("CreateImageRequestQuality")] public readonly partial struct GeneratedImageQuality { + [CodeGenMember("Hd")] + public static GeneratedImageQuality Hd { get; } = new GeneratedImageQuality(HdValue); + + /// + /// High quality level - creates images with finer details and greater consistency. + /// + /// Only supported for gpt-image-1. + /// + /// + /// + [CodeGenMember("High")] public static GeneratedImageQuality High { get; } = new GeneratedImageQuality(HdValue); + /// + /// Medium quality level. + /// + /// Only supported for gpt-image-1. + /// + /// + [CodeGenMember("Medium")] + public static GeneratedImageQuality Medium { get; } = new GeneratedImageQuality(MediumValue); + + /// + /// Low quality level. + /// + /// Only supported for gpt-image-1. + /// + /// + [CodeGenMember("Low")] + public static GeneratedImageQuality Low { get; } = new GeneratedImageQuality(LowValue); + + /// + /// Auto quality level - the system will automatically choose the appropriate quality level. + /// + /// This is the default value. + /// + /// + [CodeGenMember("Auto")] + public static GeneratedImageQuality Auto { get; } = new GeneratedImageQuality(AutoValue); } \ No newline at end of file diff --git a/src/Custom/Images/GeneratedImageSize.cs b/src/Custom/Images/GeneratedImageSize.cs index ddf7b143..11d96fae 100644 --- a/src/Custom/Images/GeneratedImageSize.cs +++ b/src/Custom/Images/GeneratedImageSize.cs @@ -52,7 +52,7 @@ public GeneratedImageSize(int width, int height) /// /// A square image with 1024 pixels of both width and height. /// - /// Supported and default for both dall-e-2 and dall-e-3 models. + /// Supported and default for both dall-e-2, dall-e-3 and gpt-image-1 models. /// /// [CodeGenMember("_1024x1024")] @@ -75,4 +75,22 @@ public GeneratedImageSize(int width, int height) /// [CodeGenMember("_1024x1792")] public static readonly GeneratedImageSize W1792xH1024 = new(1792, 1024); + + /// + /// A landscape rectangular image with 1536 pixels of width and 1024 pixels of height. + /// + /// Supported only for the newer gpt-image-1 model. + /// + /// + [CodeGenMember("_1536x1024")] + public static readonly GeneratedImageSize W1536xH1024 = new(1536, 1024); + + /// + /// A portrait rectangular image with 1024 pixels of width and 1536 pixels of height. + /// + /// Supported only for the newer gpt-image-1 model. + /// + /// + [CodeGenMember("1024x_1536")] + public static readonly GeneratedImageSize W1024xH1536 = new(1024, 1536); } \ No newline at end of file diff --git a/src/Custom/Images/ImageEditOptions.cs b/src/Custom/Images/ImageEditOptions.cs index 984d2a71..a80f312a 100644 --- a/src/Custom/Images/ImageEditOptions.cs +++ b/src/Custom/Images/ImageEditOptions.cs @@ -73,11 +73,35 @@ public ImageEditOptions() { } - // CUSTOM: Changed property type. - /// The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. + // CUSTOM: Changed property type and updated documentation. + /// + /// The size of the generated images. + /// + /// For gpt-image-1, must be one of 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), or auto (default value). + /// + /// + /// For dall-e-2, must be one of 256x256, 512x512, or 1024x1024. + /// + /// [CodeGenMember("Size")] public GeneratedImageSize? Size { get; set; } + // CUSTOM: Added Quality property + /// + /// Quality of the image that will be generated. + /// + /// High, medium and low are only supported for gpt-image-1. + /// + /// + /// dall-e-2 only supports standard quality. + /// + /// + /// Defaults to auto. + /// + /// + [CodeGenMember("Quality")] + public GeneratedImageQuality? Quality { get; set; } + // CUSTOM: Changed property type. /// The format in which the generated images are returned. Must be one of `url` or `b64_json`. [CodeGenMember("ResponseFormat")] @@ -119,6 +143,11 @@ internal MultiPartFormDataBinaryContent ToMultipartContent(Stream image, string content.Add(Size.ToString(), "size"); } + if (Quality is not null) + { + content.Add(Quality.ToString(), "quality"); + } + if (EndUserId is not null) { content.Add(EndUserId, "user"); diff --git a/src/Generated/Models/GeneratedImageQuality.cs b/src/Generated/Models/GeneratedImageQuality.cs index 030295c0..fb494d30 100644 --- a/src/Generated/Models/GeneratedImageQuality.cs +++ b/src/Generated/Models/GeneratedImageQuality.cs @@ -14,6 +14,11 @@ namespace OpenAI.Images private const string StandardValue = "standard"; private const string HdValue = "hd"; + private const string HighValue = "high"; + private const string MediumValue = "medium"; + private const string LowValue = "low"; + private const string AutoValue = "auto"; + public GeneratedImageQuality(string value) { Argument.AssertNotNull(value, nameof(value)); diff --git a/src/Generated/Models/GeneratedImageSize.cs b/src/Generated/Models/GeneratedImageSize.cs index ae5e0549..52cb4789 100644 --- a/src/Generated/Models/GeneratedImageSize.cs +++ b/src/Generated/Models/GeneratedImageSize.cs @@ -15,6 +15,8 @@ namespace OpenAI.Images private const string _1024x1024Value = "1024x1024"; private const string _1792x1024Value = "1792x1024"; private const string _1024x1792Value = "1024x1792"; + private const string _1536x1024Value = "1536x1024"; + private const string _1024x1536Value = "1024x1536"; public static bool operator ==(GeneratedImageSize left, GeneratedImageSize right) => left.Equals(right); From cb79c48cf5435e2e1f5061736b449f70bcd68a50 Mon Sep 17 00:00:00 2001 From: Benjamin Stern <1266727+benjamin-stern@users.noreply.github.com> Date: Mon, 19 May 2025 17:02:45 +0300 Subject: [PATCH 2/4] Update GeneratedImageQuality.High initialization value Changed the initialization of the `High` property in the `GeneratedImageQuality` struct from `HdValue` to `HighValue`. --- src/Custom/Images/GeneratedImageQuality.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Custom/Images/GeneratedImageQuality.cs b/src/Custom/Images/GeneratedImageQuality.cs index f5e68ebe..9f4feff7 100644 --- a/src/Custom/Images/GeneratedImageQuality.cs +++ b/src/Custom/Images/GeneratedImageQuality.cs @@ -29,7 +29,7 @@ public readonly partial struct GeneratedImageQuality /// /// [CodeGenMember("High")] - public static GeneratedImageQuality High { get; } = new GeneratedImageQuality(HdValue); + public static GeneratedImageQuality High { get; } = new GeneratedImageQuality(HighValue); /// /// Medium quality level. /// From f11530718f46e425b799bb3d328947d14c5045b1 Mon Sep 17 00:00:00 2001 From: Benjamin Stern <1266727+benjamin-stern@users.noreply.github.com> Date: Tue, 3 Jun 2025 14:33:20 +0300 Subject: [PATCH 3/4] Disable central package management in project file Added `` set to `false` for improved control over package versions. The `` element remains unchanged but is now positioned after the new element. --- src/OpenAI.csproj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OpenAI.csproj b/src/OpenAI.csproj index aaa57a36..d79c6641 100644 --- a/src/OpenAI.csproj +++ b/src/OpenAI.csproj @@ -11,7 +11,10 @@ 2.2.0 beta.4 - net8.0;net6.0;netstandard2.0 + + false + + net8.0;net6.0;netstandard2.0 latest From 3852dcec7a5f058437c562126a2b16ed4e1dfeaf Mon Sep 17 00:00:00 2001 From: Benjamin Stern <1266727+benjamin-stern@users.noreply.github.com> Date: Tue, 1 Jul 2025 17:23:05 +0300 Subject: [PATCH 4/4] Add model identifier constants to InternalCreateResponsesRequestModel This commit introduces two new constant string values, `O4MiniValue` and `O3Value`, to the `InternalCreateResponsesRequestModel` struct in the `OpenAI.Responses` namespace. These constants represent specific model identifiers for use in API requests or responses. --- src/Generated/Models/InternalCreateResponsesRequestModel.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Generated/Models/InternalCreateResponsesRequestModel.cs b/src/Generated/Models/InternalCreateResponsesRequestModel.cs index b5b312d8..44932a73 100644 --- a/src/Generated/Models/InternalCreateResponsesRequestModel.cs +++ b/src/Generated/Models/InternalCreateResponsesRequestModel.cs @@ -11,6 +11,8 @@ namespace OpenAI.Responses internal readonly partial struct InternalCreateResponsesRequestModel : IEquatable { private readonly string _value; + private const string O4MiniValue = "o4-mini"; + private const string O3Value = "o3"; private const string O3MiniValue = "o3-mini"; private const string O3Mini20250131Value = "o3-mini-2025-01-31"; private const string O1Value = "o1";