@@ -300,8 +300,9 @@ const batchPromises = <T>(array: T[], batchSize: number): T[][] => {
300
300
301
301
export const createLLMEvaluations = async (
302
302
paramsArray : CreateLLMEvaluationParams [ ]
303
- ) : Promise < void > => {
303
+ ) : Promise < string [ ] > => {
304
304
const roundCache : Record < string , RoundWithApplications > = { } ;
305
+ const failedProjects : string [ ] = [ ] ;
305
306
306
307
// Split the paramsArray into batches of 10
307
308
const batchedParams = batchPromises ( paramsArray , 10 ) ;
@@ -310,86 +311,95 @@ export const createLLMEvaluations = async (
310
311
try {
311
312
// Process each batch of promises concurrently
312
313
const evaluationPromises = batch . map ( async params => {
313
- const evaluationQuestions =
314
- params . questions === undefined || params . questions . length === 0
315
- ? await evaluationService . getQuestionsByChainAndAlloPoolId (
316
- params . chainId ,
317
- params . alloPoolId
318
- )
319
- : params . questions ;
320
-
321
- if ( evaluationQuestions === null || evaluationQuestions . length === 0 ) {
322
- logger . error (
323
- 'createLLMEvaluations:Failed to get evaluation questions'
324
- ) ;
325
- throw new Error ( 'Failed to get evaluation questions' ) ;
326
- }
327
-
328
- let roundMetadata = params . roundMetadata ;
329
- let applicationMetadata = params . applicationMetadata ;
330
-
331
- // Check if the round is already in cache
332
- if ( roundMetadata == null || applicationMetadata == null ) {
333
- let round : RoundWithApplications | null ;
334
-
335
- // If the round is cached, use it
336
- if ( roundCache [ params . alloPoolId ] != null ) {
337
- round = roundCache [ params . alloPoolId ] ;
338
- logger . debug (
339
- `Using cached round data for roundId: ${ params . alloPoolId } `
340
- ) ;
341
- } else {
342
- // Fetch the round and store it in the cache
343
- const [ error , fetchedRound ] = await catchError (
344
- indexerClient . getRoundWithApplications ( {
345
- chainId : params . chainId ,
346
- roundId : params . alloPoolId ,
347
- } )
314
+ try {
315
+ const evaluationQuestions =
316
+ params . questions === undefined || params . questions . length === 0
317
+ ? await evaluationService . getQuestionsByChainAndAlloPoolId (
318
+ params . chainId ,
319
+ params . alloPoolId
320
+ )
321
+ : params . questions ;
322
+
323
+ if (
324
+ evaluationQuestions === null ||
325
+ evaluationQuestions . length === 0
326
+ ) {
327
+ logger . error (
328
+ 'createLLMEvaluations:Failed to get evaluation questions'
348
329
) ;
330
+ throw new Error ( 'Failed to get evaluation questions' ) ;
331
+ }
349
332
350
- if ( error !== undefined || fetchedRound == null ) {
351
- logger . error ( 'Failed to fetch round with applications' ) ;
352
- throw new Error ( 'Failed to fetch round with applications' ) ;
333
+ let roundMetadata = params . roundMetadata ;
334
+ let applicationMetadata = params . applicationMetadata ;
335
+
336
+ // Check if the round is already in cache
337
+ if ( roundMetadata == null || applicationMetadata == null ) {
338
+ let round : RoundWithApplications | null ;
339
+
340
+ // If the round is cached, use it
341
+ if ( roundCache [ params . alloPoolId ] != null ) {
342
+ round = roundCache [ params . alloPoolId ] ;
343
+ logger . debug (
344
+ `Using cached round data for roundId: ${ params . alloPoolId } `
345
+ ) ;
346
+ } else {
347
+ // Fetch the round and store it in the cache
348
+ const [ error , fetchedRound ] = await catchError (
349
+ indexerClient . getRoundWithApplications ( {
350
+ chainId : params . chainId ,
351
+ roundId : params . alloPoolId ,
352
+ } )
353
+ ) ;
354
+
355
+ if ( error !== undefined || fetchedRound == null ) {
356
+ logger . error ( 'Failed to fetch round with applications' ) ;
357
+ throw new Error ( 'Failed to fetch round with applications' ) ;
358
+ }
359
+
360
+ round = fetchedRound ;
361
+ roundCache [ params . alloPoolId ] = round ;
362
+ logger . info (
363
+ `Fetched and cached round with ID: ${ round . id } , which includes ${ round . applications . length } applications`
364
+ ) ;
353
365
}
354
366
355
- round = fetchedRound ;
356
- roundCache [ params . alloPoolId ] = round ;
357
- logger . info (
358
- `Fetched and cached round with ID: ${ round . id } , which includes ${ round . applications . length } applications`
367
+ const application = round . applications . find (
368
+ app => app . id === params . alloApplicationId
359
369
) ;
370
+ if ( application == null ) {
371
+ logger . error (
372
+ `Application with ID: ${ params . alloApplicationId } not found in round`
373
+ ) ;
374
+ throw new NotFoundError (
375
+ `Application with ID: ${ params . alloApplicationId } not found in round`
376
+ ) ;
377
+ }
378
+
379
+ roundMetadata = round . roundMetadata ;
380
+ applicationMetadata = application . metadata ;
360
381
}
361
382
362
- const application = round . applications . find (
363
- app => app . id === params . alloApplicationId
383
+ const evaluation = await requestEvaluation (
384
+ roundMetadata ,
385
+ applicationMetadata ,
386
+ evaluationQuestions
364
387
) ;
365
- if ( application == null ) {
366
- logger . error (
367
- `Application with ID: ${ params . alloApplicationId } not found in round`
368
- ) ;
369
- throw new NotFoundError (
370
- `Application with ID: ${ params . alloApplicationId } not found in round`
371
- ) ;
372
- }
373
388
374
- roundMetadata = round . roundMetadata ;
375
- applicationMetadata = application . metadata ;
389
+ await createEvaluation ( {
390
+ chainId : params . chainId ,
391
+ alloPoolId : params . alloPoolId ,
392
+ alloApplicationId : params . alloApplicationId ,
393
+ cid : params . cid ,
394
+ evaluator : params . evaluator ,
395
+ summaryInput : evaluation ,
396
+ evaluatorType : EVALUATOR_TYPE . LLM_GPT3 ,
397
+ } ) ;
398
+ } catch ( error ) {
399
+ // If an error occurs, add the project ID to the failedProjects array
400
+ failedProjects . push ( params . alloApplicationId ) ;
401
+ throw error ;
376
402
}
377
-
378
- const evaluation = await requestEvaluation (
379
- roundMetadata ,
380
- applicationMetadata ,
381
- evaluationQuestions
382
- ) ;
383
-
384
- await createEvaluation ( {
385
- chainId : params . chainId ,
386
- alloPoolId : params . alloPoolId ,
387
- alloApplicationId : params . alloApplicationId ,
388
- cid : params . cid ,
389
- evaluator : params . evaluator ,
390
- summaryInput : evaluation ,
391
- evaluatorType : EVALUATOR_TYPE . LLM_GPT3 ,
392
- } ) ;
393
403
} ) ;
394
404
395
405
await Promise . all ( evaluationPromises ) ;
@@ -405,4 +415,6 @@ export const createLLMEvaluations = async (
405
415
continue ;
406
416
}
407
417
}
418
+
419
+ return failedProjects ;
408
420
} ;
0 commit comments