diff --git a/src/OpenAI.ChatGpt/OpenAiClient.cs b/src/OpenAI.ChatGpt/OpenAiClient.cs index 8fbd038..69dffc8 100644 --- a/src/OpenAI.ChatGpt/OpenAiClient.cs +++ b/src/OpenAI.ChatGpt/OpenAiClient.cs @@ -357,72 +357,4 @@ public IAsyncEnumerable StreamChatCompletionsRaw( cancellationToken ); } - - // Will be moved to a separate package. - internal async Task GenerateImageBytes( - string prompt, - string? user = null, - OpenAiImageSize size = OpenAiImageSize._1024, - CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(prompt)) - throw new ArgumentException("Value cannot be null or whitespace.", nameof(prompt)); - var request = new ImageGenerationRequest(prompt, SizeToString(size), 1, "b64_json", user); - var response = await _httpClient.PostAsJsonAsync( - ImagesEndpoint, - request, - cancellationToken: cancellationToken - ); - var responseContent = await response.Content.ReadAsStringAsync(cancellationToken); - - if (!response.IsSuccessStatusCode) - { - throw new NotExpectedResponseException(response.StatusCode, responseContent); - } - - var jsonResponse = - JsonSerializer.Deserialize(responseContent)!; - return Convert.FromBase64String(jsonResponse.Data[0].B64Json); - } - - // Will be moved to a separate package. - internal async Task GenerateImagesUris( - string prompt, - string? user = null, - OpenAiImageSize size = OpenAiImageSize._1024, - int count = 1, - CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(prompt)) - throw new ArgumentException("Value cannot be null or whitespace.", nameof(prompt)); - if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count)); - var request = new ImageGenerationRequest(prompt, SizeToString(size), count, "url", user); - var response = await _httpClient.PostAsJsonAsync( - ImagesEndpoint, - request, - options: _nullIgnoreSerializerOptions, - cancellationToken: cancellationToken - ); - var responseContent = await response.Content.ReadAsStringAsync(cancellationToken); - - if (!response.IsSuccessStatusCode) - { - throw new NotExpectedResponseException(response.StatusCode, responseContent); - } - - var jsonResponse = - JsonSerializer.Deserialize(responseContent)!; - return jsonResponse.Data.Select(it => it.Url).ToArray(); - } - - private static string SizeToString(OpenAiImageSize size) - { - return size switch - { - OpenAiImageSize._256 => "256x256", - OpenAiImageSize._512 => "512x512", - OpenAiImageSize._1024 => "1024x1024", - _ => throw new ArgumentOutOfRangeException(nameof(size), size, null) - }; - } } \ No newline at end of file diff --git a/tests/OpenAI.ChatGpt.IntegrationTests/OpenAiClientTests/ImagesApiTest.cs b/tests/OpenAI.ChatGpt.IntegrationTests/OpenAiClientTests/ImagesApiTest.cs deleted file mode 100644 index fc7dc0f..0000000 --- a/tests/OpenAI.ChatGpt.IntegrationTests/OpenAiClientTests/ImagesApiTest.cs +++ /dev/null @@ -1,31 +0,0 @@ -using OpenAI.ChatGpt.Models.Images; -using OpenAI.Tests.Shared; - -namespace OpenAI.ChatGpt.IntegrationTests.OpenAiClientTests; - -[Collection("OpenAiTestCollection")] //to prevent parallel execution -public class ImagesApiTest -{ - private readonly ITestOutputHelper _outputHelper; - private readonly OpenAiClient _client; - - public ImagesApiTest(ITestOutputHelper outputHelper) - { - _outputHelper = outputHelper; - _client = new OpenAiClient(Helpers.GetOpenAiKey()); - } - - [Fact(Skip = "Images API will be removed")] - public async void Generate_image_bytes_works() - { - byte[] image = await _client.GenerateImageBytes("bicycle", "test", OpenAiImageSize._256); - image.Should().NotBeEmpty(); - } - - [Fact(Skip = "Images API will be removed")] - public async void Generate_two_images_uri_works() - { - Uri[] uris = await _client.GenerateImagesUris("bicycle", size: OpenAiImageSize._256, count: 2); - uris.Should().HaveCount(2); - } -} \ No newline at end of file