diff --git a/ldai/client.go b/ldai/client.go index 1d665c7d..b1e988b2 100644 --- a/ldai/client.go +++ b/ldai/client.go @@ -122,7 +122,7 @@ func (c *Client) Config( } cfg := builder.Build() - return cfg, newTracker(key, parsed.Meta.VersionKey, c.sdk, &cfg, context, c.logger) + return cfg, newTracker(key, parsed.Meta.VariationKey, c.sdk, &cfg, context, c.logger) } func getAllAttributes(context ldcontext.Context) map[string]interface{} { diff --git a/ldai/client_test.go b/ldai/client_test.go index 873bc2c6..88d818d5 100644 --- a/ldai/client_test.go +++ b/ldai/client_test.go @@ -71,7 +71,7 @@ func TestEvalErrorReturnsDefault(t *testing.T) { func TestParseMultipleMessages(t *testing.T) { json := []byte(`{ - "_ldMeta": {"versionKey": "1", "enabled": true}, + "_ldMeta": {"variationKey": "1", "enabled": true}, "messages": [ {"content": "hello", "role": "user"}, {"content": "world", "role": "system"} @@ -175,8 +175,8 @@ func TestParseDisabledConfigs(t *testing.T) { }{ {"empty object", []byte("{}")}, {"missing meta field", []byte(`{"model": {}, "messages": []}`)}, - {"meta disabled explicitly", []byte(`{"meta": {"enabled": false, "versionKey": "1"}, "model": {}, "messages": []}`)}, - {"meta disable implicitly", []byte(`{"meta": { "versionKey": "1"}, "model": {}, "messages": []}`)}, + {"meta disabled explicitly", []byte(`{"meta": {"enabled": false, "variationKey": "1"}, "model": {}, "messages": []}`)}, + {"meta disable implicitly", []byte(`{"meta": { "variationKey": "1"}, "model": {}, "messages": []}`)}, } defaultVal := NewConfig().Enable().WithMessage("hello", datamodel.User).Build() @@ -368,7 +368,7 @@ func TestCannotOverwriteMessages(t *testing.T) { func eval(t *testing.T, prompt string, ctx ldcontext.Context, variables map[string]interface{}) (string, error) { t.Helper() json := []byte(`{ - "_ldMeta": {"versionKey": "1", "enabled": true}, + "_ldMeta": {"variationKey": "1", "enabled": true}, "messages": [ {"content": "` + prompt + `", "role": "user"} ] diff --git a/ldai/config.go b/ldai/config.go index 81d01555..64ee7e27 100644 --- a/ldai/config.go +++ b/ldai/config.go @@ -12,9 +12,9 @@ type Config struct { c datamodel.Config } -// VersionKey is used internally by LaunchDarkly. -func (c *Config) VersionKey() string { - return c.c.Meta.VersionKey +// VariationKey is used internally by LaunchDarkly. +func (c *Config) VariationKey() string { + return c.c.Meta.VariationKey } // Messages returns the messages defined by the config. The series of messages may be diff --git a/ldai/datamodel/datamodel.go b/ldai/datamodel/datamodel.go index 9c881877..5f25c326 100644 --- a/ldai/datamodel/datamodel.go +++ b/ldai/datamodel/datamodel.go @@ -4,8 +4,8 @@ import "github.com/launchdarkly/go-sdk-common/v3/ldvalue" // Meta defines the serialization format for config metadata. type Meta struct { - // VersionKey is the version key. - VersionKey string `json:"versionKey,omitempty"` + // VariationKey is the variation key. + VariationKey string `json:"variationKey,omitempty"` // Enabled is true if the config is enabled. Enabled bool `json:"enabled,omitempty"` diff --git a/ldai/tracker.go b/ldai/tracker.go index 9f427f86..9a50c7a5 100644 --- a/ldai/tracker.go +++ b/ldai/tracker.go @@ -114,19 +114,19 @@ func (d *defaultStopwatch) Stop() time.Duration { } // newTracker creates a new Tracker with the specified key, event sink, config, context, and loggers. -func newTracker(key string, versionKey string, events EventSink, config *Config, ctx ldcontext.Context, loggers interfaces.LDLoggers) *Tracker { - return newTrackerWithStopwatch(key, versionKey, events, config, ctx, loggers, &defaultStopwatch{}) +func newTracker(key string, variationKey string, events EventSink, config *Config, ctx ldcontext.Context, loggers interfaces.LDLoggers) *Tracker { + return newTrackerWithStopwatch(key, variationKey, events, config, ctx, loggers, &defaultStopwatch{}) } // newTrackerWithStopwatch creates a new Tracker with the specified key, event sink, config, context, loggers, and // stopwatch. This method is used for testing purposes. -func newTrackerWithStopwatch(key string, versionKey string, events EventSink, config *Config, ctx ldcontext.Context, loggers interfaces.LDLoggers, stopwatch Stopwatch) *Tracker { +func newTrackerWithStopwatch(key string, variationKey string, events EventSink, config *Config, ctx ldcontext.Context, loggers interfaces.LDLoggers, stopwatch Stopwatch) *Tracker { if config == nil { panic("LaunchDarkly SDK programmer error: config must never be nil") } trackData := ldvalue.ObjectBuild(). - Set("versionKey", ldvalue.String(versionKey)). + Set("variationKey", ldvalue.String(variationKey)). Set("configKey", ldvalue.String(key)).Build() return &Tracker{ diff --git a/ldai/tracker_test.go b/ldai/tracker_test.go index d9d87db8..fcaba72f 100644 --- a/ldai/tracker_test.go +++ b/ldai/tracker_test.go @@ -36,32 +36,32 @@ func (m *mockEvents) TrackMetric(eventName string, context ldcontext.Context, me func TestTracker_NewPanicsWithNilConfig(t *testing.T) { assert.Panics(t, func() { - newTracker("key", "versionKey", newMockEvents(), nil, ldcontext.New("key"), nil) + newTracker("key", "variationKey", newMockEvents(), nil, ldcontext.New("key"), nil) }) } func TestTracker_NewDoesNotPanicWithConfig(t *testing.T) { assert.NotPanics(t, func() { - newTracker("key", "versionKey", newMockEvents(), &Config{}, ldcontext.New("key"), nil) + newTracker("key", "variationKey", newMockEvents(), &Config{}, ldcontext.New("key"), nil) }) } -func makeTrackData(configKey, versionKey string) ldvalue.Value { +func makeTrackData(configKey, variationKey string) ldvalue.Value { return ldvalue.ObjectBuild(). - Set("versionKey", ldvalue.String(versionKey)). + Set("variationKey", ldvalue.String(variationKey)). Set("configKey", ldvalue.String(configKey)).Build() } func TestTracker_TrackSuccess(t *testing.T) { events := newMockEvents() - tracker := newTracker("key", "versionKey", events, &Config{}, ldcontext.New("key"), nil) + tracker := newTracker("key", "variationKey", events, &Config{}, ldcontext.New("key"), nil) assert.NoError(t, tracker.TrackSuccess()) expectedEvent := trackEvent{ name: "$ld:ai:generation", context: ldcontext.New("key"), metricValue: 1.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } assert.ElementsMatch(t, []trackEvent{expectedEvent}, events.events) @@ -69,7 +69,7 @@ func TestTracker_TrackSuccess(t *testing.T) { func TestTracker_TrackRequest(t *testing.T) { events := newMockEvents() - tracker := newTracker("key", "versionKey", events, &Config{}, ldcontext.New("key"), nil) + tracker := newTracker("key", "variationKey", events, &Config{}, ldcontext.New("key"), nil) expectedResponse := ProviderResponse{ Usage: TokenUsage{ @@ -91,21 +91,21 @@ func TestTracker_TrackRequest(t *testing.T) { name: "$ld:ai:generation", context: ldcontext.New("key"), metricValue: 1, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } expectedDurationEvent := trackEvent{ name: "$ld:ai:duration:total", context: ldcontext.New("key"), metricValue: 10.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } expectedTokenUsageEvent := trackEvent{ name: "$ld:ai:tokens:total", context: ldcontext.New("key"), metricValue: 1, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } expectedEvents := []trackEvent{expectedSuccessEvent, expectedDurationEvent, expectedTokenUsageEvent} @@ -124,7 +124,7 @@ func TestTracker_TrackRequestReceivesConfig(t *testing.T) { Enable(). Build() - tracker := newTracker("key", "versionKey", events, &expectedConfig, ldcontext.New("key"), nil) + tracker := newTracker("key", "variationKey", events, &expectedConfig, ldcontext.New("key"), nil) var gotConfig *Config _, _ = tracker.TrackRequest(func(c *Config) (ProviderResponse, error) { @@ -147,7 +147,7 @@ func TestTracker_LatencyMeasuredIfNotProvided(t *testing.T) { events := newMockEvents() tracker := newTrackerWithStopwatch( - "key", "versionKey", events, &Config{}, ldcontext.New("key"), nil, mockStopwatch(42*time.Millisecond)) + "key", "variationKey", events, &Config{}, ldcontext.New("key"), nil, mockStopwatch(42*time.Millisecond)) expectedResponse := ProviderResponse{ Usage: TokenUsage{ @@ -170,7 +170,7 @@ func TestTracker_LatencyMeasuredIfNotProvided(t *testing.T) { func TestTracker_TrackDuration(t *testing.T) { events := newMockEvents() - tracker := newTracker("key", "versionKey", events, &Config{}, ldcontext.New("key"), nil) + tracker := newTracker("key", "variationKey", events, &Config{}, ldcontext.New("key"), nil) assert.NoError(t, tracker.TrackDuration(time.Millisecond*10)) @@ -178,7 +178,7 @@ func TestTracker_TrackDuration(t *testing.T) { name: "$ld:ai:duration:total", context: ldcontext.New("key"), metricValue: 10.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } assert.ElementsMatch(t, []trackEvent{expectedEvent}, events.events) @@ -186,7 +186,7 @@ func TestTracker_TrackDuration(t *testing.T) { func TestTracker_TrackFeedback(t *testing.T) { events := newMockEvents() - tracker := newTracker("key", "versionKey", events, &Config{}, ldcontext.New("key"), nil) + tracker := newTracker("key", "variationKey", events, &Config{}, ldcontext.New("key"), nil) assert.NoError(t, tracker.TrackFeedback(FeedbackPositive)) assert.NoError(t, tracker.TrackFeedback(FeedbackNegative)) @@ -196,14 +196,14 @@ func TestTracker_TrackFeedback(t *testing.T) { name: "$ld:ai:feedback:user:positive", context: ldcontext.New("key"), metricValue: 1.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } expectedNegativeEvent := trackEvent{ name: "$ld:ai:feedback:user:negative", context: ldcontext.New("key"), metricValue: 1.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } assert.ElementsMatch(t, []trackEvent{expectedPositiveEvent, expectedNegativeEvent}, events.events) @@ -212,7 +212,7 @@ func TestTracker_TrackFeedback(t *testing.T) { func TestTracker_TrackUsage(t *testing.T) { t.Run("only one field set, only one event", func(t *testing.T) { events := newMockEvents() - tracker := newTracker("key", "versionKey", events, &Config{}, ldcontext.New("key"), nil) + tracker := newTracker("key", "variationKey", events, &Config{}, ldcontext.New("key"), nil) assert.NoError(t, tracker.TrackUsage(TokenUsage{ Total: 42, @@ -222,7 +222,7 @@ func TestTracker_TrackUsage(t *testing.T) { name: "$ld:ai:tokens:total", context: ldcontext.New("key"), metricValue: 42.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } assert.ElementsMatch(t, []trackEvent{expectedEvent}, events.events) @@ -230,7 +230,7 @@ func TestTracker_TrackUsage(t *testing.T) { t.Run("all fields set, all events", func(t *testing.T) { events := newMockEvents() - tracker := newTracker("key", "versionKey", events, &Config{}, ldcontext.New("key"), nil) + tracker := newTracker("key", "variationKey", events, &Config{}, ldcontext.New("key"), nil) assert.NoError(t, tracker.TrackUsage(TokenUsage{ Total: 42, @@ -242,21 +242,21 @@ func TestTracker_TrackUsage(t *testing.T) { name: "$ld:ai:tokens:total", context: ldcontext.New("key"), metricValue: 42.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } expectedInput := trackEvent{ name: "$ld:ai:tokens:input", context: ldcontext.New("key"), metricValue: 20.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } expectedOutput := trackEvent{ name: "$ld:ai:tokens:output", context: ldcontext.New("key"), metricValue: 22.0, - data: makeTrackData("key", "versionKey"), + data: makeTrackData("key", "variationKey"), } assert.ElementsMatch(t, []trackEvent{expectedTotal, expectedInput, expectedOutput}, events.events)