@@ -12,7 +12,7 @@ export interface GlobalOpts {
12
12
BaseURL ?: string
13
13
DefaultModel ?: string
14
14
DefaultModelProvider ?: string
15
- DatasetToolRepo ?: string
15
+ DatasetTool ?: string
16
16
WorkspaceTool ?: string
17
17
Env ?: string [ ]
18
18
}
@@ -386,106 +386,61 @@ export class GPTScript {
386
386
} )
387
387
}
388
388
389
- // Dataset methods
390
-
391
- async listDatasets ( workspaceID : string ) : Promise < Array < DatasetMeta > > {
392
- if ( workspaceID == "" ) {
393
- workspaceID = process . env . GPTSCRIPT_WORKSPACE_ID ?? ""
394
- }
395
-
389
+ // returns an array of dataset IDs
390
+ async listDatasets ( ) : Promise < Array < string > > {
396
391
const result = await this . runBasicCommand ( "datasets" , {
397
- workspaceID : workspaceID ,
398
- datasetToolRepo : this . opts . DatasetToolRepo ?? "" ,
399
- env : this . opts . Env
400
- } )
401
- return JSON . parse ( result ) as Array < DatasetMeta >
402
- }
403
-
404
- async createDataset ( workspaceID : string , name : string , description : string ) : Promise < Dataset > {
405
- if ( workspaceID == "" ) {
406
- workspaceID = process . env . GPTSCRIPT_WORKSPACE_ID ?? ""
407
- }
408
-
409
- const result = await this . runBasicCommand ( "datasets/create" , {
410
- input : JSON . stringify ( { datasetName : name , datasetDescription : description } ) ,
411
- workspaceID : workspaceID ,
412
- datasetToolRepo : this . opts . DatasetToolRepo ?? "" ,
392
+ input : JSON . stringify ( { "workspaceID" : process . env . GPTSCRIPT_WORKSPACE_ID } ) ,
393
+ datasetTool : this . opts . DatasetTool ?? "" ,
413
394
env : this . opts . Env
414
395
} )
415
- return JSON . parse ( result ) as Dataset
396
+ return JSON . parse ( result ) as Array < string >
416
397
}
417
398
418
- async addDatasetElement ( workspaceID : string , datasetID : string , elementName : string , elementDescription : string , elementContent : ArrayBuffer ) : Promise < DatasetElementMeta > {
419
- if ( workspaceID == "" ) {
420
- workspaceID = process . env . GPTSCRIPT_WORKSPACE_ID ?? ""
421
- }
422
-
423
- const result = await this . runBasicCommand ( "datasets/add-element" , {
424
- input : JSON . stringify ( {
425
- datasetID,
426
- elementName : elementName ,
427
- elementDescription : elementDescription ,
428
- elementContent : Buffer . from ( elementContent ) . toString ( "base64" )
429
- } ) ,
430
- workspaceID : workspaceID ,
431
- datasetToolRepo : this . opts . DatasetToolRepo ?? "" ,
432
- env : this . opts . Env
433
- } )
434
- return JSON . parse ( result ) as DatasetElementMeta
435
- }
436
-
437
- async addDatasetElements ( workspaceID : string , datasetID : string , elements : Array < DatasetElement > ) {
438
- if ( workspaceID === "" ) {
439
- workspaceID = process . env . GPTSCRIPT_WORKSPACE_ID ?? ""
440
- }
441
-
399
+ async addDatasetElements ( elements : Array < DatasetElement > , datasetID ?: string ) {
442
400
const serializableElements = elements . map ( e => {
443
401
return {
444
402
name : e . name ,
445
403
description : e . description ,
446
- contents : Buffer . from ( e . contents ) . toString ( "base64" )
404
+ contents : e . contents ,
405
+ binaryContents : Buffer . from ( e . binaryContents ?? Buffer . from ( "" ) ) . toString ( "base64" )
447
406
}
448
407
} )
449
408
450
409
return await this . runBasicCommand ( "datasets/add-elements" , {
451
- input : JSON . stringify ( { datasetID, elements : serializableElements } ) ,
452
- workspaceID : workspaceID ,
453
- datasetToolRepo : this . opts . DatasetToolRepo ?? "" ,
410
+ input : JSON . stringify ( {
411
+ workspaceID : process . env . GPTSCRIPT_WORKSPACE_ID ,
412
+ datasetID : datasetID ?? "" ,
413
+ elements : serializableElements
414
+ } ) ,
415
+ datasetTool : this . opts . DatasetTool ?? "" ,
454
416
env : this . opts . Env ,
455
417
} )
456
418
}
457
419
458
- async listDatasetElements ( workspaceID : string , datasetID : string ) : Promise < Array < DatasetElementMeta > > {
459
- if ( workspaceID == "" ) {
460
- workspaceID = process . env . GPTSCRIPT_WORKSPACE_ID ?? ""
461
- }
462
-
420
+ async listDatasetElements ( datasetID : string ) : Promise < Array < DatasetElementMeta > > {
463
421
const result = await this . runBasicCommand ( "datasets/list-elements" , {
464
- input : JSON . stringify ( { datasetID} ) ,
465
- workspaceID : workspaceID ,
466
- datasetToolRepo : this . opts . DatasetToolRepo ?? "" ,
422
+ input : JSON . stringify ( { workspaceID : process . env . GPTSCRIPT_WORKSPACE_ID , datasetID} ) ,
423
+ datasetTool : this . opts . DatasetTool ?? "" ,
467
424
env : this . opts . Env
468
425
} )
469
426
return JSON . parse ( result ) as Array < DatasetElementMeta >
470
427
}
471
428
472
- async getDatasetElement ( workspaceID : string , datasetID : string , elementName : string ) : Promise < DatasetElement > {
473
- if ( workspaceID == "" ) {
474
- workspaceID = process . env . GPTSCRIPT_WORKSPACE_ID ?? ""
475
- }
476
-
429
+ async getDatasetElement ( datasetID : string , elementName : string ) : Promise < DatasetElement > {
477
430
const result = await this . runBasicCommand ( "datasets/get-element" , {
478
- input : JSON . stringify ( { datasetID, element : elementName } ) ,
479
- workspaceID : workspaceID ,
480
- datasetToolRepo : this . opts . DatasetToolRepo ?? "" ,
431
+ input : JSON . stringify ( { workspaceID : process . env . GPTSCRIPT_WORKSPACE_ID , datasetID, name : elementName } ) ,
432
+ datasetTool : this . opts . DatasetTool ?? "" ,
481
433
env : this . opts . Env
482
434
} )
483
435
436
+ console . log ( result )
437
+
484
438
const element = JSON . parse ( result )
485
439
return {
486
440
name : element . name ,
487
441
description : element . description ,
488
- contents : Buffer . from ( element . contents , "base64" )
442
+ contents : element . contents ,
443
+ binaryContents : Buffer . from ( element . binaryContents , "base64" )
489
444
}
490
445
}
491
446
@@ -1312,8 +1267,6 @@ function jsonToCredential(cred: string): Credential {
1312
1267
}
1313
1268
}
1314
1269
1315
- // Dataset types
1316
-
1317
1270
export interface DatasetElementMeta {
1318
1271
name : string
1319
1272
description : string
@@ -1322,18 +1275,6 @@ export interface DatasetElementMeta {
1322
1275
export interface DatasetElement {
1323
1276
name : string
1324
1277
description : string
1325
- contents : ArrayBuffer
1326
- }
1327
-
1328
- export interface DatasetMeta {
1329
- id : string
1330
- name : string
1331
- description : string
1332
- }
1333
-
1334
- export interface Dataset {
1335
- id : string
1336
- name : string
1337
- description : string
1338
- elements : Record < string , DatasetElementMeta >
1278
+ contents ?: string
1279
+ binaryContents ?: ArrayBuffer
1339
1280
}
0 commit comments