@@ -43,7 +43,19 @@ def td() -> TestData:
4343 .variations (
4444 {
4545 '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}}?' }],
4759 '_ldMeta' : {'enabled' : True , 'versionKey' : 'abcd' },
4860 }
4961 )
@@ -192,7 +204,7 @@ def test_provider_config_handling(ldai_client: LDAIClient):
192204
193205
194206def 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 ()
196208 default_value = AIConfig (enabled = True , model = ModelConfig ('fake-model' ), messages = [])
197209 variables = {'name' : 'World' }
198210
@@ -202,7 +214,30 @@ def test_context_interpolation(ldai_client: LDAIClient):
202214
203215 assert config .messages is not None
204216 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?'
206241 assert config .enabled is True
207242
208243 assert config .model is not None
0 commit comments