Skip to content

Commit f240f25

Browse files
fix: include judgeConfiguration in CompletionConfigDefault.ToLdValue()
LdAiCompletionConfigDefault.ToLdValue() was not serializing the judgeConfiguration property, unlike LdAiAgentConfigDefault which did. This meant the judge config was lost when the default round-tripped through JsonVariation as an LdValue fallback. Adds conditional serialization matching the agent default pattern and a test that verifies the round-trip. Co-Authored-By: mmccarthy@launchdarkly.com <mmccarthy@launchdarkly.com>
1 parent f328252 commit f240f25

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

pkgs/sdk/server-ai/src/Config/LdAiCompletionConfigDefault.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ internal LdValue ToLdValue()
173173
["mode"] = LdValue.Of(LdAiCompletionConfig.Mode)
174174
};
175175

176-
return LdValue.ObjectFrom(new Dictionary<string, LdValue>
176+
var root = new Dictionary<string, LdValue>
177177
{
178178
{ "_ldMeta", LdValue.ObjectFrom(metaFields) },
179179
{ "messages", LdValue.ArrayFrom(Messages.Select(m => LdValue.ObjectFrom(new Dictionary<string, LdValue>
@@ -191,7 +191,23 @@ internal LdValue ToLdValue()
191191
{
192192
{ "name", LdValue.Of(Provider.Name) }
193193
}) }
194-
});
194+
};
195+
196+
if (JudgeConfiguration != null)
197+
{
198+
root["judgeConfiguration"] = LdValue.ObjectFrom(new Dictionary<string, LdValue>
199+
{
200+
{ "judges", LdValue.ArrayFrom(JudgeConfiguration.Judges.Select(j =>
201+
LdValue.ObjectFrom(new Dictionary<string, LdValue>
202+
{
203+
{ "key", LdValue.Of(j.Key) },
204+
{ "samplingRate", LdValue.Of(j.SamplingRate) }
205+
})))
206+
}
207+
});
208+
}
209+
210+
return LdValue.ObjectFrom(root);
195211
}
196212

197213
/// <summary>

pkgs/sdk/server-ai/test/LdAiClientTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,35 @@ public void CompletionConfigDefaultJudgeConfigurationSurvivesBuildFromDefault()
875875
Assert.Equal("coherence", result.JudgeConfiguration.Judges[0].Key);
876876
Assert.Equal(0.3, result.JudgeConfiguration.Judges[0].SamplingRate);
877877
}
878+
879+
[Fact]
880+
public void CompletionConfigDefaultToLdValueIncludesJudgeConfiguration()
881+
{
882+
var mockClient = new Mock<ILaunchDarklyClient>();
883+
var mockLogger = new Mock<ILogger>();
884+
885+
// Return the default LdValue directly so it round-trips through BuildCompletionConfig.
886+
mockClient.Setup(x =>
887+
x.JsonVariation("foo", It.IsAny<Context>(), It.IsAny<LdValue>()))
888+
.Returns((string _, Context _, LdValue dv) => dv);
889+
mockClient.Setup(x => x.GetLogger()).Returns(mockLogger.Object);
890+
891+
var judgeConfig = new LdAiConfigTypes.JudgeConfiguration(
892+
new List<LdAiConfigTypes.JudgeConfiguration.Judge>
893+
{
894+
new LdAiConfigTypes.JudgeConfiguration.Judge("accuracy", 0.9)
895+
});
896+
897+
var defaultConfig = LdAiCompletionConfigDefault.New()
898+
.SetJudgeConfiguration(judgeConfig)
899+
.Build();
900+
901+
var client = new LdAiClient(mockClient.Object);
902+
var result = client.CompletionConfig("foo", Context.New(ContextKind.Default, "key"), defaultConfig);
903+
904+
Assert.NotNull(result.JudgeConfiguration);
905+
Assert.Single(result.JudgeConfiguration.Judges);
906+
Assert.Equal("accuracy", result.JudgeConfiguration.Judges[0].Key);
907+
Assert.Equal(0.9, result.JudgeConfiguration.Judges[0].SamplingRate);
908+
}
878909
}

0 commit comments

Comments
 (0)