@@ -42,7 +42,7 @@ def client(td: TestData) -> LDClient:
42
42
43
43
def test_summary_starts_empty (client : LDClient ):
44
44
context = Context .create ("user-key" )
45
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 1 , context )
45
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 1 , "fakeModel" , "fakeProvider" , context )
46
46
47
47
assert tracker .get_summary ().duration is None
48
48
assert tracker .get_summary ().feedback is None
@@ -52,13 +52,13 @@ def test_summary_starts_empty(client: LDClient):
52
52
53
53
def test_tracks_duration (client : LDClient ):
54
54
context = Context .create ("user-key" )
55
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
55
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
56
56
tracker .track_duration (100 )
57
57
58
58
client .track .assert_called_with ( # type: ignore
59
59
"$ld:ai:duration:total" ,
60
60
context ,
61
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
61
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
62
62
100 ,
63
63
)
64
64
@@ -67,7 +67,7 @@ def test_tracks_duration(client: LDClient):
67
67
68
68
def test_tracks_duration_of (client : LDClient ):
69
69
context = Context .create ("user-key" )
70
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
70
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
71
71
tracker .track_duration_of (lambda : sleep (0.01 ))
72
72
73
73
calls = client .track .mock_calls # type: ignore
@@ -79,19 +79,21 @@ def test_tracks_duration_of(client: LDClient):
79
79
"variationKey" : "variation-key" ,
80
80
"configKey" : "config-key" ,
81
81
"version" : 3 ,
82
+ "modelName" : "fakeModel" ,
83
+ "providerName" : "fakeProvider" ,
82
84
}
83
85
assert calls [0 ].args [3 ] == pytest .approx (10 , rel = 10 )
84
86
85
87
86
88
def test_tracks_time_to_first_token (client : LDClient ):
87
89
context = Context .create ("user-key" )
88
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
90
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
89
91
tracker .track_time_to_first_token (100 )
90
92
91
93
client .track .assert_called_with ( # type: ignore
92
94
"$ld:ai:tokens:ttf" ,
93
95
context ,
94
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
96
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
95
97
100 ,
96
98
)
97
99
@@ -100,7 +102,7 @@ def test_tracks_time_to_first_token(client: LDClient):
100
102
101
103
def test_tracks_duration_of_with_exception (client : LDClient ):
102
104
context = Context .create ("user-key" )
103
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
105
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
104
106
105
107
def sleep_and_throw ():
106
108
sleep (0.01 )
@@ -121,13 +123,15 @@ def sleep_and_throw():
121
123
"variationKey" : "variation-key" ,
122
124
"configKey" : "config-key" ,
123
125
"version" : 3 ,
126
+ "modelName" : "fakeModel" ,
127
+ "providerName" : "fakeProvider" ,
124
128
}
125
129
assert calls [0 ].args [3 ] == pytest .approx (10 , rel = 10 )
126
130
127
131
128
132
def test_tracks_token_usage (client : LDClient ):
129
133
context = Context .create ("user-key" )
130
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
134
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
131
135
132
136
tokens = TokenUsage (300 , 200 , 100 )
133
137
tracker .track_tokens (tokens )
@@ -136,19 +140,19 @@ def test_tracks_token_usage(client: LDClient):
136
140
call (
137
141
"$ld:ai:tokens:total" ,
138
142
context ,
139
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
143
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
140
144
300 ,
141
145
),
142
146
call (
143
147
"$ld:ai:tokens:input" ,
144
148
context ,
145
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
149
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
146
150
200 ,
147
151
),
148
152
call (
149
153
"$ld:ai:tokens:output" ,
150
154
context ,
151
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
155
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
152
156
100 ,
153
157
),
154
158
]
@@ -160,7 +164,7 @@ def test_tracks_token_usage(client: LDClient):
160
164
161
165
def test_tracks_bedrock_metrics (client : LDClient ):
162
166
context = Context .create ("user-key" )
163
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
167
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
164
168
165
169
bedrock_result = {
166
170
"ResponseMetadata" : {"HTTPStatusCode" : 200 },
@@ -179,37 +183,37 @@ def test_tracks_bedrock_metrics(client: LDClient):
179
183
call (
180
184
"$ld:ai:generation" ,
181
185
context ,
182
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
186
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
183
187
1 ,
184
188
),
185
189
call (
186
190
"$ld:ai:generation:success" ,
187
191
context ,
188
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
192
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
189
193
1 ,
190
194
),
191
195
call (
192
196
"$ld:ai:duration:total" ,
193
197
context ,
194
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
198
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
195
199
50 ,
196
200
),
197
201
call (
198
202
"$ld:ai:tokens:total" ,
199
203
context ,
200
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
204
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
201
205
330 ,
202
206
),
203
207
call (
204
208
"$ld:ai:tokens:input" ,
205
209
context ,
206
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
210
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
207
211
220 ,
208
212
),
209
213
call (
210
214
"$ld:ai:tokens:output" ,
211
215
context ,
212
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
216
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
213
217
110 ,
214
218
),
215
219
]
@@ -223,7 +227,7 @@ def test_tracks_bedrock_metrics(client: LDClient):
223
227
224
228
def test_tracks_bedrock_metrics_with_error (client : LDClient ):
225
229
context = Context .create ("user-key" )
226
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
230
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
227
231
228
232
bedrock_result = {
229
233
"ResponseMetadata" : {"HTTPStatusCode" : 500 },
@@ -242,37 +246,37 @@ def test_tracks_bedrock_metrics_with_error(client: LDClient):
242
246
call (
243
247
"$ld:ai:generation" ,
244
248
context ,
245
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
249
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
246
250
1 ,
247
251
),
248
252
call (
249
253
"$ld:ai:generation:error" ,
250
254
context ,
251
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
255
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
252
256
1 ,
253
257
),
254
258
call (
255
259
"$ld:ai:duration:total" ,
256
260
context ,
257
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
261
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
258
262
50 ,
259
263
),
260
264
call (
261
265
"$ld:ai:tokens:total" ,
262
266
context ,
263
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
267
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
264
268
330 ,
265
269
),
266
270
call (
267
271
"$ld:ai:tokens:input" ,
268
272
context ,
269
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
273
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
270
274
220 ,
271
275
),
272
276
call (
273
277
"$ld:ai:tokens:output" ,
274
278
context ,
275
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
279
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
276
280
110 ,
277
281
),
278
282
]
@@ -286,7 +290,7 @@ def test_tracks_bedrock_metrics_with_error(client: LDClient):
286
290
287
291
def test_tracks_openai_metrics (client : LDClient ):
288
292
context = Context .create ("user-key" )
289
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
293
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
290
294
291
295
class Result :
292
296
def __init__ (self ):
@@ -306,31 +310,31 @@ def to_dict(self):
306
310
call (
307
311
"$ld:ai:generation" ,
308
312
context ,
309
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
313
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
310
314
1 ,
311
315
),
312
316
call (
313
317
"$ld:ai:generation:success" ,
314
318
context ,
315
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
319
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
316
320
1 ,
317
321
),
318
322
call (
319
323
"$ld:ai:tokens:total" ,
320
324
context ,
321
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
325
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
322
326
330 ,
323
327
),
324
328
call (
325
329
"$ld:ai:tokens:input" ,
326
330
context ,
327
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
331
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
328
332
220 ,
329
333
),
330
334
call (
331
335
"$ld:ai:tokens:output" ,
332
336
context ,
333
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
337
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
334
338
110 ,
335
339
),
336
340
]
@@ -342,7 +346,7 @@ def to_dict(self):
342
346
343
347
def test_tracks_openai_metrics_with_exception (client : LDClient ):
344
348
context = Context .create ("user-key" )
345
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
349
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
346
350
347
351
def raise_exception ():
348
352
raise ValueError ("Something went wrong" )
@@ -357,13 +361,13 @@ def raise_exception():
357
361
call (
358
362
"$ld:ai:generation" ,
359
363
context ,
360
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
364
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
361
365
1 ,
362
366
),
363
367
call (
364
368
"$ld:ai:generation:error" ,
365
369
context ,
366
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
370
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
367
371
1 ,
368
372
),
369
373
]
@@ -382,35 +386,35 @@ def raise_exception():
382
386
)
383
387
def test_tracks_feedback (client : LDClient , kind : FeedbackKind , label : str ):
384
388
context = Context .create ("user-key" )
385
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
389
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
386
390
387
391
tracker .track_feedback ({"kind" : kind })
388
392
389
393
client .track .assert_called_with ( # type: ignore
390
394
f"$ld:ai:feedback:user:{ label } " ,
391
395
context ,
392
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
396
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
393
397
1 ,
394
398
)
395
399
assert tracker .get_summary ().feedback == {"kind" : kind }
396
400
397
401
398
402
def test_tracks_success (client : LDClient ):
399
403
context = Context .create ("user-key" )
400
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
404
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
401
405
tracker .track_success ()
402
406
403
407
calls = [
404
408
call (
405
409
"$ld:ai:generation" ,
406
410
context ,
407
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
411
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
408
412
1 ,
409
413
),
410
414
call (
411
415
"$ld:ai:generation:success" ,
412
416
context ,
413
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
417
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
414
418
1 ,
415
419
),
416
420
]
@@ -422,20 +426,20 @@ def test_tracks_success(client: LDClient):
422
426
423
427
def test_tracks_error (client : LDClient ):
424
428
context = Context .create ("user-key" )
425
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
429
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
426
430
tracker .track_error ()
427
431
428
432
calls = [
429
433
call (
430
434
"$ld:ai:generation" ,
431
435
context ,
432
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
436
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
433
437
1 ,
434
438
),
435
439
call (
436
440
"$ld:ai:generation:error" ,
437
441
context ,
438
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
442
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
439
443
1 ,
440
444
),
441
445
]
@@ -447,33 +451,33 @@ def test_tracks_error(client: LDClient):
447
451
448
452
def test_error_overwrites_success (client : LDClient ):
449
453
context = Context .create ("user-key" )
450
- tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , context )
454
+ tracker = LDAIConfigTracker (client , "variation-key" , "config-key" , 3 , "fakeModel" , "fakeProvider" , context )
451
455
tracker .track_success ()
452
456
tracker .track_error ()
453
457
454
458
calls = [
455
459
call (
456
460
"$ld:ai:generation" ,
457
461
context ,
458
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
462
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
459
463
1 ,
460
464
),
461
465
call (
462
466
"$ld:ai:generation:success" ,
463
467
context ,
464
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
468
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
465
469
1 ,
466
470
),
467
471
call (
468
472
"$ld:ai:generation" ,
469
473
context ,
470
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
474
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
471
475
1 ,
472
476
),
473
477
call (
474
478
"$ld:ai:generation:error" ,
475
479
context ,
476
- {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 },
480
+ {"variationKey" : "variation-key" , "configKey" : "config-key" , "version" : 3 , "modelName" : "fakeModel" , "providerName" : "fakeProvider" },
477
481
1 ,
478
482
),
479
483
]
0 commit comments