@@ -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+
1623func 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+
2943func 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
101109func 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
0 commit comments