Skip to content

Commit bb6a1e9

Browse files
authored
fix: add setter for ModelId (#54)
1 parent 5e33b7d commit bb6a1e9

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

pkgs/sdk/server-ai/src/Config/LdAiConfig.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class Builder
8888
private readonly Dictionary<string, LdValue> _modelParams;
8989
private readonly Dictionary<string, LdValue> _customModelParams;
9090
private string _providerId;
91+
private string _modelId;
9192

9293
internal Builder()
9394
{
@@ -96,6 +97,7 @@ internal Builder()
9697
_modelParams = new Dictionary<string, LdValue>();
9798
_customModelParams = new Dictionary<string, LdValue>();
9899
_providerId = "";
100+
_modelId = "";
99101
}
100102

101103
/// <summary>
@@ -157,11 +159,22 @@ public Builder SetCustomModelParam(string name, LdValue value)
157159
return this;
158160
}
159161

162+
/// <summary>
163+
/// Sets the model's ID. By default, this will be the empty string.
164+
/// </summary>
165+
/// <param name="id">the model ID</param>
166+
/// <returns>the builder</returns>
167+
public Builder SetModelId(string id)
168+
{
169+
_modelId = id;
170+
return this;
171+
}
172+
160173
/// <summary>
161174
/// Sets the model provider's ID. By default, this will be the empty string.
162175
/// </summary>
163176
/// <param name="id">the ID</param>
164-
/// <returns></returns>
177+
/// <returns>the builder</returns>
165178
public Builder SetModelProviderId(string id)
166179
{
167180
_providerId = id;
@@ -174,7 +187,18 @@ public Builder SetModelProviderId(string id)
174187
/// <returns>a new LdAiConfig</returns>
175188
public LdAiConfig Build()
176189
{
177-
return new LdAiConfig(_enabled, _messages, new Meta(), new Model {Parameters = _modelParams, Custom = _customModelParams}, new Provider{ Id = _providerId });
190+
return new LdAiConfig(
191+
_enabled,
192+
_messages,
193+
new Meta(),
194+
new Model
195+
{
196+
Id = _modelId,
197+
Parameters = _modelParams,
198+
Custom = _customModelParams
199+
},
200+
new Provider{ Id = _providerId }
201+
);
178202
}
179203
}
180204

@@ -219,6 +243,7 @@ internal LdValue ToLdValue()
219243
}))) },
220244
{ "model", LdValue.ObjectFrom(new Dictionary<string, LdValue>
221245
{
246+
{ "id", LdValue.Of(Model.Id) },
222247
{ "parameters", LdValue.ObjectFrom(Model.Parameters) },
223248
{ "custom", LdValue.ObjectFrom(Model.Custom) }
224249
}) },

pkgs/sdk/server-ai/test/LdAiClientTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public void CanSetAllDefaultValueFields()
119119
LdAiConfig.New().
120120
AddMessage("foo").
121121
SetModelParam("foo", LdValue.Of("bar")).
122+
SetModelId("awesome-model").
122123
SetCustomModelParam("foo", LdValue.Of("baz")).
123124
SetModelProviderId("amazing-provider").
124125
SetEnabled(true).Build());
@@ -133,6 +134,7 @@ public void CanSetAllDefaultValueFields()
133134
Assert.Equal("amazing-provider", tracker.Config.Provider.Id);
134135
Assert.Equal("bar", tracker.Config.Model.Parameters["foo"].AsString);
135136
Assert.Equal("baz", tracker.Config.Model.Custom["foo"].AsString);
137+
Assert.Equal("awesome-model", tracker.Config.Model.Id);
136138
}
137139

138140
[Fact]

pkgs/sdk/server-ai/test/LdAiConfigTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public void CanSetModelParams()
7272
Assert.Equal(LdValue.Of(43), config.Model.Custom["baz"]);
7373
}
7474

75+
[Fact]
76+
public void CanSetModelId()
77+
{
78+
var config = LdAiConfig.New().SetModelId("awesome-model").Build();
79+
Assert.Equal("awesome-model", config.Model.Id);
80+
}
81+
7582
[Fact]
7683
public void CanSetModelProviderId()
7784
{

0 commit comments

Comments
 (0)