@@ -24,6 +24,7 @@ import (
2424 "os"
2525 "os/exec"
2626 "slices"
27+ "strconv"
2728 "strings"
2829
2930 "github.com/compose-spec/compose-go/v2/types"
@@ -67,24 +68,28 @@ func (s *composeService) ensureModels(ctx context.Context, project *types.Projec
6768 if err != nil {
6869 return fmt .Errorf ("error unmarshalling available models: %w" , err )
6970 }
71+ var availableModels []string
72+ for _ , model := range models {
73+ availableModels = append (availableModels , model .Tags ... )
74+ }
7075
7176 eg , gctx := errgroup .WithContext (ctx )
7277 eg .Go (func () error {
7378 return s .setModelEndpointVariable (gctx , dockerModel , project )
7479 })
7580
76- MODELS:
7781 for name , config := range project .Models {
78- for _ , model := range models {
79- if slices .Contains (model .Tags , config .Model ) {
80- continue MODELS
81- }
82- }
8382 if config .Name == "" {
8483 config .Name = name
8584 }
8685 eg .Go (func () error {
87- return s .pullModel (gctx , dockerModel , config , quietPull )
86+ if ! slices .Contains (availableModels , config .Model ) {
87+ err = s .pullModel (gctx , dockerModel , config , quietPull )
88+ if err != nil {
89+ return err
90+ }
91+ }
92+ return s .configureModel (gctx , dockerModel , config )
8893 })
8994 }
9095 return eg .Wait ()
@@ -140,6 +145,22 @@ func (s *composeService) pullModel(ctx context.Context, dockerModel *manager.Plu
140145 return err
141146}
142147
148+ func (s * composeService ) configureModel (ctx context.Context , dockerModel * manager.Plugin , config types.ModelConfig ) error {
149+ // configure [--context-size=<n>] MODEL [-- <runtime-flags...>]
150+ args := []string {"configure" }
151+ if config .ContextSize > 0 {
152+ args = append (args , "--context-size" , strconv .Itoa (config .ContextSize ))
153+ }
154+ args = append (args , config .Model )
155+ if len (config .RuntimeFlags ) != 0 {
156+ args = append (args , "--" )
157+ args = append (args , config .RuntimeFlags ... )
158+ }
159+ cmd := exec .CommandContext (ctx , dockerModel .Path , args ... )
160+ s .setupChildProcess (ctx , cmd )
161+ return cmd .Run ()
162+ }
163+
143164func (s * composeService ) setModelEndpointVariable (ctx context.Context , dockerModel * manager.Plugin , project * types.Project ) error {
144165 cmd := exec .CommandContext (ctx , dockerModel .Path , "status" , "--json" )
145166 s .setupChildProcess (ctx , cmd )
@@ -160,8 +181,8 @@ func (s *composeService) setModelEndpointVariable(ctx context.Context, dockerMod
160181 for _ , service := range project .Services {
161182 for model , modelConfig := range service .Models {
162183 var variable string
163- if modelConfig != nil && modelConfig .Variable != "" {
164- variable = modelConfig .Variable
184+ if modelConfig != nil && modelConfig .EndpointVariable != "" {
185+ variable = modelConfig .EndpointVariable
165186 } else {
166187 variable = strings .ToUpper (model ) + "_URL"
167188 }
0 commit comments