@@ -11,36 +11,24 @@ const mockLdClient: jest.Mocked<LDClientMin> = {
1111
1212const testContext : LDContext = { kind : 'user' , key : 'test-user' } ;
1313
14- it ( 'interpolates template variables' , ( ) => {
15- const client = new LDAIClientImpl ( mockLdClient ) ;
16- const template = 'Hello {{name}}, your score is {{score}}' ;
17- const variables = { name : 'John' , score : 42 } ;
18-
19- const result = client . interpolateTemplate ( template , variables ) ;
20- expect ( result ) . toBe ( 'Hello John, your score is 42' ) ;
21- } ) ;
22-
23- it ( 'handles empty variables in template interpolation' , ( ) => {
24- const client = new LDAIClientImpl ( mockLdClient ) ;
25- const template = 'Hello {{name}}' ;
26- const variables = { } ;
27-
28- const result = client . interpolateTemplate ( template , variables ) ;
29- expect ( result ) . toBe ( 'Hello ' ) ;
30- } ) ;
31-
32- it ( 'returns model config with interpolated prompts' , async ( ) => {
14+ it ( 'returns config with interpolated messagess' , async ( ) => {
3315 const client = new LDAIClientImpl ( mockLdClient ) ;
3416 const key = 'test-flag' ;
3517 const defaultValue : LDAIDefaults = {
36- model : { modelId : 'test' , name : 'test-model' } ,
37- prompt : [ ] ,
18+ model : { id : 'test' , parameters : { name : 'test-model' } } ,
19+ messages : [ ] ,
3820 enabled : true ,
3921 } ;
4022
4123 const mockVariation = {
42- model : { modelId : 'example-provider' , name : 'imagination' , temperature : 0.7 , maxTokens : 4096 } ,
43- prompt : [
24+ model : {
25+ id : 'example-model' ,
26+ parameters : { name : 'imagination' , temperature : 0.7 , maxTokens : 4096 } ,
27+ } ,
28+ provider : {
29+ id : 'example-provider' ,
30+ } ,
31+ messages : [
4432 { role : 'system' , content : 'Hello {{name}}' } ,
4533 { role : 'user' , content : 'Score: {{score}}' } ,
4634 ] ,
@@ -53,11 +41,17 @@ it('returns model config with interpolated prompts', async () => {
5341 mockLdClient . variation . mockResolvedValue ( mockVariation ) ;
5442
5543 const variables = { name : 'John' , score : 42 } ;
56- const result = await client . modelConfig ( key , testContext , defaultValue , variables ) ;
44+ const result = await client . config ( key , testContext , defaultValue , variables ) ;
5745
5846 expect ( result ) . toEqual ( {
59- model : { modelId : 'example-provider' , name : 'imagination' , temperature : 0.7 , maxTokens : 4096 } ,
60- prompt : [
47+ model : {
48+ id : 'example-model' ,
49+ parameters : { name : 'imagination' , temperature : 0.7 , maxTokens : 4096 } ,
50+ } ,
51+ provider : {
52+ id : 'example-provider' ,
53+ } ,
54+ messages : [
6155 { role : 'system' , content : 'Hello John' } ,
6256 { role : 'user' , content : 'Score: 42' } ,
6357 ] ,
@@ -66,46 +60,46 @@ it('returns model config with interpolated prompts', async () => {
6660 } ) ;
6761} ) ;
6862
69- it ( 'includes context in variables for prompt interpolation' , async ( ) => {
63+ it ( 'includes context in variables for messages interpolation' , async ( ) => {
7064 const client = new LDAIClientImpl ( mockLdClient ) ;
7165 const key = 'test-flag' ;
7266 const defaultValue : LDAIDefaults = {
73- model : { modelId : 'test' , name : 'test-model' } ,
74- prompt : [ ] ,
67+ model : { id : 'test' , parameters : { name : 'test-model' } } ,
68+ messages : [ ] ,
7569 } ;
7670
7771 const mockVariation = {
78- prompt : [ { role : 'system' , content : 'User key: {{ldctx.key}}' } ] ,
72+ messages : [ { role : 'system' , content : 'User key: {{ldctx.key}}' } ] ,
7973 _ldMeta : { versionKey : 'v1' , enabled : true } ,
8074 } ;
8175
8276 mockLdClient . variation . mockResolvedValue ( mockVariation ) ;
8377
84- const result = await client . modelConfig ( key , testContext , defaultValue ) ;
78+ const result = await client . config ( key , testContext , defaultValue ) ;
8579
86- expect ( result . prompt ?. [ 0 ] . content ) . toBe ( 'User key: test-user' ) ;
80+ expect ( result . messages ?. [ 0 ] . content ) . toBe ( 'User key: test-user' ) ;
8781} ) ;
8882
8983it ( 'handles missing metadata in variation' , async ( ) => {
9084 const client = new LDAIClientImpl ( mockLdClient ) ;
9185 const key = 'test-flag' ;
9286 const defaultValue : LDAIDefaults = {
93- model : { modelId : 'test' , name : 'test-model' } ,
94- prompt : [ ] ,
87+ model : { id : 'test' , parameters : { name : 'test-model' } } ,
88+ messages : [ ] ,
9589 } ;
9690
9791 const mockVariation = {
98- model : { modelId : 'example-provider' , name : 'imagination' } ,
99- prompt : [ { role : 'system' , content : 'Hello' } ] ,
92+ model : { id : 'example-provider' , parameters : { name : 'imagination' } } ,
93+ messages : [ { role : 'system' , content : 'Hello' } ] ,
10094 } ;
10195
10296 mockLdClient . variation . mockResolvedValue ( mockVariation ) ;
10397
104- const result = await client . modelConfig ( key , testContext , defaultValue ) ;
98+ const result = await client . config ( key , testContext , defaultValue ) ;
10599
106100 expect ( result ) . toEqual ( {
107- model : { modelId : 'example-provider' , name : 'imagination' } ,
108- prompt : [ { role : 'system' , content : 'Hello' } ] ,
101+ model : { id : 'example-provider' , parameters : { name : 'imagination' } } ,
102+ messages : [ { role : 'system' , content : 'Hello' } ] ,
109103 tracker : expect . any ( Object ) ,
110104 enabled : false ,
111105 } ) ;
@@ -115,18 +109,20 @@ it('passes the default value to the underlying client', async () => {
115109 const client = new LDAIClientImpl ( mockLdClient ) ;
116110 const key = 'non-existent-flag' ;
117111 const defaultValue : LDAIDefaults = {
118- model : { modelId : 'default-model' , name : 'default' } ,
119- prompt : [ { role : 'system' , content : 'Default prompt' } ] ,
112+ model : { id : 'default-model' , parameters : { name : 'default' } } ,
113+ provider : { id : 'default-provider' } ,
114+ messages : [ { role : 'system' , content : 'Default messages' } ] ,
120115 enabled : true ,
121116 } ;
122117
123118 mockLdClient . variation . mockResolvedValue ( defaultValue ) ;
124119
125- const result = await client . modelConfig ( key , testContext , defaultValue ) ;
120+ const result = await client . config ( key , testContext , defaultValue ) ;
126121
127122 expect ( result ) . toEqual ( {
128123 model : defaultValue . model ,
129- prompt : defaultValue . prompt ,
124+ messages : defaultValue . messages ,
125+ provider : defaultValue . provider ,
130126 tracker : expect . any ( Object ) ,
131127 enabled : false ,
132128 } ) ;
0 commit comments