From 573aa8540ee849a3cfd8aa905fa59ab810009a4b Mon Sep 17 00:00:00 2001 From: Mike Cutalo Date: Mon, 6 Nov 2023 18:33:20 -0800 Subject: [PATCH 1/5] add support for new image/generation api --- image.go | 20 ++++++++++++++++++++ image_api_test.go | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/image.go b/image.go index 4addcdb1e..d5bb9a364 100644 --- a/image.go +++ b/image.go @@ -13,6 +13,9 @@ const ( CreateImageSize256x256 = "256x256" CreateImageSize512x512 = "512x512" CreateImageSize1024x1024 = "1024x1024" + // dall-e-3 supported only + CreateImageSize1792x1024 = "1792x1024" + CreateImageSize1024x1792 = "1024x1792" ) const ( @@ -20,11 +23,28 @@ const ( CreateImageResponseFormatB64JSON = "b64_json" ) +const ( + CreateImageModelDallE2 = "dall-e-2" + CreateImageModelDallE3 = "dall-e-3" +) + +const ( + CreateImageQualityHD = "hd" +) + +const ( + CreateImageStyleVivid = "vivid" + CreateImageStyleNatural = "natural" +) + // ImageRequest represents the request structure for the image API. type ImageRequest struct { Prompt string `json:"prompt,omitempty"` + Model string `json:"model,omitempty"` N int `json:"n,omitempty"` + Quality string `json:"quality,omitempty"` Size string `json:"size,omitempty"` + Style string `json:"style,omitempty"` ResponseFormat string `json:"response_format,omitempty"` User string `json:"user,omitempty"` } diff --git a/image_api_test.go b/image_api_test.go index b472eb04a..5b9dc8de7 100644 --- a/image_api_test.go +++ b/image_api_test.go @@ -19,7 +19,14 @@ func TestImages(t *testing.T) { defer teardown() server.RegisterHandler("/v1/images/generations", handleImageEndpoint) _, err := client.CreateImage(context.Background(), ImageRequest{ - Prompt: "Lorem ipsum", + Prompt: "Lorem ipsum", + Model: CreateImageModelDallE3, + N: 1, + Quality: CreateImageQualityHD, + Size: CreateImageSize1024x1024, + Style: CreateImageStyleVivid, + ResponseFormat: CreateImageResponseFormatURL, + User: "user", }) checks.NoError(t, err, "CreateImage error") } From ce4ea94dddd27c75acf5c0be24c9c8db1b7d459f Mon Sep 17 00:00:00 2001 From: Mike Cutalo Date: Mon, 6 Nov 2023 18:50:54 -0800 Subject: [PATCH 2/5] fix one lint --- image.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image.go b/image.go index d5bb9a364..2d95c7d7f 100644 --- a/image.go +++ b/image.go @@ -13,7 +13,7 @@ const ( CreateImageSize256x256 = "256x256" CreateImageSize512x512 = "512x512" CreateImageSize1024x1024 = "1024x1024" - // dall-e-3 supported only + // dall-e-3 supported only. CreateImageSize1792x1024 = "1792x1024" CreateImageSize1024x1792 = "1024x1792" ) From d1e73b02661035e1c503f2befeb5095e20a84453 Mon Sep 17 00:00:00 2001 From: Mike Cutalo Date: Mon, 6 Nov 2023 20:58:42 -0800 Subject: [PATCH 3/5] add revised_prompt to response --- image.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/image.go b/image.go index 2d95c7d7f..8276abf7a 100644 --- a/image.go +++ b/image.go @@ -59,8 +59,9 @@ type ImageResponse struct { // ImageResponseDataInner represents a response data structure for image API. type ImageResponseDataInner struct { - URL string `json:"url,omitempty"` - B64JSON string `json:"b64_json,omitempty"` + URL string `json:"url,omitempty"` + B64JSON string `json:"b64_json,omitempty"` + RevisedPrompt string `json:"revised_prompt,omitempty"` } // CreateImage - API call to create an image. This is the main endpoint of the DALL-E API. From 924bd066d400286d5ed7d6003eb42ca377377360 Mon Sep 17 00:00:00 2001 From: Mike Cutalo Date: Tue, 7 Nov 2023 08:37:52 -0800 Subject: [PATCH 4/5] fix lints --- image_api_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/image_api_test.go b/image_api_test.go index 0623b5306..2eb46f2b4 100644 --- a/image_api_test.go +++ b/image_api_test.go @@ -20,12 +20,12 @@ func TestImages(t *testing.T) { server.RegisterHandler("/v1/images/generations", handleImageEndpoint) _, err := client.CreateImage(context.Background(), openai.ImageRequest{ Prompt: "Lorem ipsum", - Model: CreateImageModelDallE3, + Model: openai.CreateImageModelDallE3, N: 1, - Quality: CreateImageQualityHD, - Size: CreateImageSize1024x1024, - Style: CreateImageStyleVivid, - ResponseFormat: CreateImageResponseFormatURL, + Quality: openai.CreateImageQualityHD, + Size: openai.CreateImageSize1024x1024, + Style: openai.CreateImageStyleVivid, + ResponseFormat: openai.CreateImageResponseFormatURL, User: "user", }) checks.NoError(t, err, "CreateImage error") From bbfebb4604a53b49b0d5f4dda21211d2355c8718 Mon Sep 17 00:00:00 2001 From: Mike Cutalo Date: Tue, 7 Nov 2023 21:31:27 -0800 Subject: [PATCH 5/5] add CreateImageQualityStandard --- image.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/image.go b/image.go index 8276abf7a..4fe8b3a32 100644 --- a/image.go +++ b/image.go @@ -29,7 +29,8 @@ const ( ) const ( - CreateImageQualityHD = "hd" + CreateImageQualityHD = "hd" + CreateImageQualityStandard = "standard" ) const (