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

refactor!: Rename model and provider id to name #218

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 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.
cwaldren-ld marked this conversation as resolved.
Show resolved Hide resolved
keelerm84 marked this conversation as resolved.
Show resolved Hide resolved
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 {
cwaldren-ld marked this conversation as resolved.
Show resolved Hide resolved
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
Loading