Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: rename model.id and provider.id to name #61

Merged
merged 2 commits into from
Dec 10, 2024
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
52 changes: 26 additions & 26 deletions pkgs/sdk/server-ai/src/Config/LdAiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ internal Message(string content, Role role)
public record ModelProvider
{
/// <summary>
/// The ID of the model provider.
/// The name of the model provider.
/// </summary>
public readonly string Id;
public readonly string Name;

internal ModelProvider(string id)
internal ModelProvider(string name)
{
Id = id;
Name = name;
}
}

Expand All @@ -55,9 +55,9 @@ internal ModelProvider(string id)
public record ModelConfiguration
{
/// <summary>
/// The ID of the model.
/// The name of the model.
/// </summary>
public readonly string Id;
public readonly string Name;

/// <summary>
/// The model's built-in parameters provided by LaunchDarkly.
Expand All @@ -69,9 +69,9 @@ public record ModelConfiguration
/// </summary>
public readonly IReadOnlyDictionary<string, LdValue> Custom;

internal ModelConfiguration(string id, IReadOnlyDictionary<string, LdValue> parameters, IReadOnlyDictionary<string, LdValue> custom)
internal ModelConfiguration(string name, IReadOnlyDictionary<string, LdValue> parameters, IReadOnlyDictionary<string, LdValue> custom)
{
Id = id;
Name = name;
Parameters = parameters;
Custom = custom;
}
Expand All @@ -87,17 +87,17 @@ public class Builder
private readonly List<Message> _messages;
private readonly Dictionary<string, LdValue> _modelParams;
private readonly Dictionary<string, LdValue> _customModelParams;
private string _providerId;
private string _modelId;
private string _providerName;
private string _modelName;

internal Builder()
{
_enabled = false;
_messages = new List<Message>();
_modelParams = new Dictionary<string, LdValue>();
_customModelParams = new Dictionary<string, LdValue>();
_providerId = "";
_modelId = "";
_providerName = "";
_modelName = "";
}

/// <summary>
Expand Down Expand Up @@ -160,24 +160,24 @@ public Builder SetCustomModelParam(string name, LdValue value)
}

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

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

Expand All @@ -193,11 +193,11 @@ public LdAiConfig Build()
new Meta(),
new Model
{
Id = _modelId,
Name = _modelName,
Parameters = _modelParams,
Custom = _customModelParams
},
new Provider{ Id = _providerId }
new Provider{ Name = _providerName }
);
}
}
Expand All @@ -219,12 +219,12 @@ public LdAiConfig Build()

internal LdAiConfig(bool enabled, IEnumerable<Message> messages, Meta meta, Model model, Provider provider)
{
Model = new ModelConfiguration(model?.Id ?? "", model?.Parameters ?? new Dictionary<string, LdValue>(),
Model = new ModelConfiguration(model?.Name ?? "", model?.Parameters ?? new Dictionary<string, LdValue>(),
model?.Custom ?? new Dictionary<string, LdValue>());
Messages = messages?.ToList() ?? new List<Message>();
VersionKey = meta?.VersionKey ?? "";
Enabled = enabled;
Provider = new ModelProvider(provider?.Id ?? "");
Provider = new ModelProvider(provider?.Name ?? "");
}
internal LdValue ToLdValue()
{
Expand All @@ -243,13 +243,13 @@ internal LdValue ToLdValue()
}))) },
{ "model", LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "id", LdValue.Of(Model.Id) },
{ "name", LdValue.Of(Model.Name) },
{ "parameters", LdValue.ObjectFrom(Model.Parameters) },
{ "custom", LdValue.ObjectFrom(Model.Custom) }
}) },
{"provider", LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{"id", LdValue.Of(Provider.Id)}
{"name", LdValue.Of(Provider.Name)}
})}
});
}
Expand Down
12 changes: 6 additions & 6 deletions pkgs/sdk/server-ai/src/DataModel/DataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public class AiConfig
public class Model
{
/// <summary>
/// The model's ID.
/// The model's name.
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }

/// <summary>
/// The model's parameters. These are provided by LaunchDarkly.
Expand All @@ -121,8 +121,8 @@ public class Model
public class Provider
{
/// <summary>
/// The provider's ID.
/// The provider's name.
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
}
20 changes: 10 additions & 10 deletions pkgs/sdk/server-ai/test/LdAiClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public void CanSetAllDefaultValueFields()
LdAiConfig.New().
AddMessage("foo").
SetModelParam("foo", LdValue.Of("bar")).
SetModelId("awesome-model").
SetModelName("awesome-model").
SetCustomModelParam("foo", LdValue.Of("baz")).
SetModelProviderId("amazing-provider").
SetModelProviderName("amazing-provider").
SetEnabled(true).Build());

Assert.True(tracker.Config.Enabled);
Expand All @@ -131,10 +131,10 @@ public void CanSetAllDefaultValueFields()
Assert.Equal("foo", message.Content);
Assert.Equal(Role.User, message.Role);
});
Assert.Equal("amazing-provider", tracker.Config.Provider.Id);
Assert.Equal("amazing-provider", tracker.Config.Provider.Name);
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);
Assert.Equal("awesome-model", tracker.Config.Model.Name);
}

[Fact]
Expand Down Expand Up @@ -170,8 +170,8 @@ public void ConfigEnabledReturnsInstance()
Assert.Equal(Role.System, message.Role);
});

Assert.Equal("", tracker.Config.Provider.Id);
Assert.Equal("", tracker.Config.Model.Id);
Assert.Equal("", tracker.Config.Provider.Name);
Assert.Equal("", tracker.Config.Model.Name);
Assert.Empty(tracker.Config.Model.Custom);
Assert.Empty(tracker.Config.Model.Parameters);
}
Expand All @@ -189,7 +189,7 @@ public void ModelParametersAreParsed()
{
"_ldMeta": {"versionKey": "1", "enabled": true},
"model" : {
"id": "model-foo",
"name": "model-foo",
"parameters": {
"foo": "bar",
"baz": 42
Expand All @@ -215,7 +215,7 @@ public void ModelParametersAreParsed()
var tracker = client.Config("foo", context,
LdAiConfig.New().AddMessage("Goodbye!").Build());

Assert.Equal("model-foo", tracker.Config.Model.Id);
Assert.Equal("model-foo", tracker.Config.Model.Name);
Assert.Equal("bar", tracker.Config.Model.Parameters["foo"].AsString);
Assert.Equal(42, tracker.Config.Model.Parameters["baz"].AsInt);
Assert.Equal("baz", tracker.Config.Model.Custom["foo"].AsString);
Expand All @@ -234,7 +234,7 @@ public void ProviderConfigIsParsed()
{
"_ldMeta": {"versionKey": "1", "enabled": true},
"provider": {
"id": "amazing-provider"
"name": "amazing-provider"
}
}
""";
Expand All @@ -252,6 +252,6 @@ public void ProviderConfigIsParsed()
var tracker = client.Config("foo", context,
LdAiConfig.New().AddMessage("Goodbye!").Build());

Assert.Equal("amazing-provider", tracker.Config.Provider.Id);
Assert.Equal("amazing-provider", tracker.Config.Provider.Name);
}
}
8 changes: 4 additions & 4 deletions pkgs/sdk/server-ai/test/LdAiConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ public void CanSetModelParams()
[Fact]
public void CanSetModelId()
{
var config = LdAiConfig.New().SetModelId("awesome-model").Build();
Assert.Equal("awesome-model", config.Model.Id);
var config = LdAiConfig.New().SetModelName("awesome-model").Build();
Assert.Equal("awesome-model", config.Model.Name);
}

[Fact]
public void CanSetModelProviderId()
{
var config = LdAiConfig.New()
.SetModelProviderId("amazing-provider")
.SetModelProviderName("amazing-provider")
.Build();

Assert.Equal("amazing-provider", config.Provider.Id);
Assert.Equal("amazing-provider", config.Provider.Name);
}
}
Loading