@@ -18,15 +18,23 @@ type DatasetElement struct {
1818 BinaryContents []byte `json:"binaryContents"`
1919}
2020
21+ type DatasetMeta struct {
22+ ID string `json:"id"`
23+ Name string `json:"name"`
24+ Description string `json:"description"`
25+ }
26+
2127type datasetRequest struct {
2228 Input string `json:"input"`
2329 DatasetTool string `json:"datasetTool"`
2430 Env []string `json:"env"`
2531}
2632
2733type addDatasetElementsArgs struct {
28- DatasetID string `json:"datasetID"`
29- Elements []DatasetElement `json:"elements"`
34+ DatasetID string `json:"datasetID"`
35+ Name string `json:"name"`
36+ Description string `json:"description"`
37+ Elements []DatasetElement `json:"elements"`
3038}
3139
3240type listDatasetElementArgs struct {
@@ -38,7 +46,7 @@ type getDatasetElementArgs struct {
3846 Element string `json:"name"`
3947}
4048
41- func (g * GPTScript ) ListDatasets (ctx context.Context ) ([]string , error ) {
49+ func (g * GPTScript ) ListDatasets (ctx context.Context ) ([]DatasetMeta , error ) {
4250 out , err := g .runBasicCommand (ctx , "datasets" , datasetRequest {
4351 Input : "{}" ,
4452 DatasetTool : g .globalOpts .DatasetTool ,
@@ -48,22 +56,36 @@ func (g *GPTScript) ListDatasets(ctx context.Context) ([]string, error) {
4856 return nil , err
4957 }
5058
51- var datasets []string
59+ var datasets []DatasetMeta
5260 if err = json .Unmarshal ([]byte (out ), & datasets ); err != nil {
5361 return nil , err
5462 }
5563 return datasets , nil
5664}
5765
58- func ( g * GPTScript ) CreateDatasetWithElements ( ctx context. Context , elements [] DatasetElement ) ( string , error ) {
59- return g . AddDatasetElements ( ctx , "" , elements )
66+ type DatasetOptions struct {
67+ Name , Description string
6068}
6169
62- func (g * GPTScript ) AddDatasetElements (ctx context.Context , datasetID string , elements []DatasetElement ) (string , error ) {
70+ func (g * GPTScript ) CreateDatasetWithElements (ctx context.Context , elements []DatasetElement , options ... DatasetOptions ) (string , error ) {
71+ return g .AddDatasetElements (ctx , "" , elements , options ... )
72+ }
73+
74+ func (g * GPTScript ) AddDatasetElements (ctx context.Context , datasetID string , elements []DatasetElement , options ... DatasetOptions ) (string , error ) {
6375 args := addDatasetElementsArgs {
6476 DatasetID : datasetID ,
6577 Elements : elements ,
6678 }
79+
80+ for _ , opt := range options {
81+ if opt .Name != "" {
82+ args .Name = opt .Name
83+ }
84+ if opt .Description != "" {
85+ args .Description = opt .Description
86+ }
87+ }
88+
6789 argsJSON , err := json .Marshal (args )
6890 if err != nil {
6991 return "" , fmt .Errorf ("failed to marshal element args: %w" , err )
0 commit comments