Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues #204. #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenAI_API/EndpointBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <see cref="OpenAIAPI"/>.
/// </summary>
/// <param name="api"></param>
internal EndpointBase(OpenAIAPI api)
protected EndpointBase(OpenAIAPI api)
{
this._Api = api;
}
Expand Down
23 changes: 17 additions & 6 deletions OpenAI_Tests/ImageGenerationEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<ArgumentException>(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<ArgumentException>(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]
Expand All @@ -157,6 +157,17 @@ public void BadNumImagesWithDalle3ShouldFail()
Assert.ThrowsAsync<Newtonsoft.Json.JsonSerializationException>(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
};


}
}