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

Support new fields for /v1/images/generation API #530

Merged
merged 6 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,38 @@ const (
CreateImageSize256x256 = "256x256"
CreateImageSize512x512 = "512x512"
CreateImageSize1024x1024 = "1024x1024"
// dall-e-3 supported only.
CreateImageSize1792x1024 = "1792x1024"
CreateImageSize1024x1792 = "1024x1792"
)

const (
CreateImageResponseFormatURL = "url"
CreateImageResponseFormatB64JSON = "b64_json"
)

const (
CreateImageModelDallE2 = "dall-e-2"
CreateImageModelDallE3 = "dall-e-3"
)

const (
CreateImageQualityHD = "hd"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikecutalo
Sometimes you may want to explicitly specify default values in the code. Please add the following as well.

CreateImageQualityStandard = "standard"

image

https://platform.openai.com/docs/api-reference/images/create#images-create-quality

)

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"`
}
Expand All @@ -39,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.
Expand Down
9 changes: 8 additions & 1 deletion image_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ func TestImages(t *testing.T) {
defer teardown()
server.RegisterHandler("/v1/images/generations", handleImageEndpoint)
_, err := client.CreateImage(context.Background(), openai.ImageRequest{
Prompt: "Lorem ipsum",
Prompt: "Lorem ipsum",
Model: openai.CreateImageModelDallE3,
N: 1,
Quality: openai.CreateImageQualityHD,
Size: openai.CreateImageSize1024x1024,
Style: openai.CreateImageStyleVivid,
ResponseFormat: openai.CreateImageResponseFormatURL,
User: "user",
})
checks.NoError(t, err, "CreateImage error")
}
Expand Down
Loading