11import pytest
22from ldclient import LDClient , Context , Config
33from ldclient .integrations .test_data import TestData
4- from ldai .types import AIConfig , AIConfigData , LDMessage
5- from ldai .client import LDAIClient
4+ from ldai .client import AIConfig , AIConfigData , LDAIClient , LDMessage
65from ldai .tracker import LDAIConfigTracker
76from ldclient .testing .builders import *
87
@@ -41,13 +40,17 @@ def client(td: TestData) -> LDClient:
4140 config = Config ('sdk-key' , update_processor_class = td , send_events = False )
4241 return LDClient (config = config )
4342
43+ @pytest .fixture
44+ def tracker (td : TestData ) -> LDAIConfigTracker :
45+ return LDAIConfigTracker (client (td ), 'abcd' , 'model-config' , Context .create ('user-key' ))
46+
4447@pytest .fixture
4548def ldai_client (client : LDClient ) -> LDAIClient :
4649 return LDAIClient (client )
4750
4851def test_model_config_interpolation (ldai_client : LDAIClient ):
4952 context = Context .create ('user-key' )
50- default_value = AIConfig (config = AIConfigData (model = { 'modelId' : 'fakeModel' }, prompt = [LDMessage (role = 'system' , content = 'Hello, {{name}}!' )], _ldMeta = { 'enabled' : True , 'versionKey' : 'abcd' } ), tracker = LDAIConfigTracker ( ), enabled = True )
53+ default_value = AIConfig (config = AIConfigData (model = { 'modelId' : 'fakeModel' }, prompt = [LDMessage (role = 'system' , content = 'Hello, {{name}}!' )]), tracker = tracker ( td () ), enabled = True )
5154 variables = {'name' : 'World' }
5255
5356 config = ldai_client .model_config ('model-config' , context , default_value , variables )
@@ -59,7 +62,7 @@ def test_model_config_interpolation(ldai_client: LDAIClient):
5962
6063def test_model_config_no_variables (ldai_client : LDAIClient ):
6164 context = Context .create ('user-key' )
62- default_value = AIConfig (config = AIConfigData (model = {}, prompt = [], _ldMeta = { 'enabled' : True , 'versionKey' : 'abcd' } ), tracker = LDAIConfigTracker ( ), enabled = True )
65+ default_value = AIConfig (config = AIConfigData (model = {}, prompt = []), tracker = tracker ( td () ), enabled = True )
6366
6467 config = ldai_client .model_config ('model-config' , context , default_value , {})
6568
@@ -70,7 +73,7 @@ def test_model_config_no_variables(ldai_client: LDAIClient):
7073
7174def test_context_interpolation (ldai_client : LDAIClient ):
7275 context = Context .builder ('user-key' ).name ("Sandy" ).build ()
73- default_value = AIConfig (config = AIConfigData (model = {}, prompt = [], _ldMeta = { 'enabled' : True , 'versionKey' : 'abcd' } ), tracker = LDAIConfigTracker ( ), enabled = True )
76+ default_value = AIConfig (config = AIConfigData (model = {}, prompt = []), tracker = tracker ( td () ), enabled = True )
7477 variables = {'name' : 'World' }
7578
7679 config = ldai_client .model_config ('ctx-interpolation' , context , default_value , variables )
@@ -80,17 +83,9 @@ def test_context_interpolation(ldai_client: LDAIClient):
8083 assert config .config .prompt [0 ].content == 'Hello, Sandy!'
8184 assert config .enabled is True
8285
83- def test_model_config_disabled (ldai_client : LDAIClient ):
84- context = Context .create ('user-key' )
85- default_value = AIConfig (config = AIConfigData (model = {}, prompt = [], _ldMeta = {'enabled' : True , 'versionKey' : 'abcd' }), tracker = LDAIConfigTracker (), enabled = True )
86-
87- config = ldai_client .model_config ('off-config' , context , default_value , {})
88-
89- assert config .enabled is False
90-
9186def test_model_config_multiple (ldai_client : LDAIClient ):
9287 context = Context .create ('user-key' )
93- default_value = AIConfig (config = AIConfigData (model = {}, prompt = [], _ldMeta = { 'enabled' : True , 'versionKey' : 'abcd' } ), tracker = LDAIConfigTracker ( ), enabled = True )
88+ default_value = AIConfig (config = AIConfigData (model = {}, prompt = []), tracker = tracker ( td () ), enabled = True )
9489 variables = {'name' : 'World' , 'day' : 'Monday' }
9590
9691 config = ldai_client .model_config ('multiple-prompt' , context , default_value , variables )
@@ -99,4 +94,12 @@ def test_model_config_multiple(ldai_client: LDAIClient):
9994 assert len (config .config .prompt ) > 0
10095 assert config .config .prompt [0 ].content == 'Hello, World!'
10196 assert config .config .prompt [1 ].content == 'The day is, Monday!'
102- assert config .enabled is True
97+ assert config .enabled is True
98+
99+ def test_model_config_disabled (ldai_client : LDAIClient ):
100+ context = Context .create ('user-key' )
101+ default_value = AIConfig (config = AIConfigData (model = {}, prompt = []), tracker = tracker (td ()), enabled = False )
102+
103+ config = ldai_client .model_config ('off-config' , context , default_value , {})
104+
105+ assert config .enabled is False
0 commit comments