From ebdc281c667446e04b37ef44ee5e3f953d288eb2 Mon Sep 17 00:00:00 2001 From: "Matthew M. Keeler" Date: Mon, 9 Dec 2024 15:33:24 -0500 Subject: [PATCH] refactor!: Rename model and provider id to name (#218) Co-authored-by: Casey Waldren --- ldai/client.go | 4 ++-- ldai/client_test.go | 8 ++++---- ldai/config.go | 32 ++++++++++++++++---------------- ldai/datamodel/datamodel.go | 8 ++++---- ldai/tracker_test.go | 7 ++++--- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/ldai/client.go b/ldai/client.go index d771c3a7..5650fd67 100644 --- a/ldai/client.go +++ b/ldai/client.go @@ -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 { diff --git a/ldai/client_test.go b/ldai/client_test.go index 391e68d8..9745aa27 100644 --- a/ldai/client_test.go +++ b/ldai/client_test.go @@ -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() diff --git a/ldai/config.go b/ldai/config.go index 97a9c83b..81d01555 100644 --- a/ldai/config.go +++ b/ldai/config.go @@ -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. @@ -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 } @@ -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 } @@ -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, }, }, } diff --git a/ldai/datamodel/datamodel.go b/ldai/datamodel/datamodel.go index d4dcd063..9c881877 100644 --- a/ldai/datamodel/datamodel.go +++ b/ldai/datamodel/datamodel.go @@ -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"` @@ -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. diff --git a/ldai/tracker_test.go b/ldai/tracker_test.go index 98a89f12..d9d87db8 100644 --- a/ldai/tracker_test.go +++ b/ldai/tracker_test.go @@ -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" @@ -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().