Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 0bf514a

Browse files
committed
fix(compose): make sure any flags defined for compose up also exist for compose down
When compose calls the model provider, the same arguments are passed to both compose up and compose down. Unless compose down supports any flag supported by compose up, some of these flags will cause a parsing error and cause compose down to fail. To fix this, move the flag setup to a dedicated type and function that can be shared by both commands. Signed-off-by: Alberto Garcia Hierro <[email protected]>
1 parent a9364e3 commit 0bf514a

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

commands/compose.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import (
1313
"github.com/spf13/cobra"
1414
)
1515

16+
type composeCommandFlags struct {
17+
Models []string
18+
CtxSize int64
19+
RawRuntimeFlags string
20+
Backend string
21+
}
22+
1623
func newComposeCmd() *cobra.Command {
1724

1825
c := &cobra.Command{
@@ -26,15 +33,19 @@ func newComposeCmd() *cobra.Command {
2633
return c
2734
}
2835

36+
func setupComposeCommandFlags(c *cobra.Command, flags *composeCommandFlags) {
37+
c.Flags().StringArrayVar(&flags.Models, "model", nil, "model to use")
38+
c.Flags().Int64Var(&flags.CtxSize, "context-size", -1, "context size for the model")
39+
c.Flags().StringVar(&flags.RawRuntimeFlags, "runtime-flags", "", "raw runtime flags to pass to the inference engine")
40+
c.Flags().StringVar(&flags.Backend, "backend", llamacpp.Name, "inference backend to use")
41+
}
42+
2943
func newUpCommand() *cobra.Command {
30-
var models []string
31-
var ctxSize int64
32-
var rawRuntimeFlags string
33-
var backend string
44+
flags := &composeCommandFlags{}
3445
c := &cobra.Command{
3546
Use: "up",
3647
RunE: func(cmd *cobra.Command, args []string) error {
37-
if len(models) == 0 {
48+
if len(flags.Models) == 0 {
3849
err := errors.New("options.model is required")
3950
_ = sendError(err.Error())
4051
return err
@@ -52,26 +63,26 @@ func newUpCommand() *cobra.Command {
5263
return errors.New("unable to determine standalone runner endpoint")
5364
}
5465

55-
if err := downloadModelsOnlyIfNotFound(desktopClient, models); err != nil {
66+
if err := downloadModelsOnlyIfNotFound(desktopClient, flags.Models); err != nil {
5667
return err
5768
}
5869

59-
if ctxSize > 0 {
60-
sendInfo(fmt.Sprintf("Setting context size to %d", ctxSize))
70+
if flags.CtxSize > 0 {
71+
sendInfo(fmt.Sprintf("Setting context size to %d", flags.CtxSize))
6172
}
62-
if rawRuntimeFlags != "" {
63-
sendInfo("Setting raw runtime flags to " + rawRuntimeFlags)
73+
if flags.RawRuntimeFlags != "" {
74+
sendInfo("Setting raw runtime flags to " + flags.RawRuntimeFlags)
6475
}
6576

66-
for _, model := range models {
77+
for _, model := range flags.Models {
6778
if err := desktopClient.ConfigureBackend(scheduling.ConfigureRequest{
6879
Model: model,
69-
ContextSize: ctxSize,
70-
RawRuntimeFlags: rawRuntimeFlags,
80+
ContextSize: flags.CtxSize,
81+
RawRuntimeFlags: flags.RawRuntimeFlags,
7182
}); err != nil {
7283
configErrFmtString := "failed to configure backend for model %s with context-size %d and runtime-flags %s"
73-
_ = sendErrorf(configErrFmtString+": %v", model, ctxSize, rawRuntimeFlags, err)
74-
return fmt.Errorf(configErrFmtString+": %w", model, ctxSize, rawRuntimeFlags, err)
84+
_ = sendErrorf(configErrFmtString+": %v", model, flags.CtxSize, flags.RawRuntimeFlags, err)
85+
return fmt.Errorf(configErrFmtString+": %w", model, flags.CtxSize, flags.RawRuntimeFlags, err)
7586
}
7687
sendInfo("Successfully configured backend for model " + model)
7788
}
@@ -91,23 +102,19 @@ func newUpCommand() *cobra.Command {
91102
return nil
92103
},
93104
}
94-
c.Flags().StringArrayVar(&models, "model", nil, "model to use")
95-
c.Flags().Int64Var(&ctxSize, "context-size", -1, "context size for the model")
96-
c.Flags().StringVar(&rawRuntimeFlags, "runtime-flags", "", "raw runtime flags to pass to the inference engine")
97-
c.Flags().StringVar(&backend, "backend", llamacpp.Name, "inference backend to use")
105+
setupComposeCommandFlags(c, flags)
98106
return c
99107
}
100108

101109
func newDownCommand() *cobra.Command {
102-
var model []string
103110
c := &cobra.Command{
104111
Use: "down",
105112
RunE: func(cmd *cobra.Command, args []string) error {
106113
// No required cleanup on down
107114
return nil
108115
},
109116
}
110-
c.Flags().StringArrayVar(&model, "model", nil, "model to use")
117+
setupComposeCommandFlags(c, &composeCommandFlags{})
111118
return c
112119
}
113120

docs/reference/docker_model_compose_down.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@ usage: docker model compose down
33
pname: docker model compose
44
plink: docker_model_compose.yaml
55
options:
6+
- option: backend
7+
value_type: string
8+
default_value: llama.cpp
9+
description: inference backend to use
10+
deprecated: false
11+
hidden: false
12+
experimental: false
13+
experimentalcli: false
14+
kubernetes: false
15+
swarm: false
16+
- option: context-size
17+
value_type: int64
18+
default_value: "-1"
19+
description: context size for the model
20+
deprecated: false
21+
hidden: false
22+
experimental: false
23+
experimentalcli: false
24+
kubernetes: false
25+
swarm: false
626
- option: model
727
value_type: stringArray
828
default_value: '[]'
@@ -13,6 +33,15 @@ options:
1333
experimentalcli: false
1434
kubernetes: false
1535
swarm: false
36+
- option: runtime-flags
37+
value_type: string
38+
description: raw runtime flags to pass to the inference engine
39+
deprecated: false
40+
hidden: false
41+
experimental: false
42+
experimentalcli: false
43+
kubernetes: false
44+
swarm: false
1645
inherited_options:
1746
- option: project-name
1847
value_type: string

0 commit comments

Comments
 (0)