Skip to content

Commit

Permalink
refactor!: rename _ldMeta.versionKey to variationKey (#62)
Browse files Browse the repository at this point in the history
This renames `_ldMeta.versionKey` field to `variationKey` following the
latest spec changes.
  • Loading branch information
cwaldren-ld authored Dec 10, 2024
1 parent 562a2c6 commit 3f7089d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions pkgs/sdk/server-ai/src/Config/LdAiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ internal LdAiConfig(bool enabled, IEnumerable<Message> messages, Meta meta, Mode
Model = new ModelConfiguration(model?.Id ?? "", model?.Parameters ?? new Dictionary<string, LdValue>(),
model?.Custom ?? new Dictionary<string, LdValue>());
Messages = messages?.ToList() ?? new List<Message>();
VersionKey = meta?.VersionKey ?? "";
VariationKey = meta?.VariationKey ?? "";
Enabled = enabled;
Provider = new ModelProvider(provider?.Id ?? "");
}
Expand All @@ -233,7 +233,7 @@ internal LdValue ToLdValue()
{ "_ldMeta", LdValue.ObjectFrom(
new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(VersionKey) },
{ "variationKey", LdValue.Of(VariationKey) },
{ "enabled", LdValue.Of(Enabled) }
}) },
{ "messages", LdValue.ArrayFrom(Messages.Select(m => LdValue.ObjectFrom(new Dictionary<string, LdValue>
Expand Down Expand Up @@ -269,7 +269,7 @@ internal LdValue ToLdValue()
/// <summary>
/// This field meant for internal LaunchDarkly usage.
/// </summary>
public string VersionKey { get; }
public string VariationKey { get; }

/// <summary>
/// Convenient helper that returns a disabled LdAiConfig.
Expand Down
6 changes: 3 additions & 3 deletions pkgs/sdk/server-ai/src/DataModel/DataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public enum Role
public class Meta
{
/// <summary>
/// The version key.
/// The variation key.
/// </summary>
[JsonPropertyName("versionKey")]
public string VersionKey { get; set; }
[JsonPropertyName("variationKey")]
public string VariationKey { get; set; }

/// <summary>
/// If the config is enabled.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/sdk/server-ai/src/LdAiConfigTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public LdAiConfigTracker(ILaunchDarklyClient client, string configKey, LdAiConfi
_context = context;
_trackData = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(Config.VersionKey)},
{ "variationKey", LdValue.Of(config.VariationKey)},
{ "configKey" , LdValue.Of(configKey ?? throw new ArgumentNullException(nameof(configKey))) }
});
}
Expand Down
4 changes: 2 additions & 2 deletions pkgs/sdk/server-ai/test/InterpolationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private string Eval(string prompt, Context context, IReadOnlyDictionary<string,
// The replacement is done this way because to use string.Format, we'd need to escape the curly braces.
var configJson = """
{
"_ldMeta": {"versionKey": "1", "enabled": true},
"_ldMeta": {"variationKey": "1", "enabled": true},
"model": {},
"messages": [
{
Expand Down Expand Up @@ -126,7 +126,7 @@ public void TestInterpolationMalformed()

const string configJson = """
{
"_ldMeta": {"versionKey": "1", "enabled": true},
"_ldMeta": {"variationKey": "1", "enabled": true},
"model": {},
"messages": [
{
Expand Down
10 changes: 5 additions & 5 deletions pkgs/sdk/server-ai/test/LdAiClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public void ReturnsDefaultConfigWhenGivenInvalidVariation()

private const string MetaDisabledExplicitly = """
{
"_ldMeta": {"versionKey": "1", "enabled": false},
"_ldMeta": {"variationKey": "1", "enabled": false},
"model": {},
"messages": []
}
""";

private const string MetaDisabledImplicitly = """
{
"_ldMeta": {"versionKey": "1"},
"_ldMeta": {"variationKey": "1"},
"model": {},
"messages": []
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public void ConfigEnabledReturnsInstance()

const string json = """
{
"_ldMeta": {"versionKey": "1", "enabled": true},
"_ldMeta": {"variationKey": "1", "enabled": true},
"messages": [{"content": "Hello!", "role": "system"}]
}
""";
Expand Down Expand Up @@ -187,7 +187,7 @@ public void ModelParametersAreParsed()

const string json = """
{
"_ldMeta": {"versionKey": "1", "enabled": true},
"_ldMeta": {"variationKey": "1", "enabled": true},
"model" : {
"id": "model-foo",
"parameters": {
Expand Down Expand Up @@ -232,7 +232,7 @@ public void ProviderConfigIsParsed()

const string json = """
{
"_ldMeta": {"versionKey": "1", "enabled": true},
"_ldMeta": {"variationKey": "1", "enabled": true},
"provider": {
"id": "amazing-provider"
}
Expand Down
14 changes: 7 additions & 7 deletions pkgs/sdk/server-ai/test/LdAiConfigTrackerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void CanTrackDuration()
var config = LdAiConfig.Disabled;
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(config.VersionKey) },
{ "variationKey", LdValue.Of(config.VariationKey) },
{ "configKey", LdValue.Of(flagKey) }
});
var tracker = new LdAiConfigTracker(mockClient.Object, flagKey, config, context);
Expand All @@ -61,7 +61,7 @@ public void CanTrackSuccess()
var config = LdAiConfig.Disabled;
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(config.VersionKey) },
{ "variationKey", LdValue.Of(config.VariationKey) },
{ "configKey", LdValue.Of(flagKey) }
});

Expand All @@ -80,7 +80,7 @@ public async void CanTrackDurationOfTask()
var config = LdAiConfig.Disabled;
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(config.VersionKey) },
{ "variationKey", LdValue.Of(config.VariationKey) },
{ "configKey", LdValue.Of(flagKey) }
});

Expand Down Expand Up @@ -114,7 +114,7 @@ public void CanTrackFeedback()
var config = LdAiConfig.Disabled;
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(config.VersionKey) },
{ "variationKey", LdValue.Of(config.VariationKey) },
{ "configKey", LdValue.Of(flagKey) }
});

Expand All @@ -135,7 +135,7 @@ public void CanTrackTokens()
var config = LdAiConfig.Disabled;
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(config.VersionKey) },
{ "variationKey", LdValue.Of(config.VariationKey) },
{ "configKey", LdValue.Of(flagKey) }
});

Expand Down Expand Up @@ -163,7 +163,7 @@ public void CanTrackResponseWithSpecificLatency()
var config = LdAiConfig.Disabled;
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(config.VersionKey) },
{ "variationKey", LdValue.Of(config.VariationKey) },
{ "configKey", LdValue.Of(flagKey) }
});

Expand Down Expand Up @@ -204,7 +204,7 @@ public void CanTrackResponseWithPartialData()
var config = LdAiConfig.Disabled;
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "versionKey", LdValue.Of(config.VersionKey) },
{ "variationKey", LdValue.Of(config.VariationKey) },
{ "configKey", LdValue.Of(flagKey) }
});

Expand Down

0 comments on commit 3f7089d

Please sign in to comment.