Repository: sashabaranov/go-openai
Pull request #264 (2023-04-18 08:48:33)

add ImageVariRequest/ImageEditRequest.ResponseFormat

codecov[bot]: ## [Codecov](https://codecov.io/gh/sashabaranov/go-openai/pull/264?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#264](https://codecov.io/gh/sashabaranov/go-openai/pull/264?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (0423b07) into [master](https://codecov.io/gh/sashabaranov/go-openai/commit/061c97ef7ee75e3ad782797cb46925949e548746?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (061c97e) will **increase** coverage by `0.10%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master     #264      +/-   ##
==========================================
+ Coverage   91.45%   91.56%   +0.10%     
==========================================
  Files          22       22              
  Lines         620      628       +8     
==========================================
+ Hits          567      575       +8     
  Misses         39       39              
  Partials       14       14              
```


| [Impacted Files](https://codecov.io/gh/sashabaranov/go-openai/pull/264?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [image.go](https://codecov.io/gh/sashabaranov/go-openai/pull/264?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-aW1hZ2UuZ28=) | `92.77% <100.00%> (+0.77%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/image.go b/image.go
index bda23f7..21703bd 100644
--- a/image.go
+++ b/image.go
@@ -55,11 +55,12 @@ func (c *Client) CreateImage(ctx context.Context, request ImageRequest) (respons
 
 // ImageEditRequest represents the request structure for the image API.
 type ImageEditRequest struct {
-	Image  *os.File `json:"image,omitempty"`
-	Mask   *os.File `json:"mask,omitempty"`
-	Prompt string   `json:"prompt,omitempty"`
-	N      int      `json:"n,omitempty"`
-	Size   string   `json:"size,omitempty"`
+	Image          *os.File `json:"image,omitempty"`
+	Mask           *os.File `json:"mask,omitempty"`
+	Prompt         string   `json:"prompt,omitempty"`
+	N              int      `json:"n,omitempty"`
+	Size           string   `json:"size,omitempty"`
+	ResponseFormat string   `json:"response_format,omitempty"`
 }
 
 // CreateEditImage - API call to create an image. This is the main endpoint of the DALL-E API.
@@ -85,14 +86,22 @@ func (c *Client) CreateEditImage(ctx context.Context, request ImageEditRequest)
 	if err != nil {
 		return
 	}
+
 	err = builder.writeField("n", strconv.Itoa(request.N))
 	if err != nil {
 		return
 	}
+
 	err = builder.writeField("size", request.Size)
 	if err != nil {
 		return
 	}
+
+	err = builder.writeField("response_format", request.ResponseFormat)
+	if err != nil {
+		return
+	}
+
 	err = builder.close()
 	if err != nil {
 		return
@@ -111,9 +120,10 @@ func (c *Client) CreateEditImage(ctx context.Context, request ImageEditRequest)
 
 // ImageVariRequest represents the request structure for the image API.
 type ImageVariRequest struct {
-	Image *os.File `json:"image,omitempty"`
-	N     int      `json:"n,omitempty"`
-	Size  string   `json:"size,omitempty"`
+	Image          *os.File `json:"image,omitempty"`
+	N              int      `json:"n,omitempty"`
+	Size           string   `json:"size,omitempty"`
+	ResponseFormat string   `json:"response_format,omitempty"`
 }
 
 // CreateVariImage - API call to create an image variation. This is the main endpoint of the DALL-E API.
@@ -132,10 +142,17 @@ func (c *Client) CreateVariImage(ctx context.Context, request ImageVariRequest)
 	if err != nil {
 		return
 	}
+
 	err = builder.writeField("size", request.Size)
 	if err != nil {
 		return
 	}
+
+	err = builder.writeField("response_format", request.ResponseFormat)
+	if err != nil {
+		return
+	}
+
 	err = builder.close()
 	if err != nil {
 		return


Test patch:
diff --git a/image_test.go b/image_test.go
index 34367b8..4a7dad5 100644
--- a/image_test.go
+++ b/image_test.go
@@ -118,11 +118,12 @@ func TestImageEdit(t *testing.T) {
 	}()
 
 	req := ImageEditRequest{
-		Image:  origin,
-		Mask:   mask,
-		Prompt: "There is a turtle in the pool",
-		N:      3,
-		Size:   CreateImageSize1024x1024,
+		Image:          origin,
+		Mask:           mask,
+		Prompt:         "There is a turtle in the pool",
+		N:              3,
+		Size:           CreateImageSize1024x1024,
+		ResponseFormat: CreateImageResponseFormatURL,
 	}
 	_, err = client.CreateEditImage(ctx, req)
 	checks.NoError(t, err, "CreateImage error")
@@ -154,10 +155,11 @@ func TestImageEditWithoutMask(t *testing.T) {
 	}()
 
 	req := ImageEditRequest{
-		Image:  origin,
-		Prompt: "There is a turtle in the pool",
-		N:      3,
-		Size:   CreateImageSize1024x1024,
+		Image:          origin,
+		Prompt:         "There is a turtle in the pool",
+		N:              3,
+		Size:           CreateImageSize1024x1024,
+		ResponseFormat: CreateImageResponseFormatURL,
 	}
 	_, err = client.CreateEditImage(ctx, req)
 	checks.NoError(t, err, "CreateImage error")
@@ -220,9 +222,10 @@ func TestImageVariation(t *testing.T) {
 	}()
 
 	req := ImageVariRequest{
-		Image: origin,
-		N:     3,
-		Size:  CreateImageSize1024x1024,
+		Image:          origin,
+		N:              3,
+		Size:           CreateImageSize1024x1024,
+		ResponseFormat: CreateImageResponseFormatURL,
 	}
 	_, err = client.CreateVariImage(ctx, req)
 	checks.NoError(t, err, "CreateImage error")
@@ -336,6 +339,10 @@ func TestImageFormBuilderFailures(t *testing.T) {
 	_, err = client.CreateEditImage(ctx, req)
 	checks.ErrorIs(t, err, mockFailedErr, "CreateImage should return error if form builder fails")
 
+	failForField = "response_format"
+	_, err = client.CreateEditImage(ctx, req)
+	checks.ErrorIs(t, err, mockFailedErr, "CreateImage should return error if form builder fails")
+
 	failForField = ""
 	mockBuilder.mockClose = func() error {
 		return mockFailedErr
@@ -384,6 +391,10 @@ func TestVariImageFormBuilderFailures(t *testing.T) {
 	_, err = client.CreateVariImage(ctx, req)
 	checks.ErrorIs(t, err, mockFailedErr, "CreateVariImage should return error if form builder fails")
 
+	failForField = "response_format"
+	_, err = client.CreateVariImage(ctx, req)
+	checks.ErrorIs(t, err, mockFailedErr, "CreateVariImage should return error if form builder fails")
+
 	failForField = ""
 	mockBuilder.mockClose = func() error {
 		return mockFailedErr