@@ -35,10 +35,20 @@ type Modelfile interface {
3535 GetConfigs () []string
3636
3737 // 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
3939 // order in the modelfile.
4040 GetModels () []string
4141
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+
4252 // GetName returns the value of the name command in the modelfile.
4353 GetName () string
4454
@@ -65,6 +75,8 @@ type Modelfile interface {
6575type modelfile struct {
6676 config * hashset.Set
6777 model * hashset.Set
78+ code * hashset.Set
79+ dataset * hashset.Set
6880 name string
6981 arch string
7082 family string
@@ -78,8 +90,10 @@ type modelfile struct {
7890// It parses the modelfile and returns the modelfile interface.
7991func NewModelfile (path string ) (Modelfile , error ) {
8092 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 (),
8397 }
8498 if err := mf .parseFile (path ); err != nil {
8599 return nil , err
@@ -107,6 +121,10 @@ func (mf *modelfile) parseFile(path string) error {
107121 mf .config .Add (child .GetNext ().GetValue ())
108122 case modefilecommand .MODEL :
109123 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 ())
110128 case modefilecommand .NAME :
111129 if mf .name != "" {
112130 return fmt .Errorf ("duplicate name command on line %d" , child .GetStartLine ())
@@ -184,6 +202,40 @@ func (mf *modelfile) GetModels() []string {
184202 return models
185203}
186204
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+
187239// GetName returns the value of the name command in the modelfile.
188240func (mf * modelfile ) GetName () string {
189241 return mf .name
0 commit comments