11import pytest
22from ldclient import LDClient , Context , Config
33from ldclient .integrations .test_data import TestData
4- from ldai .types import AIConfig
4+ from ldai .types import AIConfig , AIConfigData , LDMessage
55from ldai .client import LDAIClient
6+ from ldai .tracker import LDAIConfigTracker
67from ldclient .testing .builders import *
78
9+
10+
811@pytest .fixture
912def td () -> TestData :
1013 td = TestData .data_source ()
@@ -45,57 +48,56 @@ def ldai_client(client: LDClient) -> LDAIClient:
4548
4649def test_model_config_interpolation (ldai_client : LDAIClient ):
4750 context = Context .create ('user-key' )
48- default_value = AIConfig (config = {
49- 'model' : { 'modelId' : 'fakeModel' },
50- 'prompt' : [{'role' : 'system' , 'content' : 'Hello, {{name}}!' }],
51- '_ldMeta' : {'enabled' : True , 'versionKey' : 'abcd' }
52- }, tracker = None , enabled = True )
51+ default_value = AIConfig (config = AIConfigData (model = { 'modelId' : 'fakeModel' }, prompt = [LDMessage (role = 'system' , content = 'Hello, {{name}}!' )], _ldMeta = {'enabled' : True , 'versionKey' : 'abcd' }), tracker = LDAIConfigTracker (), enabled = True )
5352 variables = {'name' : 'World' }
5453
5554 config = ldai_client .model_config ('model-config' , context , default_value , variables )
56-
57- assert config .config ['prompt' ][0 ]['content' ] == 'Hello, World!'
55+
56+ assert config .config .prompt is not None
57+ assert len (config .config .prompt ) > 0
58+ assert config .config .prompt [0 ].content == 'Hello, World!'
5859 assert config .enabled is True
59- assert config .tracker .version_key == 'abcd'
6060
6161def test_model_config_no_variables (ldai_client : LDAIClient ):
6262 context = Context .create ('user-key' )
63- default_value = AIConfig (config = {}, tracker = None , enabled = True )
63+ default_value = AIConfig (config = AIConfigData ( model = {}, prompt = [], _ldMeta = { 'enabled' : True , 'versionKey' : 'abcd' }), tracker = LDAIConfigTracker () , enabled = True )
6464
6565 config = ldai_client .model_config ('model-config' , context , default_value , {})
6666
67- assert config .config ['prompt' ][0 ]['content' ] == 'Hello, !'
67+ assert config .config .prompt is not None
68+ assert len (config .config .prompt ) > 0
69+ assert config .config .prompt [0 ].content == 'Hello, !'
6870 assert config .enabled is True
69- assert config .tracker .version_key == 'abcd'
7071
7172def test_context_interpolation (ldai_client : LDAIClient ):
7273 context = Context .builder ('user-key' ).name ("Sandy" ).build ()
73- default_value = AIConfig (config = {}, tracker = None , enabled = True )
74+ default_value = AIConfig (config = AIConfigData ( model = {}, prompt = [], _ldMeta = { 'enabled' : True , 'versionKey' : 'abcd' }), tracker = LDAIConfigTracker () , enabled = True )
7475 variables = {'name' : 'World' }
7576
7677 config = ldai_client .model_config ('ctx-interpolation' , context , default_value , variables )
7778
78- assert config .config ['prompt' ][0 ]['content' ] == 'Hello, Sandy!'
79+ assert config .config .prompt is not None
80+ assert len (config .config .prompt ) > 0
81+ assert config .config .prompt [0 ].content == 'Hello, Sandy!'
7982 assert config .enabled is True
80- assert config .tracker .version_key == 'abcd'
81-
83+
8284def test_model_config_disabled (ldai_client : LDAIClient ):
8385 context = Context .create ('user-key' )
84- default_value = AIConfig (config = {}, tracker = None , enabled = True )
86+ default_value = AIConfig (config = AIConfigData ( model = {}, prompt = [], _ldMeta = { 'enabled' : True , 'versionKey' : 'abcd' }), tracker = LDAIConfigTracker () , enabled = True )
8587
8688 config = ldai_client .model_config ('off-config' , context , default_value , {})
8789
8890 assert config .enabled is False
89- assert config .tracker .version_key == 'abcd'
9091
9192def test_model_config_multiple (ldai_client : LDAIClient ):
9293 context = Context .create ('user-key' )
93- default_value = AIConfig (config = {}, tracker = None , enabled = True )
94+ default_value = AIConfig (config = AIConfigData ( model = {}, prompt = [], _ldMeta = { 'enabled' : True , 'versionKey' : 'abcd' }), tracker = LDAIConfigTracker () , enabled = True )
9495 variables = {'name' : 'World' , 'day' : 'Monday' }
9596
9697 config = ldai_client .model_config ('multiple-prompt' , context , default_value , variables )
9798
98- assert config .config ['prompt' ][0 ]['content' ] == 'Hello, World!'
99- assert config .config ['prompt' ][1 ]['content' ] == 'The day is, Monday!'
100- assert config .enabled is True
101- assert config .tracker .version_key == 'abcd'
99+ assert config .config .prompt is not None
100+ assert len (config .config .prompt ) > 0
101+ assert config .config .prompt [0 ].content == 'Hello, World!'
102+ assert config .config .prompt [1 ].content == 'The day is, Monday!'
103+ assert config .enabled is True
0 commit comments