From 744db42ff979fabd7970aa72b10c02c42cba026d Mon Sep 17 00:00:00 2001 From: Zeeshan Mustafa Date: Mon, 6 May 2024 22:01:47 +0500 Subject: [PATCH] Fixed issues #204. 1. Improved ImageGenerationEndpointTests by introducing ImageSize construction helper method in orther to retain access level of ImageSize constructor. 2. Corrected EndpointBase constructor access level (changed to 'protected') in order to support HttpClientResolutionTests --- OpenAI_API/EndpointBase.cs | 2 +- OpenAI_Tests/ImageGenerationEndpointTests.cs | 23 +++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/OpenAI_API/EndpointBase.cs b/OpenAI_API/EndpointBase.cs index d981c7e..20556db 100644 --- a/OpenAI_API/EndpointBase.cs +++ b/OpenAI_API/EndpointBase.cs @@ -27,7 +27,7 @@ public abstract class EndpointBase /// Constructor of the api endpoint base, to be called from the contructor of any devived classes. Rather than instantiating any endpoint yourself, access it through an instance of . /// /// - internal EndpointBase(OpenAIAPI api) + protected EndpointBase(OpenAIAPI api) { this._Api = api; } diff --git a/OpenAI_Tests/ImageGenerationEndpointTests.cs b/OpenAI_Tests/ImageGenerationEndpointTests.cs index 94c31fb..9a241b2 100644 --- a/OpenAI_Tests/ImageGenerationEndpointTests.cs +++ b/OpenAI_Tests/ImageGenerationEndpointTests.cs @@ -51,8 +51,8 @@ public void CreateDALLE2ImageWithUrl(string size) var api = new OpenAI_API.OpenAIAPI(); Assert.IsNotNull(api.ImageGenerations); - - var results = api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest("A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art", 2, new ImageSize(size))).Result; + + var results = api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest("A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art", 2, ConstructImageSize(size))).Result; Assert.IsNotNull(results); if (results.CreatedUnixTime.HasValue) { @@ -108,9 +108,9 @@ public void CreateDALLE3ImageWithUrl(string quality, string size) { var api = new OpenAI_API.OpenAIAPI(); - Assert.IsNotNull(api.ImageGenerations); + Assert.IsNotNull(api.ImageGenerations); - var results = api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest("A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art", OpenAI_API.Models.Model.DALLE3, new ImageSize(size), quality)).Result; + var results = api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest("A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art", OpenAI_API.Models.Model.DALLE3, ConstructImageSize(size), quality)).Result; Assert.IsNotNull(results); if (results.CreatedUnixTime.HasValue) { @@ -139,9 +139,9 @@ public void BadParameterCombosShouldFail(string model, string quality, string si { var api = new OpenAI_API.OpenAIAPI(); - Assert.IsNotNull(api.ImageGenerations); + Assert.IsNotNull(api.ImageGenerations); - Assert.ThrowsAsync(async () => await api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest("A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art", model, new ImageSize(size), quality))); + Assert.ThrowsAsync(async () => await api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest("A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art", model, ConstructImageSize(size), quality))); } [Test] @@ -157,6 +157,17 @@ public void BadNumImagesWithDalle3ShouldFail() Assert.ThrowsAsync(async () => await api.ImageGenerations.CreateImageAsync(req)); } + private ImageSize ConstructImageSize(string size) + => size switch + { + "256x256" => ImageSize._256, + "512x512" => ImageSize._512, + "1024x1024" => ImageSize._1024, + "1024x1792" => ImageSize._1024x1792, + "1792x1024" => ImageSize._1792x1024, + _ => ImageSize._256 + }; + } }