Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions pkgs/sdk/server-ai/src/Config/LdAiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class Builder
private readonly Dictionary<string, LdValue> _modelParams;
private readonly Dictionary<string, LdValue> _customModelParams;
private string _providerId;
private string _modelId;

internal Builder()
{
Expand All @@ -96,6 +97,7 @@ internal Builder()
_modelParams = new Dictionary<string, LdValue>();
_customModelParams = new Dictionary<string, LdValue>();
_providerId = "";
_modelId = "";
}

/// <summary>
Expand Down Expand Up @@ -157,11 +159,22 @@ public Builder SetCustomModelParam(string name, LdValue value)
return this;
}

/// <summary>
/// Sets the model's ID. By default, this will be the empty string.
/// </summary>
/// <param name="id">the model ID</param>
/// <returns>the builder</returns>
public Builder SetModelId(string id)
{
_modelId = id;
return this;
}

/// <summary>
/// Sets the model provider's ID. By default, this will be the empty string.
/// </summary>
/// <param name="id">the ID</param>
/// <returns></returns>
/// <returns>the builder</returns>
public Builder SetModelProviderId(string id)
{
_providerId = id;
Expand All @@ -174,7 +187,18 @@ public Builder SetModelProviderId(string id)
/// <returns>a new LdAiConfig</returns>
public LdAiConfig Build()
{
return new LdAiConfig(_enabled, _messages, new Meta(), new Model {Parameters = _modelParams, Custom = _customModelParams}, new Provider{ Id = _providerId });
return new LdAiConfig(
_enabled,
_messages,
new Meta(),
new Model
{
Id = _modelId,
Parameters = _modelParams,
Custom = _customModelParams
},
new Provider{ Id = _providerId }
);
}
}

Expand Down Expand Up @@ -219,6 +243,7 @@ internal LdValue ToLdValue()
}))) },
{ "model", LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "id", LdValue.Of(Model.Id) },
{ "parameters", LdValue.ObjectFrom(Model.Parameters) },
{ "custom", LdValue.ObjectFrom(Model.Custom) }
}) },
Expand Down
2 changes: 2 additions & 0 deletions pkgs/sdk/server-ai/test/LdAiClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void CanSetAllDefaultValueFields()
LdAiConfig.New().
AddMessage("foo").
SetModelParam("foo", LdValue.Of("bar")).
SetModelId("awesome-model").
SetCustomModelParam("foo", LdValue.Of("baz")).
SetModelProviderId("amazing-provider").
SetEnabled(true).Build());
Expand All @@ -133,6 +134,7 @@ public void CanSetAllDefaultValueFields()
Assert.Equal("amazing-provider", tracker.Config.Provider.Id);
Assert.Equal("bar", tracker.Config.Model.Parameters["foo"].AsString);
Assert.Equal("baz", tracker.Config.Model.Custom["foo"].AsString);
Assert.Equal("awesome-model", tracker.Config.Model.Id);
}

[Fact]
Expand Down
7 changes: 7 additions & 0 deletions pkgs/sdk/server-ai/test/LdAiConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public void CanSetModelParams()
Assert.Equal(LdValue.Of(43), config.Model.Custom["baz"]);
}

[Fact]
public void CanSetModelId()
{
var config = LdAiConfig.New().SetModelId("awesome-model").Build();
Assert.Equal("awesome-model", config.Model.Id);
}

[Fact]
public void CanSetModelProviderId()
{
Expand Down
Loading