@@ -43,7 +43,19 @@ def td() -> TestData:
43
43
.variations (
44
44
{
45
45
'model' : {'id' : 'fakeModel' , 'parameters' : {'extra-attribute' : 'I can be anything I set my mind/type to' }},
46
- 'messages' : [{'role' : 'system' , 'content' : 'Hello, {{ldctx.name}}!' }],
46
+ 'messages' : [{'role' : 'system' , 'content' : 'Hello, {{ldctx.name}}! Is your last name {{ldctx.last}}?' }],
47
+ '_ldMeta' : {'enabled' : True , 'versionKey' : 'abcd' },
48
+ }
49
+ )
50
+ .variation_for_all (0 )
51
+ )
52
+
53
+ td .update (
54
+ td .flag ('multi-ctx-interpolation' )
55
+ .variations (
56
+ {
57
+ 'model' : {'id' : 'fakeModel' , 'parameters' : {'extra-attribute' : 'I can be anything I set my mind/type to' }},
58
+ 'messages' : [{'role' : 'system' , 'content' : 'Hello, {{ldctx.user.name}}! Do you work for {{ldctx.org.shortname}}?' }],
47
59
'_ldMeta' : {'enabled' : True , 'versionKey' : 'abcd' },
48
60
}
49
61
)
@@ -192,7 +204,7 @@ def test_provider_config_handling(ldai_client: LDAIClient):
192
204
193
205
194
206
def test_context_interpolation (ldai_client : LDAIClient ):
195
- context = Context .builder ('user-key' ).name ("Sandy" ).build ()
207
+ context = Context .builder ('user-key' ).name ("Sandy" ).set ( 'last' , 'Beaches' ). build ()
196
208
default_value = AIConfig (enabled = True , model = ModelConfig ('fake-model' ), messages = [])
197
209
variables = {'name' : 'World' }
198
210
@@ -202,7 +214,30 @@ def test_context_interpolation(ldai_client: LDAIClient):
202
214
203
215
assert config .messages is not None
204
216
assert len (config .messages ) > 0
205
- assert config .messages [0 ].content == 'Hello, Sandy!'
217
+ assert config .messages [0 ].content == 'Hello, Sandy! Is your last name Beaches?'
218
+ assert config .enabled is True
219
+
220
+ assert config .model is not None
221
+ assert config .model .id == 'fakeModel'
222
+ assert config .model .get_parameter ('temperature' ) is None
223
+ assert config .model .get_parameter ('maxTokens' ) is None
224
+ assert config .model .get_parameter ('extra-attribute' ) == 'I can be anything I set my mind/type to'
225
+
226
+
227
+ def test_multi_context_interpolation (ldai_client : LDAIClient ):
228
+ user_context = Context .builder ('user-key' ).name ("Sandy" ).build ()
229
+ org_context = Context .builder ('org-key' ).kind ('org' ).name ("LaunchDarkly" ).set ('shortname' , 'LD' ).build ()
230
+ context = Context .multi_builder ().add (user_context ).add (org_context ).build ()
231
+ default_value = AIConfig (enabled = True , model = ModelConfig ('fake-model' ), messages = [])
232
+ variables = {'name' : 'World' }
233
+
234
+ config , _ = ldai_client .config (
235
+ 'multi-ctx-interpolation' , context , default_value , variables
236
+ )
237
+
238
+ assert config .messages is not None
239
+ assert len (config .messages ) > 0
240
+ assert config .messages [0 ].content == 'Hello, Sandy! Do you work for LD?'
206
241
assert config .enabled is True
207
242
208
243
assert config .model is not None
0 commit comments