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

CreateImageEdit Throw Exception if Mask is null #66

Closed
hanialaraj opened this issue Jan 10, 2023 · 0 comments · Fixed by #68
Closed

CreateImageEdit Throw Exception if Mask is null #66

hanialaraj opened this issue Jan 10, 2023 · 0 comments · Fixed by #68
Assignees

Comments

@hanialaraj
Copy link

Describe the bug
When calling CreateImageEdit method, and passing ImageEditCreateRequest object to the method, if the optional parameter "Mask" is not set, it throws an exception
Value cannot be null. (Parameter 'content')|System.ArgumentNullException: Value cannot be null. (Parameter 'content') at System.Net.Http.ByteArrayContent..ctor(Byte[] content) at OpenAI.GPT3.Managers.OpenAIService.CreateImageEdit(ImageEditCreateRequest imageEditCreateRequest)

Your code piece

var imageCreateResponse = await _openAIService.Image.CreateImageEdit(new ImageEditCreateRequest()
{
    Size = "512x512",
    N = 1,
    ImageName = "123456",
    Image = fileBytes,
    User = Cryptography.SHA1Hash("123456789", true),
    Prompt = "Robot, AI"

});

From the SDK source code, there is no check on Mask property before adding it to the request

multipartContent.Add(new ByteArrayContent(imageEditCreateRequest.Mask), "mask", imageEditCreateRequest.MaskName);

public async Task<ImageCreateResponse> CreateImageEdit(ImageEditCreateRequest imageEditCreateRequest)
    {
        var multipartContent = new MultipartFormDataContent();
        if (imageEditCreateRequest.User != null) multipartContent.Add(new StringContent(imageEditCreateRequest.User), "user");
        if (imageEditCreateRequest.ResponseFormat != null) multipartContent.Add(new StringContent(imageEditCreateRequest.ResponseFormat), "response_format");
        if (imageEditCreateRequest.Size != null) multipartContent.Add(new StringContent(imageEditCreateRequest.Size), "size");
        if (imageEditCreateRequest.N != null) multipartContent.Add(new StringContent(imageEditCreateRequest.N.ToString()!), "n");

        multipartContent.Add(new StringContent(imageEditCreateRequest.Prompt), "prompt");
        multipartContent.Add(new ByteArrayContent(imageEditCreateRequest.Image), "image", imageEditCreateRequest.ImageName);
        multipartContent.Add(new ByteArrayContent(imageEditCreateRequest.Mask), "mask", imageEditCreateRequest.MaskName);

        return await _httpClient.PostFileAndReadAsAsync<ImageCreateResponse>(_endpointProvider.ImageEditCreate(), multipartContent);
    }
@kayhantolga kayhantolga self-assigned this Jan 10, 2023
@kayhantolga kayhantolga linked a pull request Jan 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants