Skip to content

Commit

Permalink
add an ILdAiClient interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Nov 8, 2024
1 parent 6ec3f94 commit 8c18ca5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
29 changes: 29 additions & 0 deletions pkgs/sdk/server-ai/src/Interfaces/ILdAiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using LaunchDarkly.Sdk.Server.Ai.Config;

namespace LaunchDarkly.Sdk.Server.Ai.Interfaces;

/// <summary>
/// Represents the interface of the AI client, useful for mocking.
/// </summary>
public interface ILdAiClient
{

/// <summary>
/// Retrieves a LaunchDarkly AI config identified by the given key. The return value
/// is an <see cref="LdAiConfigTracker"/>, which makes the configuration available and
/// provides convenience methods for generating events related to model usage.
///
/// Any variables provided will be interpolated into the prompt's messages.
/// Additionally, the current LaunchDarkly context will be available as 'ldctx' within
/// a prompt message.
///
/// </summary>
/// <param name="key">the flag key</param>
/// <param name="context">the context</param>
/// <param name="defaultValue">the default config, if unable to retrieve from LaunchDarkly</param>
/// <param name="variables">the list of variables used when interpolating the prompt</param>
/// <returns>an AI config tracker</returns>
public LdAiConfigTracker ModelConfig(string key, Context context, LdAiConfig defaultValue,
IReadOnlyDictionary<string, object> variables = null);
}
20 changes: 2 additions & 18 deletions pkgs/sdk/server-ai/src/LdAiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
using System.Collections.Immutable;
using System.Linq;
using System.Text.Json;
using LaunchDarkly.Sdk.Server.Ai.Adapters;
using LaunchDarkly.Sdk.Server.Ai.Config;
using LaunchDarkly.Sdk.Server.Ai.DataModel;
using LaunchDarkly.Sdk.Server.Ai.Interfaces;
using LaunchDarkly.Sdk.Server.Interfaces;
using Mustache;

namespace LaunchDarkly.Sdk.Server.Ai;
Expand All @@ -16,7 +14,7 @@ namespace LaunchDarkly.Sdk.Server.Ai;
/// The LaunchDarkly AI client. The client is capable of retrieving AI configurations from LaunchDarkly,
/// and generating events specific to usage of the AI configuration when interacting with model providers.
/// </summary>
public sealed class LdAiClient
public sealed class LdAiClient : ILdAiClient
{
private readonly ILaunchDarklyClient _client;
private readonly ILogger _logger;
Expand Down Expand Up @@ -44,21 +42,7 @@ public LdAiClient(ILaunchDarklyClient client)
// LaunchDarkly context. For example, {{ ldctx.key }} will return the context key.
private const string LdContextVariable = "ldctx";

/// <summary>
/// Retrieves a LaunchDarkly AI config identified by the given key. The return value
/// is an <see cref="LdAiConfigTracker"/>, which makes the configuration available and
/// provides convenience methods for generating events related to model usage.
///
/// Any variables provided will be interpolated into the prompt's messages.
/// Additionally, the current LaunchDarkly context will be available as 'ldctx' within
/// a prompt message.
///
/// </summary>
/// <param name="key">the flag key</param>
/// <param name="context">the context</param>
/// <param name="defaultValue">the default config, if unable to retrieve from LaunchDarkly</param>
/// <param name="variables">the list of variables used when interpolating the prompt</param>
/// <returns>an AI config tracker</returns>
/// <inheritdoc/>
public LdAiConfigTracker ModelConfig(string key, Context context, LdAiConfig defaultValue,
IReadOnlyDictionary<string, object> variables = null)
{
Expand Down

0 comments on commit 8c18ca5

Please sign in to comment.