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

Commit bfa5561

Browse files
authored
Merge pull request #77 from glours/compose-provider-metadata
add compose metadata subcommand to return information about model runner cli usage as a Compose provider
2 parents 8798f10 + bb6b18a commit bfa5561

File tree

4 files changed

+85
-15
lines changed

4 files changed

+85
-15
lines changed

commands/compose.go

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"github.com/spf13/pflag"
78
"slices"
89
"strings"
910

@@ -18,8 +19,9 @@ func newComposeCmd() *cobra.Command {
1819
c := &cobra.Command{
1920
Use: "compose EVENT",
2021
}
21-
c.AddCommand(newUpCommand())
22-
c.AddCommand(newDownCommand())
22+
upCmd := newUpCommand()
23+
downCmd := newDownCommand()
24+
c.AddCommand(upCmd, downCmd, newMetadataCommand(upCmd, downCmd))
2325
c.Hidden = true
2426
c.PersistentFlags().String("project-name", "", "compose project name") // unused by model
2527

@@ -95,19 +97,40 @@ func newUpCommand() *cobra.Command {
9597
c.Flags().Int64Var(&ctxSize, "context-size", -1, "context size for the model")
9698
c.Flags().StringVar(&rawRuntimeFlags, "runtime-flags", "", "raw runtime flags to pass to the inference engine")
9799
c.Flags().StringVar(&backend, "backend", llamacpp.Name, "inference backend to use")
100+
_ = c.MarkFlagRequired("model")
98101
return c
99102
}
100103

101104
func newDownCommand() *cobra.Command {
102-
var model []string
103105
c := &cobra.Command{
104106
Use: "down",
105107
RunE: func(cmd *cobra.Command, args []string) error {
106108
// No required cleanup on down
107109
return nil
108110
},
109111
}
110-
c.Flags().StringArrayVar(&model, "model", nil, "model to use")
112+
return c
113+
}
114+
115+
func newMetadataCommand(upCmd, downCmd *cobra.Command) *cobra.Command {
116+
c := &cobra.Command{
117+
Use: "metadata",
118+
Short: "Metadata for Docker Compose",
119+
RunE: func(cmd *cobra.Command, args []string) error {
120+
providerMetadata := ProviderMetadata{
121+
Description: "Docker Model Runner",
122+
}
123+
providerMetadata.Up = commandParameters(upCmd)
124+
providerMetadata.Down = commandParameters(downCmd)
125+
126+
jsonMetadata, err := json.Marshal(providerMetadata)
127+
if err != nil {
128+
return err
129+
}
130+
fmt.Printf(string(jsonMetadata))
131+
return nil
132+
},
133+
}
111134
return c
112135
}
113136

@@ -188,3 +211,36 @@ func sendInfo(s string) error {
188211
_, err = fmt.Println(string(marshal))
189212
return err
190213
}
214+
215+
func commandParameters(cmd *cobra.Command) CommandMetadata {
216+
cmdMetadata := CommandMetadata{}
217+
cmd.Flags().VisitAll(func(f *pflag.Flag) {
218+
_, isRequired := f.Annotations[cobra.BashCompOneRequiredFlag]
219+
cmdMetadata.Parameters = append(cmdMetadata.Parameters, ParameterMetadata{
220+
Name: f.Name,
221+
Description: f.Usage,
222+
Required: isRequired,
223+
Type: f.Value.Type(),
224+
Default: f.DefValue,
225+
})
226+
})
227+
return cmdMetadata
228+
}
229+
230+
type ProviderMetadata struct {
231+
Description string `json:"description"`
232+
Up CommandMetadata `json:"up"`
233+
Down CommandMetadata `json:"down"`
234+
}
235+
236+
type CommandMetadata struct {
237+
Parameters []ParameterMetadata `json:"parameters"`
238+
}
239+
240+
type ParameterMetadata struct {
241+
Name string `json:"name"`
242+
Description string `json:"description"`
243+
Required bool `json:"required"`
244+
Type string `json:"type"`
245+
Default string `json:"default,omitempty"`
246+
}

docs/reference/docker_model_compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ pname: docker model
33
plink: docker_model.yaml
44
cname:
55
- docker model compose down
6+
- docker model compose metadata
67
- docker model compose up
78
clink:
89
- docker_model_compose_down.yaml
10+
- docker_model_compose_metadata.yaml
911
- docker_model_compose_up.yaml
1012
options:
1113
- option: project-name

docs/reference/docker_model_compose_down.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ command: docker model compose down
22
usage: docker model compose down
33
pname: docker model compose
44
plink: docker_model_compose.yaml
5-
options:
6-
- option: model
7-
value_type: stringArray
8-
default_value: '[]'
9-
description: model to use
10-
deprecated: false
11-
hidden: false
12-
experimental: false
13-
experimentalcli: false
14-
kubernetes: false
15-
swarm: false
165
inherited_options:
176
- option: project-name
187
value_type: string
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
command: docker model compose metadata
2+
short: Metadata for Docker Compose
3+
long: Metadata for Docker Compose
4+
usage: docker model compose metadata
5+
pname: docker model compose
6+
plink: docker_model_compose.yaml
7+
inherited_options:
8+
- option: project-name
9+
value_type: string
10+
description: compose project name
11+
deprecated: false
12+
hidden: false
13+
experimental: false
14+
experimentalcli: false
15+
kubernetes: false
16+
swarm: false
17+
deprecated: false
18+
hidden: true
19+
experimental: false
20+
experimentalcli: true
21+
kubernetes: false
22+
swarm: false
23+

0 commit comments

Comments
 (0)