Class LdAiConfigTracker
A tracker capable of reporting events related to a particular AI configuration.
Implements
Inherited Members
Namespace: LaunchDarkly.Sdk.Server.Ai
Assembly: LaunchDarkly.ServerSdk.Ai.dll
Syntax
public class LdAiConfigTracker : ILdAiConfigTracker
Constructors
| Edit this page View SourceLdAiConfigTracker(ILaunchDarklyClient, string, LdAiConfig, Context)
Constructs a new AI configuration tracker. The tracker is associated with a configuration, a context, and a key which identifies the configuration.
Declaration
public LdAiConfigTracker(ILaunchDarklyClient client, string configKey, LdAiConfig config, Context context)
Parameters
Type | Name | Description |
---|---|---|
ILaunchDarklyClient | client | the LaunchDarkly client |
string | configKey | key of the AI config |
LdAiConfig | config | the AI config |
Context | context | the context |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
Properties
| Edit this page View SourceConfig
The AI model configuration retrieved from LaunchDarkly, or a default value if unable to retrieve.
Declaration
public LdAiConfig Config { get; }
Property Value
Type | Description |
---|---|
LdAiConfig |
Methods
| Edit this page View SourceTrackDuration(float)
Tracks a duration metric related to this config. For example, if a particular operation related to usage of the AI model takes 100ms, this can be tracked and made available in LaunchDarkly.
Declaration
public void TrackDuration(float durationMs)
Parameters
Type | Name | Description |
---|---|---|
float | durationMs | the duration in milliseconds |
TrackDurationOfTask<T>(Task<T>)
Tracks the duration of a task, and returns the result of the task.
Declaration
public Task<T> TrackDurationOfTask<T>(Task<T> task)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | the task |
Returns
Type | Description |
---|---|
Task<T> | the task |
Type Parameters
Name | Description |
---|---|
T | type of the task's result |
TrackFeedback(Feedback)
Tracks feedback (positive or negative) related to the output of the model.
Declaration
public void TrackFeedback(Feedback feedback)
Parameters
Type | Name | Description |
---|---|---|
Feedback | feedback | the feedback |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
TrackRequest(Task<Response>)
Tracks a request to a provider. The request is a task that returns a Response, which contains information about the request such as token usage and metrics.
It is the responsibility of the caller to fill in the Response object with any details that should be tracked.
Example:
var response = tracker.TrackRequest(Task.Run(() => new Response {
// 1. Make a request to the AI provider
// 2. Identify relevant statistics returned in the response
// 3. Return a Response object containing the relevant statistics
Usage = new Usage { Total = 1, Input = 1, Output = 1 },
Metrics = new Metrics { LatencyMs = 100 }
}));
If no latency statistic is explicitly returned in the Response, then the duration of the Task is automatically measured and recorded as the latency metric associated with this request.
Declaration
public Task<Response> TrackRequest(Task<Response> request)
Parameters
Type | Name | Description |
---|---|---|
Task<Response> | request | a task representing the request |
Returns
Type | Description |
---|---|
Task<Response> | the task |
TrackSuccess()
Tracks a generation event related to this config.
Declaration
public void TrackSuccess()
TrackTokens(Usage)
Tracks token usage related to this config.
Declaration
public void TrackTokens(Usage usage)
Parameters
Type | Name | Description |
---|---|---|
Usage | usage | the token usage |