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

image: Add support for different models #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions image/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type CreateParams struct {
Size string `json:"size,omitempty"`
Format string `json:"response_format,omitempty"`
User string `json:"user,omitempty"`
Model string `json:"model,omitempty"`
}

type CreateResponse struct {
Expand All @@ -17,6 +18,9 @@ type CreateResponse struct {
}

func (c *Client) Create(ctx context.Context, p *CreateParams) (*CreateResponse, error) {
if p.Model == "" {
p.Model = c.model
}
var r CreateResponse
if err := c.s.MakeRequest(ctx, c.CreateEndpoint, p, &r); err != nil {
return nil, err
Expand Down
13 changes: 11 additions & 2 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,31 @@ import (
)

const (
DallE2 = "dall-e-2"
DallE3 = "dall-e-3"
defaultCreateEndpoint = "https://api.openai.com/v1/images/generations"
defaultModel = DallE2
)

// Client is a client to communicate with Open AI's images API.
type Client struct {
s *openai.Session
s *openai.Session
model string

// CreateEndpoint allows overriding the default
// for the image generation API endpoint.
// Set this field before using the client.
CreateEndpoint string
}

func NewClient(session *openai.Session) *Client {
func NewClient(session *openai.Session, model ...string) *Client {
m := defaultModel
if len(model) > 0 {
m = model[0]
}
return &Client{
s: session,
model: m,
CreateEndpoint: defaultCreateEndpoint,
}
}
Expand Down