diff --git a/pkgs/sdk/server-ai/src/Config/LdAiConfig.cs b/pkgs/sdk/server-ai/src/Config/LdAiConfig.cs
index 321dae7b..eb97273d 100644
--- a/pkgs/sdk/server-ai/src/Config/LdAiConfig.cs
+++ b/pkgs/sdk/server-ai/src/Config/LdAiConfig.cs
@@ -32,6 +32,51 @@ internal Message(string content, Role role)
}
}
+
+ ///
+ /// Information about the model provider.
+ ///
+ public record ModelProvider
+ {
+ ///
+ /// The ID of the model provider.
+ ///
+ public readonly string Id;
+
+ internal ModelProvider(string id)
+ {
+ Id = id;
+ }
+ }
+
+ ///
+ /// Information about the model.
+ ///
+ public record ModelConfiguration
+ {
+ ///
+ /// The ID of the model.
+ ///
+ public readonly string Id;
+
+ ///
+ /// The model's built-in parameters provided by LaunchDarkly.
+ ///
+ public readonly IReadOnlyDictionary Parameters;
+
+ ///
+ /// The model's custom parameters provided by the user.
+ ///
+ public readonly IReadOnlyDictionary Custom;
+
+ internal ModelConfiguration(string id, IReadOnlyDictionary parameters, IReadOnlyDictionary custom)
+ {
+ Id = id;
+ Parameters = parameters;
+ Custom = custom;
+ }
+ }
+
///
/// Builder for constructing an LdAiConfig instance, which can be passed as the default
/// value to the AI Client's method.
@@ -39,25 +84,29 @@ internal Message(string content, Role role)
public class Builder
{
private bool _enabled;
- private readonly List _prompt;
- private readonly Dictionary _modelParams;
+ private readonly List _messages;
+ private readonly Dictionary _modelParams;
+ private readonly Dictionary _customModelParams;
+ private string _providerId;
internal Builder()
{
_enabled = false;
- _prompt = new List();
- _modelParams = new Dictionary();
+ _messages = new List();
+ _modelParams = new Dictionary();
+ _customModelParams = new Dictionary();
+ _providerId = "";
}
///
- /// Adds a prompt message with the given content and role. The default role is .
+ /// Adds a message with the given content and role. The default role is .
///
/// the content, which may contain Mustache templates
/// the role
/// a new builder
- public Builder AddPromptMessage(string content, Role role = Role.User)
+ public Builder AddMessage(string content, Role role = Role.User)
{
- _prompt.Add(new Message(content, role));
+ _messages.Add(new Message(content, role));
return this;
}
@@ -85,66 +134,74 @@ public Builder SetEnabled(bool enabled)
}
///
- /// Sets a parameter for the model. The value may be any object.
+ /// Sets a parameter for the model.
///
/// the parameter name
/// the parameter value
/// the builder
- public Builder SetModelParam(string name, object value)
+ public Builder SetModelParam(string name, LdValue value)
{
_modelParams[name] = value;
return this;
}
+ ///
+ /// Sets a custom parameter for the model.
+ ///
+ /// the custom parameter name
+ /// the custom parameter value
+ /// the builder
+ public Builder SetCustomModelParam(string name, LdValue value)
+ {
+ _customModelParams[name] = value;
+ return this;
+ }
+
+ ///
+ /// Sets the model provider's ID. By default, this will be the empty string.
+ ///
+ /// the ID
+ ///
+ public Builder SetModelProviderId(string id)
+ {
+ _providerId = id;
+ return this;
+ }
+
///
/// Builds the LdAiConfig instance.
///
/// a new LdAiConfig
public LdAiConfig Build()
{
- return new LdAiConfig(_enabled, _prompt, new Meta(), _modelParams);
+ return new LdAiConfig(_enabled, _messages, new Meta(), new Model {Parameters = _modelParams, Custom = _customModelParams}, new Provider{ Id = _providerId });
}
}
///
/// The prompts associated with the config.
///
- public readonly IReadOnlyList Prompt;
+ public readonly IReadOnlyList Messages;
///
/// The model parameters associated with the config.
///
- public readonly IReadOnlyDictionary Model;
-
+ public readonly ModelConfiguration Model;
+ ///
+ /// Information about the model provider.
+ ///
+ public readonly ModelProvider Provider;
- internal LdAiConfig(bool enabled, IEnumerable prompt, Meta meta, IReadOnlyDictionary model)
+ internal LdAiConfig(bool enabled, IEnumerable messages, Meta meta, Model model, Provider provider)
{
- Model = model ?? new Dictionary();
- Prompt = prompt?.ToList() ?? new List();
+ Model = new ModelConfiguration(model?.Id ?? "", model?.Parameters ?? new Dictionary(),
+ model?.Custom ?? new Dictionary());
+ Messages = messages?.ToList() ?? new List();
VersionKey = meta?.VersionKey ?? "";
Enabled = enabled;
+ Provider = new ModelProvider(provider?.Id ?? "");
}
-
- private static LdValue ObjectToValue(object obj)
- {
- if (obj == null)
- {
- return LdValue.Null;
- }
-
- return obj switch
- {
- bool b => LdValue.Of(b),
- double d => LdValue.Of(d),
- string s => LdValue.Of(s),
- IEnumerable