@@ -32,32 +32,81 @@ internal Message(string content, Role role)
3232 }
3333 }
3434
35+
36+ /// <summary>
37+ /// Information about the model provider.
38+ /// </summary>
39+ public record ModelProvider
40+ {
41+ /// <summary>
42+ /// The ID of the model provider.
43+ /// </summary>
44+ public readonly string Id ;
45+
46+ internal ModelProvider ( string id )
47+ {
48+ Id = id ;
49+ }
50+ }
51+
52+ /// <summary>
53+ /// Information about the model.
54+ /// </summary>
55+ public record ModelConfiguration
56+ {
57+ /// <summary>
58+ /// The ID of the model.
59+ /// </summary>
60+ public readonly string Id ;
61+
62+ /// <summary>
63+ /// The model's built-in parameters provided by LaunchDarkly.
64+ /// </summary>
65+ public readonly IReadOnlyDictionary < string , LdValue > Parameters ;
66+
67+ /// <summary>
68+ /// The model's custom parameters provided by the user.
69+ /// </summary>
70+ public readonly IReadOnlyDictionary < string , LdValue > Custom ;
71+
72+ internal ModelConfiguration ( string id , IReadOnlyDictionary < string , LdValue > parameters , IReadOnlyDictionary < string , LdValue > custom )
73+ {
74+ Id = id ;
75+ Parameters = parameters ;
76+ Custom = custom ;
77+ }
78+ }
79+
3580 /// <summary>
3681 /// Builder for constructing an LdAiConfig instance, which can be passed as the default
3782 /// value to the AI Client's <see cref="LdAiClient.ModelConfig"/> method.
3883 /// </summary>
3984 public class Builder
4085 {
4186 private bool _enabled ;
42- private readonly List < Message > _prompt ;
43- private readonly Dictionary < string , object > _modelParams ;
87+ private readonly List < Message > _messages ;
88+ private readonly Dictionary < string , LdValue > _modelParams ;
89+ private readonly Dictionary < string , LdValue > _customModelParams ;
90+ private string _providerId ;
4491
4592 internal Builder ( )
4693 {
4794 _enabled = false ;
48- _prompt = new List < Message > ( ) ;
49- _modelParams = new Dictionary < string , object > ( ) ;
95+ _messages = new List < Message > ( ) ;
96+ _modelParams = new Dictionary < string , LdValue > ( ) ;
97+ _customModelParams = new Dictionary < string , LdValue > ( ) ;
98+ _providerId = "" ;
5099 }
51100
52101 /// <summary>
53- /// Adds a prompt message with the given content and role. The default role is <see cref="Role.User"/>.
102+ /// Adds a message with the given content and role. The default role is <see cref="Role.User"/>.
54103 /// </summary>
55104 /// <param name="content">the content, which may contain Mustache templates</param>
56105 /// <param name="role">the role</param>
57106 /// <returns>a new builder</returns>
58- public Builder AddPromptMessage ( string content , Role role = Role . User )
107+ public Builder AddMessage ( string content , Role role = Role . User )
59108 {
60- _prompt . Add ( new Message ( content , role ) ) ;
109+ _messages . Add ( new Message ( content , role ) ) ;
61110 return this ;
62111 }
63112
@@ -85,66 +134,74 @@ public Builder SetEnabled(bool enabled)
85134 }
86135
87136 /// <summary>
88- /// Sets a parameter for the model. The value may be any object.
137+ /// Sets a parameter for the model.
89138 /// </summary>
90139 /// <param name="name">the parameter name</param>
91140 /// <param name="value">the parameter value</param>
92141 /// <returns>the builder</returns>
93- public Builder SetModelParam ( string name , object value )
142+ public Builder SetModelParam ( string name , LdValue value )
94143 {
95144 _modelParams [ name ] = value ;
96145 return this ;
97146 }
98147
148+ /// <summary>
149+ /// Sets a custom parameter for the model.
150+ /// </summary>
151+ /// <param name="name">the custom parameter name</param>
152+ /// <param name="value">the custom parameter value</param>
153+ /// <returns>the builder</returns>
154+ public Builder SetCustomModelParam ( string name , LdValue value )
155+ {
156+ _customModelParams [ name ] = value ;
157+ return this ;
158+ }
159+
160+ /// <summary>
161+ /// Sets the model provider's ID. By default, this will be the empty string.
162+ /// </summary>
163+ /// <param name="id">the ID</param>
164+ /// <returns></returns>
165+ public Builder SetModelProviderId ( string id )
166+ {
167+ _providerId = id ;
168+ return this ;
169+ }
170+
99171 /// <summary>
100172 /// Builds the LdAiConfig instance.
101173 /// </summary>
102174 /// <returns>a new LdAiConfig</returns>
103175 public LdAiConfig Build ( )
104176 {
105- return new LdAiConfig ( _enabled , _prompt , new Meta ( ) , _modelParams ) ;
177+ return new LdAiConfig ( _enabled , _messages , new Meta ( ) , new Model { Parameters = _modelParams , Custom = _customModelParams } , new Provider { Id = _providerId } ) ;
106178 }
107179 }
108180
109181 /// <summary>
110182 /// The prompts associated with the config.
111183 /// </summary>
112- public readonly IReadOnlyList < Message > Prompt ;
184+ public readonly IReadOnlyList < Message > Messages ;
113185
114186 /// <summary>
115187 /// The model parameters associated with the config.
116188 /// </summary>
117- public readonly IReadOnlyDictionary < string , object > Model ;
118-
189+ public readonly ModelConfiguration Model ;
119190
191+ /// <summary>
192+ /// Information about the model provider.
193+ /// </summary>
194+ public readonly ModelProvider Provider ;
120195
121- internal LdAiConfig ( bool enabled , IEnumerable < Message > prompt , Meta meta , IReadOnlyDictionary < string , object > model )
196+ internal LdAiConfig ( bool enabled , IEnumerable < Message > messages , Meta meta , Model model , Provider provider )
122197 {
123- Model = model ?? new Dictionary < string , object > ( ) ;
124- Prompt = prompt ? . ToList ( ) ?? new List < Message > ( ) ;
198+ Model = new ModelConfiguration ( model ? . Id ?? "" , model ? . Parameters ?? new Dictionary < string , LdValue > ( ) ,
199+ model ? . Custom ?? new Dictionary < string , LdValue > ( ) ) ;
200+ Messages = messages ? . ToList ( ) ?? new List < Message > ( ) ;
125201 VersionKey = meta ? . VersionKey ?? "" ;
126202 Enabled = enabled ;
203+ Provider = new ModelProvider ( provider ? . Id ?? "" ) ;
127204 }
128-
129- private static LdValue ObjectToValue ( object obj )
130- {
131- if ( obj == null )
132- {
133- return LdValue . Null ;
134- }
135-
136- return obj switch
137- {
138- bool b => LdValue . Of ( b ) ,
139- double d => LdValue . Of ( d ) ,
140- string s => LdValue . Of ( s ) ,
141- IEnumerable < object > list => LdValue . ArrayFrom ( list . Select ( ObjectToValue ) ) ,
142- IDictionary < string , object > dict => LdValue . ObjectFrom ( dict . ToDictionary ( kv => kv . Key ,
143- kv => ObjectToValue ( kv . Value ) ) ) ,
144- _ => LdValue . Null
145- } ;
146- }
147-
148205 internal LdValue ToLdValue ( )
149206 {
150207 return LdValue . ObjectFrom ( new Dictionary < string , LdValue >
@@ -155,12 +212,20 @@ internal LdValue ToLdValue()
155212 { "versionKey" , LdValue . Of ( VersionKey ) } ,
156213 { "enabled" , LdValue . Of ( Enabled ) }
157214 } ) } ,
158- { "prompt " , LdValue . ArrayFrom ( Prompt . Select ( m => LdValue . ObjectFrom ( new Dictionary < string , LdValue >
215+ { "messages " , LdValue . ArrayFrom ( Messages . Select ( m => LdValue . ObjectFrom ( new Dictionary < string , LdValue >
159216 {
160217 { "content" , LdValue . Of ( m . Content ) } ,
161218 { "role" , LdValue . Of ( m . Role . ToString ( ) ) }
162219 } ) ) ) } ,
163- { "model" , ObjectToValue ( Model ) }
220+ { "model" , LdValue . ObjectFrom ( new Dictionary < string , LdValue >
221+ {
222+ { "parameters" , LdValue . ObjectFrom ( Model . Parameters ) } ,
223+ { "custom" , LdValue . ObjectFrom ( Model . Custom ) }
224+ } ) } ,
225+ { "provider" , LdValue . ObjectFrom ( new Dictionary < string , LdValue >
226+ {
227+ { "id" , LdValue . Of ( Provider . Id ) }
228+ } ) }
164229 } ) ;
165230 }
166231
@@ -176,7 +241,6 @@ internal LdValue ToLdValue()
176241 /// <returns>true if enabled</returns>
177242 public bool Enabled { get ; }
178243
179-
180244 /// <summary>
181245 /// This field meant for internal LaunchDarkly usage.
182246 /// </summary>
@@ -185,7 +249,5 @@ internal LdValue ToLdValue()
185249 /// <summary>
186250 /// Convenient helper that returns a disabled LdAiConfig.
187251 /// </summary>
188- public static LdAiConfig Disabled = New ( ) . Disable ( ) . Build ( ) ;
189-
190-
252+ public static LdAiConfig Disabled => New ( ) . Disable ( ) . Build ( ) ;
191253}
0 commit comments