@@ -43,6 +43,9 @@ const modelMappingKeys = [
43
43
'review' ,
44
44
'review_item' ,
45
45
'review_item_comment' ,
46
+ 'llm_provider' ,
47
+ 'llm_model' ,
48
+ 'ai_workflow'
46
49
] ;
47
50
const subModelMappingKeys = {
48
51
review_item_comment : [ 'reviewItemComment' , 'appeal' , 'appealResponse' ] ,
@@ -102,6 +105,9 @@ const reviewItemCommentAppealResponseIdMap = readIdMap(
102
105
) ;
103
106
const uploadIdMap = readIdMap ( 'uploadIdMap' ) ;
104
107
const submissionIdMap = readIdMap ( 'submissionIdMap' ) ;
108
+ const llmProviderIdMap = readIdMap ( 'llmProviderIdMap' ) ;
109
+ const llmModelIdMap = readIdMap ( 'llmModelIdMap' ) ;
110
+ const aiWorkflowIdMap = readIdMap ( 'aiWorkflowIdMap' ) ;
105
111
106
112
// read resourceSubmissionSet
107
113
const rsSetFile = '.tmp/resourceSubmissionSet.json' ;
@@ -808,7 +814,6 @@ async function processType(type: string, subtype?: string) {
808
814
case 'scorecard' : {
809
815
console . log ( `[${ type } ][${ file } ] Processing file` ) ;
810
816
const processedData = jsonData [ key ]
811
- . filter ( ( sc ) => ! scorecardIdMap . has ( sc . scorecard_id ) )
812
817
. map ( ( sc ) => {
813
818
const id = nanoid ( 14 ) ;
814
819
scorecardIdMap . set ( sc . scorecard_id , id ) ;
@@ -1342,6 +1347,177 @@ async function processType(type: string, subtype?: string) {
1342
1347
}
1343
1348
break ;
1344
1349
}
1350
+ case 'llm_provider' : {
1351
+ console . log ( `[${ type } ][${ subtype } ][${ file } ] Processing file` ) ;
1352
+ const idToLegacyIdMap = { } ;
1353
+ const processedData = jsonData [ key ]
1354
+ . map ( ( c ) => {
1355
+ const id = nanoid ( 14 ) ;
1356
+ llmProviderIdMap . set (
1357
+ c . llm_provider_id ,
1358
+ id ,
1359
+ ) ;
1360
+ idToLegacyIdMap [ id ] = c . llm_provider_id ;
1361
+ return {
1362
+ id : id ,
1363
+ name : c . name ,
1364
+ createdAt : new Date ( c . create_date ) ,
1365
+ createdBy : c . create_user ,
1366
+ } ;
1367
+ } ) ;
1368
+
1369
+ const totalBatches = Math . ceil ( processedData . length / batchSize ) ;
1370
+ for ( let i = 0 ; i < processedData . length ; i += batchSize ) {
1371
+ const batchIndex = i / batchSize + 1 ;
1372
+ console . log (
1373
+ `[${ type } ][${ subtype } ][${ file } ] Processing batch ${ batchIndex } /${ totalBatches } ` ,
1374
+ ) ;
1375
+ const batch = processedData . slice ( i , i + batchSize ) ;
1376
+ await prisma . llmProvider
1377
+ . createMany ( {
1378
+ data : batch ,
1379
+ } )
1380
+ . catch ( async ( ) => {
1381
+ console . error (
1382
+ `[${ type } ][${ subtype } ][${ file } ] An error occurred, retrying individually` ,
1383
+ ) ;
1384
+ for ( const item of batch ) {
1385
+ await prisma . llmProvider
1386
+ . create ( {
1387
+ data : item ,
1388
+ } )
1389
+ . catch ( ( err ) => {
1390
+ llmProviderIdMap . delete (
1391
+ idToLegacyIdMap [ item . id ] ,
1392
+ ) ;
1393
+ console . error (
1394
+ `[${ type } ][${ subtype } ][${ file } ] Error code: ${ err . code } , LegacyId: ${ idToLegacyIdMap [ item . id ] } ` ,
1395
+ ) ;
1396
+ } ) ;
1397
+ }
1398
+ } ) ;
1399
+ }
1400
+ break ;
1401
+ }
1402
+ case 'llm_model' : {
1403
+ console . log ( `[${ type } ][${ subtype } ][${ file } ] Processing file` ) ;
1404
+ const idToLegacyIdMap = { } ;
1405
+ const processedData = jsonData [ key ]
1406
+ . map ( ( c ) => {
1407
+ const id = nanoid ( 14 ) ;
1408
+ llmModelIdMap . set (
1409
+ c . llm_model_id ,
1410
+ id ,
1411
+ ) ;
1412
+ idToLegacyIdMap [ id ] = c . llm_model_id ;
1413
+ console . log ( llmProviderIdMap . get ( c . provider_id ) , 'c.provider_id' )
1414
+ return {
1415
+ id : id ,
1416
+ providerId : llmProviderIdMap . get ( c . provider_id ) ,
1417
+ name : c . name ,
1418
+ description : c . description ,
1419
+ icon : c . icon ,
1420
+ url : c . url ,
1421
+ createdAt : new Date ( c . create_date ) ,
1422
+ createdBy : c . create_user ,
1423
+ } ;
1424
+ } ) ;
1425
+
1426
+ console . log ( llmProviderIdMap , processedData , 'processedData' )
1427
+
1428
+ const totalBatches = Math . ceil ( processedData . length / batchSize ) ;
1429
+ for ( let i = 0 ; i < processedData . length ; i += batchSize ) {
1430
+ const batchIndex = i / batchSize + 1 ;
1431
+ console . log (
1432
+ `[${ type } ][${ subtype } ][${ file } ] Processing batch ${ batchIndex } /${ totalBatches } ` ,
1433
+ ) ;
1434
+ const batch = processedData . slice ( i , i + batchSize ) ;
1435
+ await prisma . llmModel
1436
+ . createMany ( {
1437
+ data : batch ,
1438
+ } )
1439
+ . catch ( async ( ) => {
1440
+ console . error (
1441
+ `[${ type } ][${ subtype } ][${ file } ] An error occurred, retrying individually` ,
1442
+ ) ;
1443
+ for ( const item of batch ) {
1444
+ await prisma . llmModel
1445
+ . create ( {
1446
+ data : item ,
1447
+ } )
1448
+ . catch ( ( err ) => {
1449
+ llmModelIdMap . delete (
1450
+ idToLegacyIdMap [ item . id ] ,
1451
+ ) ;
1452
+ console . error (
1453
+ `[${ type } ][${ subtype } ][${ file } ] Error code: ${ err . code } , LegacyId: ${ idToLegacyIdMap [ item . id ] } ` ,
1454
+ ) ;
1455
+ } ) ;
1456
+ }
1457
+ } ) ;
1458
+ }
1459
+ break ;
1460
+ }
1461
+ case 'ai_workflow' : {
1462
+ console . log ( `[${ type } ][${ subtype } ][${ file } ] Processing file` ) ;
1463
+ const idToLegacyIdMap = { } ;
1464
+ const processedData = jsonData [ key ]
1465
+ . map ( ( c ) => {
1466
+ const id = nanoid ( 14 ) ;
1467
+ aiWorkflowIdMap . set (
1468
+ c . ai_workflow_id ,
1469
+ id ,
1470
+ ) ;
1471
+ idToLegacyIdMap [ id ] = c . ai_workflow_id ;
1472
+ return {
1473
+ id : id ,
1474
+ llmId : llmModelIdMap . get ( c . llm_id ) ,
1475
+ name : c . name ,
1476
+ description : c . description ,
1477
+ defUrl : c . def_url ,
1478
+ gitId : c . git_id ,
1479
+ gitOwner : c . git_owner ,
1480
+ scorecardId : scorecardIdMap . get ( c . scorecard_id ) ,
1481
+ createdAt : new Date ( c . create_date ) ,
1482
+ createdBy : c . create_user ,
1483
+ updatedAt : new Date ( c . modify_date ) ,
1484
+ updatedBy : c . modify_user ,
1485
+ } ;
1486
+ } ) ;
1487
+
1488
+ const totalBatches = Math . ceil ( processedData . length / batchSize ) ;
1489
+ for ( let i = 0 ; i < processedData . length ; i += batchSize ) {
1490
+ const batchIndex = i / batchSize + 1 ;
1491
+ console . log (
1492
+ `[${ type } ][${ subtype } ][${ file } ] Processing batch ${ batchIndex } /${ totalBatches } ` ,
1493
+ ) ;
1494
+ const batch = processedData . slice ( i , i + batchSize ) ;
1495
+ await prisma . aiWorkflow
1496
+ . createMany ( {
1497
+ data : batch ,
1498
+ } )
1499
+ . catch ( async ( ) => {
1500
+ console . error (
1501
+ `[${ type } ][${ subtype } ][${ file } ] An error occurred, retrying individually` ,
1502
+ ) ;
1503
+ for ( const item of batch ) {
1504
+ await prisma . aiWorkflow
1505
+ . create ( {
1506
+ data : item ,
1507
+ } )
1508
+ . catch ( ( err ) => {
1509
+ aiWorkflowIdMap . delete (
1510
+ idToLegacyIdMap [ item . id ] ,
1511
+ ) ;
1512
+ console . error (
1513
+ `[${ type } ][${ subtype } ][${ file } ] Error code: ${ err . code } , LegacyId: ${ idToLegacyIdMap [ item . id ] } ` ,
1514
+ ) ;
1515
+ } ) ;
1516
+ }
1517
+ } ) ;
1518
+ }
1519
+ break ;
1520
+ }
1345
1521
default :
1346
1522
console . warn ( `No processor defined for type: ${ type } ` ) ;
1347
1523
return ;
@@ -1509,6 +1685,9 @@ migrate()
1509
1685
} ,
1510
1686
{ key : 'uploadIdMap' , value : uploadIdMap } ,
1511
1687
{ key : 'submissionIdMap' , value : submissionIdMap } ,
1688
+ { key : 'llmProviderIdMap' , value : llmProviderIdMap } ,
1689
+ { key : 'llmModelIdMap' , value : llmModelIdMap } ,
1690
+ { key : 'aiWorkflowIdMap' , value : aiWorkflowIdMap }
1512
1691
] . forEach ( ( f ) => {
1513
1692
if ( ! fs . existsSync ( '.tmp' ) ) {
1514
1693
fs . mkdirSync ( '.tmp' ) ;
0 commit comments