@@ -35,10 +35,20 @@ type Modelfile interface {
35
35
GetConfigs () []string
36
36
37
37
// GetModels returns the args of the model command in the modelfile,
38
- // and deduplicates the args. The order of the args is the same as The
38
+ // and deduplicates the args. The order of the args is the same as the
39
39
// order in the modelfile.
40
40
GetModels () []string
41
41
42
+ // GetCode returns the args of the code command in the modelfile,
43
+ // and deduplicates the args. The order of the args is the same as the
44
+ // order in the modelfile.
45
+ GetCodes () []string
46
+
47
+ // GetDatasets returns the args of the dataset command in the modelfile,
48
+ // and deduplicates the args. The order of the args is the same as the
49
+ // order in the modelfile.
50
+ GetDatasets () []string
51
+
42
52
// GetName returns the value of the name command in the modelfile.
43
53
GetName () string
44
54
@@ -65,6 +75,8 @@ type Modelfile interface {
65
75
type modelfile struct {
66
76
config * hashset.Set
67
77
model * hashset.Set
78
+ code * hashset.Set
79
+ dataset * hashset.Set
68
80
name string
69
81
arch string
70
82
family string
@@ -78,8 +90,10 @@ type modelfile struct {
78
90
// It parses the modelfile and returns the modelfile interface.
79
91
func NewModelfile (path string ) (Modelfile , error ) {
80
92
mf := & modelfile {
81
- config : hashset .New (),
82
- model : hashset .New (),
93
+ config : hashset .New (),
94
+ model : hashset .New (),
95
+ code : hashset .New (),
96
+ dataset : hashset .New (),
83
97
}
84
98
if err := mf .parseFile (path ); err != nil {
85
99
return nil , err
@@ -107,6 +121,10 @@ func (mf *modelfile) parseFile(path string) error {
107
121
mf .config .Add (child .GetNext ().GetValue ())
108
122
case modefilecommand .MODEL :
109
123
mf .model .Add (child .GetNext ().GetValue ())
124
+ case modefilecommand .CODE :
125
+ mf .code .Add (child .GetNext ().GetValue ())
126
+ case modefilecommand .DATASET :
127
+ mf .dataset .Add (child .GetNext ().GetValue ())
110
128
case modefilecommand .NAME :
111
129
if mf .name != "" {
112
130
return fmt .Errorf ("duplicate name command on line %d" , child .GetStartLine ())
@@ -184,6 +202,40 @@ func (mf *modelfile) GetModels() []string {
184
202
return models
185
203
}
186
204
205
+ // GetCode returns the args of the code command in the modelfile,
206
+ // and deduplicates the args. The order of the args is the same as the
207
+ // order in the modelfile.
208
+ func (mf * modelfile ) GetCodes () []string {
209
+ var codes []string
210
+ for _ , rawCode := range mf .code .Values () {
211
+ code , ok := rawCode .(string )
212
+ if ! ok {
213
+ continue
214
+ }
215
+
216
+ codes = append (codes , code )
217
+ }
218
+
219
+ return codes
220
+ }
221
+
222
+ // GetDatasets returns the args of the dataset command in the modelfile,
223
+ // and deduplicates the args. The order of the args is the same as the
224
+ // order in the modelfile.
225
+ func (mf * modelfile ) GetDatasets () []string {
226
+ var datasets []string
227
+ for _ , rawDataset := range mf .dataset .Values () {
228
+ dataset , ok := rawDataset .(string )
229
+ if ! ok {
230
+ continue
231
+ }
232
+
233
+ datasets = append (datasets , dataset )
234
+ }
235
+
236
+ return datasets
237
+ }
238
+
187
239
// GetName returns the value of the name command in the modelfile.
188
240
func (mf * modelfile ) GetName () string {
189
241
return mf .name
0 commit comments