Skip to content

Commit 38ab2db

Browse files
[AIC-1636] refactor: Split CompletionConfig into public entry + private Evaluate to track usage only once
Co-Authored-By: unknown <>
1 parent 66fdd10 commit 38ab2db

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkgs/sdk/server-ai/src/LdAiClient.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,17 @@ public ILdAiConfigTracker CompletionConfig(string key, Context context, LdAiConf
6363
{
6464
_client.Track(TrackUsageCompletionConfig, context, LdValue.Of(key), 1);
6565

66+
return Evaluate(key, context, defaultValue, variables);
67+
}
6668

69+
/// <summary>
70+
/// Internal evaluation method that retrieves and parses an AI Config without tracking usage.
71+
/// This allows higher-level SDK entry methods to track their own usage events without
72+
/// double-counting.
73+
/// </summary>
74+
private ILdAiConfigTracker Evaluate(string key, Context context, LdAiConfig defaultValue,
75+
IReadOnlyDictionary<string, object> variables = null)
76+
{
6777
var result = _client.JsonVariation(key, context, defaultValue.ToLdValue());
6878

6979
var parsed = ParseConfig(result, key);
@@ -87,7 +97,6 @@ public ILdAiConfigTracker CompletionConfig(string key, Context context, LdAiConf
8797
}
8898
}
8999

90-
91100
var prompt = new List<LdAiConfig.Message>();
92101

93102
if (parsed.Messages != null)
@@ -109,7 +118,6 @@ public ILdAiConfigTracker CompletionConfig(string key, Context context, LdAiConf
109118
}
110119

111120
return new LdAiConfigTracker(_client, key, new LdAiConfig(parsed.Meta?.Enabled ?? false, prompt, parsed.Meta, parsed.Model, parsed.Provider), context);
112-
113121
}
114122

115123
/// <summary>

0 commit comments

Comments
 (0)