go-openai icon indicating copy to clipboard operation
go-openai copied to clipboard

Issue while invoking Edit Image API

Open mohitkanwar opened this issue 1 year ago • 1 comments

Describe the bug While integrating with the latest Edit Image API (POST https://api.openai.com/v1/images/edits) by using the following code :

req := openai.ImageEditRequest{Image: file, Mask: maskFile, Prompt: prompt, N: count, Size: size, ResponseFormat: responseFormat}

	response, err = srvc.client.CreateEditImage(context.Background(), req)

We are getting the following error response from openAI :

error, status code: 500, message: The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID XXXXXXXXXXX in your email.)

This is a consistent response. However, if we hit the API using HTTP client directly, it works fine.

The examples do not contain the examples on using this API, and the tests are working fine with mock. So I am a bit stuck on using this client for Edit Images API

Environment :

  • go-openai version: v1.16.0
  • Go version: 1.21
  • OpenAI API version: v1

mohitkanwar avatar Nov 21 '23 07:11 mohitkanwar

You may test the integration test by adding the following code :

filePath := "/image.png" // Replace with your file path

// Open the file
file, err := os.Open(filePath)
if err != nil {
	log.Println("Error opening file:", err)
	//fmt.Println("Error opening file:", err)
	return
}
defer file.Close()

_, err = c.CreateEditImage(
	ctx, openai.ImageEditRequest{
		Image:  file,
		Mask:   nil,
		Size:   openai.CreateImageSize1024x1024,
		N:      1,
		Prompt: "Please add India's flag at the background",
	})
log.Println("Error executing request file:", err)
checks.NoError(t, err, "CreateEditImage returned error")

mohitkanwar avatar Nov 21 '23 09:11 mohitkanwar