@@ -18,15 +18,23 @@ type DatasetElement struct {
18
18
BinaryContents []byte `json:"binaryContents"`
19
19
}
20
20
21
+ type DatasetMeta struct {
22
+ ID string `json:"id"`
23
+ Name string `json:"name"`
24
+ Description string `json:"description"`
25
+ }
26
+
21
27
type datasetRequest struct {
22
28
Input string `json:"input"`
23
29
DatasetTool string `json:"datasetTool"`
24
30
Env []string `json:"env"`
25
31
}
26
32
27
33
type 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"`
30
38
}
31
39
32
40
type listDatasetElementArgs struct {
@@ -38,7 +46,7 @@ type getDatasetElementArgs struct {
38
46
Element string `json:"name"`
39
47
}
40
48
41
- func (g * GPTScript ) ListDatasets (ctx context.Context ) ([]string , error ) {
49
+ func (g * GPTScript ) ListDatasets (ctx context.Context ) ([]DatasetMeta , error ) {
42
50
out , err := g .runBasicCommand (ctx , "datasets" , datasetRequest {
43
51
Input : "{}" ,
44
52
DatasetTool : g .globalOpts .DatasetTool ,
@@ -48,22 +56,36 @@ func (g *GPTScript) ListDatasets(ctx context.Context) ([]string, error) {
48
56
return nil , err
49
57
}
50
58
51
- var datasets []string
59
+ var datasets []DatasetMeta
52
60
if err = json .Unmarshal ([]byte (out ), & datasets ); err != nil {
53
61
return nil , err
54
62
}
55
63
return datasets , nil
56
64
}
57
65
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
60
68
}
61
69
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 ) {
63
75
args := addDatasetElementsArgs {
64
76
DatasetID : datasetID ,
65
77
Elements : elements ,
66
78
}
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
+
67
89
argsJSON , err := json .Marshal (args )
68
90
if err != nil {
69
91
return "" , fmt .Errorf ("failed to marshal element args: %w" , err )
0 commit comments