Skip to content

Commit

Permalink
refactor!: Rename model and provider id to name (#218)
Browse files Browse the repository at this point in the history
Co-authored-by: Casey Waldren <[email protected]>
  • Loading branch information
keelerm84 and cwaldren-ld authored Dec 9, 2024
1 parent c301213 commit ebdc281
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions ldai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (c *Client) Config(
}

builder := NewConfig().
WithModelId(parsed.Model.Id).
WithProviderId(parsed.Provider.Id).
WithModelName(parsed.Model.Name).
WithProviderName(parsed.Provider.Name).
WithEnabled(parsed.Meta.Enabled)

for i, msg := range parsed.Messages {
Expand Down
8 changes: 4 additions & 4 deletions ldai/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ func TestCanSetDefaultConfigFields(t *testing.T) {
defaultVal := NewConfig().Enable().
WithMessage("hello", datamodel.User).
WithMessage("world", datamodel.System).
WithProviderId("provider").
WithModelId("model").Build()
WithProviderName("provider").
WithModelName("model").Build()

cfg, _ := client.Config("key", ldcontext.New("user"), defaultVal, nil)

assert.True(t, cfg.Enabled())
assert.Equal(t, "provider", cfg.ProviderId())
assert.Equal(t, "model", cfg.ModelId())
assert.Equal(t, "provider", cfg.ProviderName())
assert.Equal(t, "model", cfg.ModelName())
assert.Equal(t, 2, len(cfg.Messages()))

msg := cfg.Messages()
Expand Down
32 changes: 16 additions & 16 deletions ldai/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func (c *Config) Enabled() bool {
return c.c.Meta.Enabled
}

// ProviderId returns the provider ID associated with the config.
func (c *Config) ProviderId() string {
return c.c.Provider.Id
// ProviderName returns the provider name associated with the config.
func (c *Config) ProviderName() string {
return c.c.Provider.Name
}

// ModelId returns the model ID associated with the config.
func (c *Config) ModelId() string {
return c.c.Model.Id
// ModelName returns the model name associated with the config.
func (c *Config) ModelName() string {
return c.c.Model.Name
}

// ModelParam returns the model parameter named by key. The second parameter is true if the key exists.
Expand All @@ -60,8 +60,8 @@ func (c *Config) AsLdValue() ldvalue.Value {
type ConfigBuilder struct {
messages []datamodel.Message
enabled bool
providerId string
modelId string
providerName string
modelName string
modelParams map[string]ldvalue.Value
modelCustomParams map[string]ldvalue.Value
}
Expand Down Expand Up @@ -104,15 +104,15 @@ func (cb *ConfigBuilder) Disable() *ConfigBuilder {
return cb.WithEnabled(false)
}

// WithModelId sets the model ID associated with the config.
func (cb *ConfigBuilder) WithModelId(modelId string) *ConfigBuilder {
cb.modelId = modelId
// WithModelName sets the model name associated with the config.
func (cb *ConfigBuilder) WithModelName(modelName string) *ConfigBuilder {
cb.modelName = modelName
return cb
}

// WithProviderId sets the provider ID associated with the config.
func (cb *ConfigBuilder) WithProviderId(providerId string) *ConfigBuilder {
cb.providerId = providerId
// WithProviderName sets the provider name associated with the config.
func (cb *ConfigBuilder) WithProviderName(providerName string) *ConfigBuilder {
cb.providerName = providerName
return cb
}

Expand Down Expand Up @@ -140,12 +140,12 @@ func (cb *ConfigBuilder) Build() Config {
Enabled: cb.enabled,
},
Model: datamodel.Model{
Id: cb.modelId,
Name: cb.modelName,
Parameters: maps.Clone(cb.modelParams),
Custom: maps.Clone(cb.modelCustomParams),
},
Provider: datamodel.Provider{
Id: cb.providerId,
Name: cb.providerName,
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions ldai/datamodel/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type Meta struct {

// Model defines the serialization format for a model.
type Model struct {
// Id identifies the model.
Id string `json:"id"`
// Name identifies the model.
Name string `json:"name"`

// Parameters are the model parameters, generally provided by LaunchDarkly.
Parameters map[string]ldvalue.Value `json:"parameters,omitempty"`
Expand All @@ -25,8 +25,8 @@ type Model struct {

// Provider defines the serialization format for a model provider.
type Provider struct {
// Id identifies the provider.
Id string `json:"id"`
// Name identifies the provider.
Name string `json:"name"`
}

// Role defines the role of a message.
Expand Down
7 changes: 4 additions & 3 deletions ldai/tracker_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ldai

import (
"github.com/launchdarkly/go-server-sdk/ldai/datamodel"
"testing"
"time"

"github.com/launchdarkly/go-server-sdk/ldai/datamodel"

"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
"github.com/launchdarkly/go-sdk-common/v3/ldlogtest"
"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
Expand Down Expand Up @@ -116,8 +117,8 @@ func TestTracker_TrackRequestReceivesConfig(t *testing.T) {

expectedConfig := NewConfig().
WithMessage("hello", datamodel.Assistant).
WithModelId("model").
WithProviderId("provider").
WithModelName("model").
WithProviderName("provider").
WithModelParam("param", ldvalue.String("value")).
WithCustomModelParam("custom", ldvalue.String("value")).
Enable().
Expand Down

0 comments on commit ebdc281

Please sign in to comment.