diff --git a/pkgs/sdk/server-ai/src/Interfaces/ILdAiClient.cs b/pkgs/sdk/server-ai/src/Interfaces/ILdAiClient.cs
index 2e5c32bd..28fd3dfb 100644
--- a/pkgs/sdk/server-ai/src/Interfaces/ILdAiClient.cs
+++ b/pkgs/sdk/server-ai/src/Interfaces/ILdAiClient.cs
@@ -22,10 +22,11 @@ public interface ILdAiClient
///
/// the AI Completion Config key
/// the context
- /// the default config, if unable to retrieve from LaunchDarkly
+ /// the default config, if unable to retrieve from LaunchDarkly. When not provided,
+ /// a disabled config is used as the fallback.
/// the list of variables used when interpolating the prompt
/// an AI Completion Config tracker
- public ILdAiConfigTracker CompletionConfig(string key, Context context, LdAiConfig defaultValue,
+ public ILdAiConfigTracker CompletionConfig(string key, Context context, LdAiConfig defaultValue = null,
IReadOnlyDictionary variables = null);
///
@@ -37,6 +38,6 @@ public ILdAiConfigTracker CompletionConfig(string key, Context context, LdAiConf
/// the list of variables used when interpolating the prompt
/// an AI Completion Config tracker
[Obsolete("Use CompletionConfig instead.")]
- public ILdAiConfigTracker Config(string key, Context context, LdAiConfig defaultValue,
+ public ILdAiConfigTracker Config(string key, Context context, LdAiConfig defaultValue = null,
IReadOnlyDictionary variables = null);
}
diff --git a/pkgs/sdk/server-ai/src/LdAiClient.cs b/pkgs/sdk/server-ai/src/LdAiClient.cs
index 9690ad49..803b3d5a 100644
--- a/pkgs/sdk/server-ai/src/LdAiClient.cs
+++ b/pkgs/sdk/server-ai/src/LdAiClient.cs
@@ -58,10 +58,11 @@ public LdAiClient(ILaunchDarklyClient client)
private const string LdContextVariable = "ldctx";
///
- public ILdAiConfigTracker CompletionConfig(string key, Context context, LdAiConfig defaultValue,
+ public ILdAiConfigTracker CompletionConfig(string key, Context context, LdAiConfig defaultValue = null,
IReadOnlyDictionary variables = null)
{
_client.Track(TrackUsageCompletionConfig, context, LdValue.Of(key), 1);
+ defaultValue ??= LdAiConfig.Disabled;
return Evaluate(key, context, defaultValue, variables);
}
@@ -129,7 +130,7 @@ private ILdAiConfigTracker Evaluate(string key, Context context, LdAiConfig defa
/// the list of variables used when interpolating the prompt
/// an AI Completion Config tracker
[Obsolete("Use CompletionConfig instead.")]
- public ILdAiConfigTracker Config(string key, Context context, LdAiConfig defaultValue,
+ public ILdAiConfigTracker Config(string key, Context context, LdAiConfig defaultValue = null,
IReadOnlyDictionary variables = null)
{
return CompletionConfig(key, context, defaultValue, variables);
diff --git a/pkgs/sdk/server-ai/test/LdAiClientTest.cs b/pkgs/sdk/server-ai/test/LdAiClientTest.cs
index 4d8b2639..f28e9c9d 100644
--- a/pkgs/sdk/server-ai/test/LdAiClientTest.cs
+++ b/pkgs/sdk/server-ai/test/LdAiClientTest.cs
@@ -324,4 +324,35 @@ public void ProviderConfigIsParsed()
Assert.Equal("amazing-provider", tracker.Config.Provider.Name);
}
+
+ [Fact]
+ public void ConfigWithoutDefaultValueUsesDisabledConfig()
+ {
+ var mockClient = new Mock();
+ var mockLogger = new Mock();
+
+ mockClient.Setup(x =>
+ x.JsonVariation("foo", It.IsAny(), It.IsAny())).Returns(LdValue.Null);
+ mockClient.Setup(x => x.GetLogger()).Returns(mockLogger.Object);
+
+ var client = new LdAiClient(mockClient.Object);
+ var tracker = client.Config("foo", Context.New(ContextKind.Default, "key"));
+
+ Assert.False(tracker.Config.Enabled);
+ }
+
+ [Fact]
+ public void DisabledMethodReturnsDisabledConfig()
+ {
+ var config = LdAiConfig.Disabled;
+ Assert.False(config.Enabled);
+ }
+
+ [Fact]
+ public void DisabledMethodReturnsNewInstanceEachCall()
+ {
+ var first = LdAiConfig.Disabled;
+ var second = LdAiConfig.Disabled;
+ Assert.NotSame(first, second);
+ }
}