@@ -1201,4 +1201,61 @@ describe("Token Cost Calculation", () => {
1201
1201
expect ( generation . usage_details . output ) . toBe ( generationUsage1 . usage . output ) ;
1202
1202
expect ( generation . usage_details . total ) . toBe ( generationUsage1 . usage . total ) ;
1203
1203
} ) ;
1204
+
1205
+ it ( "should skip tokenization and cost calculation if generation status is ERROR" , async ( ) => {
1206
+ const generationUsage1 = {
1207
+ model : modelName ,
1208
+ input : "hello world" ,
1209
+ output : "hey whassup" ,
1210
+ usage : null ,
1211
+ level : "ERROR" ,
1212
+ } ;
1213
+
1214
+ const events = [
1215
+ {
1216
+ id : uuidv4 ( ) ,
1217
+ type : "generation-create" ,
1218
+ timestamp : new Date ( ) . toISOString ( ) ,
1219
+ body : {
1220
+ id : generationId ,
1221
+ startTime : new Date ( ) . toISOString ( ) ,
1222
+ ...generationUsage1 ,
1223
+ } ,
1224
+ } ,
1225
+ ] ;
1226
+
1227
+ await ( mockIngestionService as any ) . processObservationEventList ( {
1228
+ projectId,
1229
+ entityId : generationId ,
1230
+ createdAtTimestamp : new Date ( ) ,
1231
+ observationEventList : events ,
1232
+ } ) ;
1233
+
1234
+ expect ( mockAddToClickhouseWriter ) . toHaveBeenCalled ( ) ;
1235
+ const args = mockAddToClickhouseWriter . mock . calls [ 0 ] ;
1236
+ const tableName = args [ 0 ] ;
1237
+ const generation = args [ 1 ] ;
1238
+
1239
+ expect ( tableName ) . toBe ( "observations" ) ;
1240
+ expect ( generation ) . toBeDefined ( ) ;
1241
+ expect ( generation . type ) . toBe ( "GENERATION" ) ;
1242
+ expect ( generation . level ) . toBe ( "ERROR" ) ;
1243
+
1244
+ // Model name should be matched
1245
+ expect ( generation . internal_model_id ) . toBe ( tokenModelData . id ) ;
1246
+
1247
+ // No user provided cost
1248
+ expect ( generation . provided_cost_details . input ) . toBeUndefined ( ) ;
1249
+ expect ( generation . provided_cost_details . output ) . toBeUndefined ( ) ;
1250
+ expect ( generation . provided_cost_details . total ) . toBeUndefined ( ) ;
1251
+
1252
+ // No calculated cost
1253
+ expect ( generation . cost_details . input ) . toBeUndefined ( ) ;
1254
+ expect ( generation . cost_details . output ) . toBeUndefined ( ) ;
1255
+ expect ( generation . cost_details . total ) . toBeUndefined ( ) ;
1256
+
1257
+ expect ( generation . usage_details . input ) . toBeUndefined ( ) ;
1258
+ expect ( generation . usage_details . output ) . toBeUndefined ( ) ;
1259
+ expect ( generation . usage_details . total ) . toBeUndefined ( ) ;
1260
+ } ) ;
1204
1261
} ) ;
0 commit comments