Skip to content

Commit

Permalink
docs: client.go docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoaguirre committed Feb 11, 2025
1 parent 817bc06 commit 1caa09c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions go/plugins/vertexai/modelgarden/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ type ClientConfig struct {
Region string
}

// ClientCreator is a function type that will be defined on every provider in order to create its
// client
type ClientCreator func(config any) (Client, error)

// Register adds the client creator function to a cache for later use
func (f *ClientFactory) Register(provider string, creator ClientCreator) {
if _, ok := f.creators[provider]; !ok {
f.creators[provider] = creator
}
}

// CreateClient creates a client with the given configuration
// A [ClientCreator] must have been previously registered
func (f *ClientFactory) CreateClient(config *ClientConfig) (Client, error) {
if config == nil {
return nil, errors.New("empty client config")
Expand All @@ -67,6 +72,7 @@ func (f *ClientFactory) CreateClient(config *ClientConfig) (Client, error) {
var client Client
var err error
switch config.Provider {
// TODO: add providers when needed
case AnthropicProvider:
client, err = creator(&AnthropicClientConfig{
Region: config.Region,
Expand Down

0 comments on commit 1caa09c

Please sign in to comment.