Skip to content

Commit

Permalink
WithREST w/o arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Feb 8, 2024
1 parent 9c2d68a commit 499320a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions vertexai/genai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Client struct {
//
// You may configure the client by passing in options from the
// [google.golang.org/api/option] package. You may also use options defined in
// this package, such as [WithUseREST].
// this package, such as [WithREST].
func NewClient(ctx context.Context, projectID, location string, opts ...option.ClientOption) (*Client, error) {
opts = append([]option.ClientOption{
option.WithEndpoint(fmt.Sprintf("%s-aiplatform.googleapis.com:443", location)),
Expand All @@ -57,7 +57,7 @@ func NewClient(ctx context.Context, projectID, location string, opts ...option.C

var c *aiplatform.PredictionClient
var err error
if conf.useREST {
if conf.withREST {
c, err = aiplatform.NewPredictionRESTClient(ctx, opts...)
} else {
c, err = aiplatform.NewPredictionClient(ctx, opts...)
Expand Down
2 changes: 1 addition & 1 deletion vertexai/genai/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestLiveREST(t *testing.T) {
t.Skip("need -project and -model")
}
ctx := context.Background()
client, err := NewClient(ctx, *projectID, "us-central1", WithUseREST(true))
client, err := NewClient(ctx, *projectID, "us-central1", WithREST())
if err != nil {
t.Fatal(err)
}
Expand Down
20 changes: 9 additions & 11 deletions vertexai/genai/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@ import (
"google.golang.org/api/option/internaloption"
)

// WithUseREST is an option that may be passed to a Vertex AI client on
// creation. If true, the client will use REST for transport; if false (default),
// the client will use gRPC for transport.
func WithUseREST(b bool) option.ClientOption {
return &withUseREST{useREST: b}
// WithREST is an option that enables REST transport for the client.
// The default transport (if this option isn't provided) is gRPC.
func WithREST() option.ClientOption {
return &withREST{}
}

func (w *withUseREST) applyVertexaiOpt(c *config) {
c.useREST = w.useREST
func (w *withREST) applyVertexaiOpt(c *config) {
c.withREST = true
}

type config struct {
// useREST uses REST as the underlying transport for the client.
useREST bool
// withREST tells the client to use REST as the underlying transport.
withREST bool
}

// newConfig generates a new config with all the given
Expand All @@ -53,7 +52,6 @@ type vertexaiClientOption interface {
applyVertexaiOpt(*config)
}

type withUseREST struct {
type withREST struct {
internaloption.EmbeddableAdapter
useREST bool
}

0 comments on commit 499320a

Please sign in to comment.