Skip to content

Commit

Permalink
Dalle image additions (#80)
Browse files Browse the repository at this point in the history
* Added Model, Style and Quality properties to ImageGenerationRequest.
Updated some failing tests

* Update doc strings

* Increment package version
  • Loading branch information
jodendaal committed Nov 10, 2023
1 parent 6636855 commit ef69f0b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 26 deletions.
16 changes: 8 additions & 8 deletions src/OpenAI.Net.Integration.Tests/AudioService_Transcription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public async Task GetTranscription(string model,bool isSuccess, HttpStatusCode s

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Text?.Contains("Testing")??false, Is.EqualTo(isSuccess), "Should contain the word Testing");
Assert.That(response.Result?.Text?.Contains("1") ?? false, Is.EqualTo(isSuccess), "Should contain the word 1");
Assert.That(response.Result?.Text?.Contains("2") ?? false, Is.EqualTo(isSuccess), "Should contain the word 2");
Assert.That(response.Result?.Text?.Contains("3") ?? false, Is.EqualTo(isSuccess), "Should contain the word 3");
Assert.That(response.Result?.Text?.ToLowerInvariant().Contains("testing")??false, Is.EqualTo(isSuccess), "Should contain the word Testing");
Assert.That((response.Result?.Text?.Contains("1") ?? false) || (response.Result?.Text?.ToLowerInvariant().Contains("one") ?? false), Is.EqualTo(isSuccess), "Should contain the word 1 or one");
Assert.That((response.Result?.Text?.Contains("2") ?? false) || (response.Result?.Text?.ToLowerInvariant().Contains("two") ?? false), Is.EqualTo(isSuccess), "Should contain the word 2 or two");
Assert.That((response.Result?.Text?.Contains("3") ?? false) || (response.Result?.Text?.ToLowerInvariant().Contains("three") ?? false), Is.EqualTo(isSuccess), "Should contain the word 3 or three");
}

[TestCase(ModelTypes.Whisper1, true, HttpStatusCode.OK, TestName = "GetTranscriptionWithExtension_When_Success")]
Expand All @@ -32,10 +32,10 @@ public async Task GetTranscriptionWithExtension(string model, bool isSuccess, Ht

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Text?.Contains("Testing") ?? false, Is.EqualTo(isSuccess), "Should contain the word Testing");
Assert.That(response.Result?.Text?.Contains("1") ?? false, Is.EqualTo(isSuccess), "Should contain the word 1");
Assert.That(response.Result?.Text?.Contains("2") ?? false, Is.EqualTo(isSuccess), "Should contain the word 2");
Assert.That(response.Result?.Text?.Contains("3") ?? false, Is.EqualTo(isSuccess), "Should contain the word 3");
Assert.That(response.Result?.Text?.ToLowerInvariant().Contains("testing") ?? false, Is.EqualTo(isSuccess), "Should contain the word Testing");
Assert.That((response.Result?.Text?.Contains("1") ?? false) || (response.Result?.Text?.ToLowerInvariant().Contains("one") ?? false), Is.EqualTo(isSuccess), "Should contain the word 1 or one");
Assert.That((response.Result?.Text?.Contains("2") ?? false) || (response.Result?.Text?.ToLowerInvariant().Contains("two") ?? false), Is.EqualTo(isSuccess), "Should contain the word 2 or two");
Assert.That((response.Result?.Text?.Contains("3") ?? false) || (response.Result?.Text?.ToLowerInvariant().Contains("three") ?? false), Is.EqualTo(isSuccess), "Should contain the word 3 or three");
}

}
Expand Down
30 changes: 15 additions & 15 deletions src/OpenAI.Net.Integration.Tests/ChatCompletionService_Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Get(string model, bool isSuccess, HttpStatusCode statusCode)
Assert.That(response.Result?.Choices?.Count() == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
if (isSuccess)
{
Assert.That(response.Result!.Choices.FirstOrDefault()!.Message.Content.Trim(), Is.EqualTo("This is a test."), "Choices are not mapped correctly");
Assert.That(response.Result!.Choices.FirstOrDefault()!.Message.Content.ToLowerInvariant(), Contains.Substring("this is a test"), "Choices are not mapped correctly");
}
}

Expand Down Expand Up @@ -58,20 +58,20 @@ public async Task GetWithListExtension(string model, bool isSuccess, HttpStatusC
}

[Test]
public async Task TetEditReplacement()
{
var messages = new List<Message>
{
Message.Create(ChatRoleType.System, "You are a spell checker. Fix the spelling mistakes"),
Message.Create(ChatRoleType.User, "What day of the wek is it?"),
};

var response = await OpenAIService.Chat.Get(messages, o => {
o.MaxTokens = 1000;
});

Assert.That(response.IsSuccess, Is.True);
Assert.That(response.Result?.Choices[0].Message.Content, Is.EqualTo("What day of the week is it?"));
public async Task TetEditReplacement()
{
var messages = new List<Message>
{
Message.Create(ChatRoleType.System, "You are a spell checker. Fix the spelling mistakes"),
Message.Create(ChatRoleType.User, "What day of the wek is it?"),
};

var response = await OpenAIService.Chat.Get(messages, o => {
o.MaxTokens = 1000;
});

Assert.That(response.IsSuccess, Is.True);
Assert.That(response.Result?.Choices[0].Message.Content, Is.EqualTo("What day of the week is it?"));
}
}
}
4 changes: 2 additions & 2 deletions src/OpenAI.Net.Integration.Tests/ImageService_Generate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task Generate(string prompt,int noOfImages,bool isSuccess, HttpStat
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Data?.Count() == noOfImages, Is.EqualTo(isSuccess), "Data is not mapped correctly");
Assert.That(response.Result?.Data?[0].Url?.Contains("https://"), isSuccess ? Is.EqualTo(isSuccess) : Is.EqualTo(null), "Choice text not set");
Assert.That(response.ErrorResponse?.Error?.Message?.Contains("is not one of ['256x256', '512x512', '1024x1024']"), isSuccess ? Is.EqualTo(null) : Is.EqualTo(true),"Error message not returned");
Assert.That(response.ErrorResponse?.Error?.Message?.Contains("is not one of ['256x256', '512x512', '1024x1024', '1024x1792', '1792x1024']"), isSuccess ? Is.EqualTo(null) : Is.EqualTo(true),"Error message not returned");
}

[TestCase("A cute baby sea otter", 1, true, HttpStatusCode.OK, "256x256", TestName = "GenerateBase64_When_Success")]
Expand All @@ -41,7 +41,7 @@ public async Task GenerateBase64(string prompt, int noOfImages, bool isSuccess,

Assert.IsNull(response.Result?.Data?[0].Url);
Assert.That(response.Result?.Data?[0].Base64 != null,Is.EqualTo(isSuccess));
Assert.That(response.ErrorResponse?.Error?.Message?.Contains("is not one of ['256x256', '512x512', '1024x1024']"), isSuccess ? Is.EqualTo(null) : Is.EqualTo(true), "Error message not returned");
Assert.That(response.ErrorResponse?.Error?.Message?.Contains("is not one of ['256x256', '512x512', '1024x1024', '1024x1792', '1792x1024']"), isSuccess ? Is.EqualTo(null) : Is.EqualTo(true), "Error message not returned");
}
}
}
3 changes: 3 additions & 0 deletions src/OpenAI.Net.Integration.Tests/ImageService_Variation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public async Task Variation_Base64ToFileContent(bool isSuccess, HttpStatusCode s
o.N = 1;
o.Size = "256x256";
o.ResponseFormat = ImageResponseFormat.Base64;
o.Style = ImageStyleOptions.Vivid;
o.Quality = ImageQualityOptions.HighDefinition;
o.Model = ImageModelOptions.Dalle2;
});


Expand Down
7 changes: 7 additions & 0 deletions src/OpenAI.Net/Models/ImageModelOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenAI.Net
{
public static class ImageModelOptions
{
public const string Dalle2 = "dall-e-2";
}
}
8 changes: 8 additions & 0 deletions src/OpenAI.Net/Models/ImageQualityOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OpenAI.Net
{
public static class ImageQualityOptions
{
public const string Standard = "standard";
public const string HighDefinition = "hd";
}
}
8 changes: 8 additions & 0 deletions src/OpenAI.Net/Models/ImageStyleOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OpenAI.Net
{
public static class ImageStyleOptions
{
public const string Vivid = "vivid";
public const string Natural = "natural";
}
}
2 changes: 1 addition & 1 deletion src/OpenAI.Net/OpenAI.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/jodendaal/OpenAI.Net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>1.0.20.0</AssemblyVersion>
<AssemblyVersion>1.0.21.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand Down

0 comments on commit ef69f0b

Please sign in to comment.