|
8 | 8 | namespace LaunchDarkly.Sdk.Server.Ai.Config |
9 | 9 | { |
10 | 10 |
|
11 | | - |
12 | 11 | /// <summary> |
13 | | - /// TBD |
| 12 | + /// Represents an AI configuration, which contains model parameters and prompt messages. |
14 | 13 | /// </summary> |
15 | 14 | public record LdAiConfig |
16 | 15 | { |
17 | 16 |
|
18 | 17 | /// <summary> |
19 | | - /// TBD |
| 18 | + /// Represents a single message, which is part of a prompt. |
20 | 19 | /// </summary> |
21 | 20 | public record Message |
22 | 21 | { |
23 | 22 | /// <summary> |
24 | | - /// TBD |
| 23 | + /// The content of the message, which may contain Mustache templates. |
25 | 24 | /// </summary> |
26 | 25 | public readonly string Content; |
27 | 26 |
|
28 | 27 | /// <summary> |
29 | | - /// TBD |
| 28 | + /// The role of the message. |
30 | 29 | /// </summary> |
31 | 30 | public readonly Role Role; |
32 | 31 |
|
33 | | - /// <summary> |
34 | | - /// TBD |
35 | | - /// </summary> |
36 | | - /// <param name="content">TBD</param> |
37 | | - /// <param name="role">TBD</param> |
38 | | - public Message(string content, Role role) |
| 32 | + internal Message(string content, Role role) |
39 | 33 | { |
40 | 34 | Content = content; |
41 | 35 | Role = role; |
42 | 36 | } |
43 | 37 | } |
44 | 38 |
|
45 | 39 | /// <summary> |
46 | | - /// TBD |
| 40 | + /// Builder for constructing an LdAiConfig instance, which can be passed as the default |
| 41 | + /// value to the AI Client's <see cref="LdAiClient.ModelConfig"/> method. |
47 | 42 | /// </summary> |
48 | 43 | public class Builder |
49 | 44 | { |
50 | 45 | private readonly List<Message> _prompt; |
51 | 46 | private bool _enabled; |
52 | | - private Dictionary<string, object> _modelParams; |
| 47 | + private readonly Dictionary<string, object> _modelParams; |
53 | 48 |
|
54 | 49 |
|
55 | 50 | /// <summary> |
56 | | - /// TBD |
| 51 | + /// Constructs a new builder. By default, the config will be disabled, with no prompt |
| 52 | + /// messages or model parameters. |
57 | 53 | /// </summary> |
58 | 54 | public Builder() |
59 | 55 | { |
60 | | - _enabled = true; |
| 56 | + _enabled = false; |
61 | 57 | _prompt = new List<Message>(); |
62 | 58 | _modelParams = new Dictionary<string, object>(); |
63 | 59 | } |
64 | 60 |
|
65 | 61 | /// <summary> |
66 | | - /// TBD |
| 62 | + /// Adds a prompt message with the given content and role. The default role is <see cref="Role.User"/>. |
67 | 63 | /// </summary> |
68 | | - /// <param name="content"></param> |
69 | | - /// <param name="role"></param> |
70 | | - /// <returns></returns> |
| 64 | + /// <param name="content">the content, which may contain Mustache templates</param> |
| 65 | + /// <param name="role">the role</param> |
| 66 | + /// <returns>a new builder</returns> |
71 | 67 | public Builder AddPromptMessage(string content, Role role = Role.User) |
72 | 68 | { |
73 | 69 | _prompt.Add(new Message(content, role)); |
74 | 70 | return this; |
75 | 71 | } |
76 | 72 |
|
77 | 73 | /// <summary> |
78 | | - /// |
| 74 | + /// Disables the config. |
79 | 75 | /// </summary> |
80 | | - /// <returns></returns> |
81 | | - public Builder Disable() |
82 | | - { |
83 | | - return SetEnabled(false); |
84 | | - } |
| 76 | + /// <returns>the builder</returns> |
| 77 | + public Builder Disable() => SetEnabled(false); |
85 | 78 |
|
86 | 79 | /// <summary> |
87 | | - /// |
| 80 | + /// Enables the config. |
88 | 81 | /// </summary> |
89 | | - /// <param name="enabled"></param> |
90 | | - /// <returns></returns> |
| 82 | + /// <returns>the builder</returns> |
| 83 | + public Builder Enable() => SetEnabled(true); |
| 84 | + |
| 85 | + /// <summary> |
| 86 | + /// Sets the enabled state of the config based on a boolean. |
| 87 | + /// </summary> |
| 88 | + /// <param name="enabled">whether the config is enabled</param> |
| 89 | + /// <returns>the builder</returns> |
91 | 90 | public Builder SetEnabled(bool enabled) |
92 | 91 | { |
93 | 92 | _enabled = enabled; |
94 | 93 | return this; |
95 | 94 | } |
96 | 95 |
|
97 | 96 | /// <summary> |
98 | | - /// |
| 97 | + /// Sets a parameter for the model. The value may be any object. |
99 | 98 | /// </summary> |
100 | | - /// <param name="key"></param> |
101 | | - /// <param name="value"></param> |
102 | | - /// <returns></returns> |
103 | | - public Builder SetModelParam(string key, object value) |
| 99 | + /// <param name="name">the parameter name</param> |
| 100 | + /// <param name="value">the parameter value</param> |
| 101 | + /// <returns>the builder</returns> |
| 102 | + public Builder SetModelParam(string name, object value) |
104 | 103 | { |
105 | | - _modelParams[key] = value; |
| 104 | + _modelParams[name] = value; |
106 | 105 | return this; |
107 | 106 | } |
108 | 107 |
|
109 | 108 | /// <summary> |
110 | | - /// TBD |
| 109 | + /// Builds the LdAiConfig instance. |
111 | 110 | /// </summary> |
112 | | - /// <returns></returns> |
| 111 | + /// <returns>a new LdAiConfig</returns> |
113 | 112 | public LdAiConfig Build() |
114 | 113 | { |
115 | 114 | return new LdAiConfig(_enabled, _prompt, new Meta(), _modelParams); |
116 | 115 | } |
117 | 116 | } |
118 | 117 |
|
119 | 118 | /// <summary> |
120 | | - /// TBD |
| 119 | + /// The prompts associated with the config. |
121 | 120 | /// </summary> |
122 | 121 | public readonly IReadOnlyList<Message> Prompt; |
123 | 122 |
|
124 | 123 | /// <summary> |
125 | | - /// TBD |
| 124 | + /// The model parameters associated with the config. |
126 | 125 | /// </summary> |
127 | 126 | public readonly IReadOnlyDictionary<string, object> Model; |
128 | 127 |
|
129 | | - private readonly string _versionKey; |
130 | | - |
131 | | - |
132 | | - private readonly bool _enabled; |
133 | | - |
134 | 128 | internal LdAiConfig(bool enabled, IEnumerable<Message> prompt, Meta meta, IReadOnlyDictionary<string, object> model) |
135 | 129 | { |
136 | | - Model = model; |
137 | | - Prompt = prompt?.ToList(); |
138 | | - _versionKey = meta?.VersionKey ?? ""; |
139 | | - _enabled = enabled; |
| 130 | + Model = model ?? new Dictionary<string, object>(); |
| 131 | + Prompt = prompt?.ToList() ?? new List<Message>(); |
| 132 | + VersionKey = meta?.VersionKey ?? ""; |
| 133 | + Enabled = enabled; |
140 | 134 | } |
141 | 135 |
|
142 | 136 |
|
143 | 137 | /// <summary> |
144 | | - /// TBD |
| 138 | + /// Creates a new LdAiConfig builder. |
145 | 139 | /// </summary> |
146 | | - /// <returns></returns> |
| 140 | + /// <returns>the builder</returns> |
147 | 141 | public static Builder New() => new(); |
148 | 142 |
|
149 | 143 | /// <summary> |
150 | | - /// TBD |
| 144 | + /// Returns true if the config is enabled. |
151 | 145 | /// </summary> |
152 | | - /// <returns></returns> |
153 | | - public bool IsEnabled() => _enabled; |
| 146 | + /// <returns>true if enabled</returns> |
| 147 | + public bool Enabled { get; } |
154 | 148 |
|
155 | 149 |
|
156 | 150 | /// <summary> |
157 | | - /// |
| 151 | + /// This field meant for internal LaunchDarkly usage. |
158 | 152 | /// </summary> |
159 | | - public string VersionKey => _versionKey; |
| 153 | + public string VersionKey { get; } |
160 | 154 |
|
161 | 155 | /// <summary> |
162 | | - /// TBD |
| 156 | + /// Convenient helper that returns a disabled LdAiConfig. |
163 | 157 | /// </summary> |
164 | | - public static LdAiConfig Disabled = new LdAiConfig(false, null, null, null); |
| 158 | + public static LdAiConfig Disabled = New().Disable().Build(); |
165 | 159 |
|
166 | 160 | } |
167 | 161 | } |
0 commit comments