Skip to content

add compose metadata subcommand to return information about model runner cli usage as a Compose provider #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions commands/compose.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/spf13/pflag"
"slices"
"strings"

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

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

func newDownCommand() *cobra.Command {
var model []string
c := &cobra.Command{
Use: "down",
RunE: func(cmd *cobra.Command, args []string) error {
// No required cleanup on down
return nil
},
}
c.Flags().StringArrayVar(&model, "model", nil, "model to use")
Comment on lines -102 to -110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In testing, I'm seeing things fail on docker compose down:

 ✘ llama3.2                     exit status 1                                                                                                                          0.0s
 ✘ qwen3                        exit status 1                                                                                                                          0.0s
 failed to remove service provider: exit status 1

Are we sure that we should remove the model argument to down?

Copy link
Contributor

@xenoscopic xenoscopic Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I add these two lines back, then compose down does seem to work correctly.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test this somehow in the builds?

Copy link
Contributor Author

@glours glours Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use Compose v2.37.x for your test, this is link to this change docker/compose#12903
If you test with the latest Desktop version 4.42.1 you should not have the issue

return c
}

func newMetadataCommand(upCmd, downCmd *cobra.Command) *cobra.Command {
c := &cobra.Command{
Use: "metadata",
Short: "Metadata for Docker Compose",
RunE: func(cmd *cobra.Command, args []string) error {
providerMetadata := ProviderMetadata{
Description: "Docker Model Runner",
}
providerMetadata.Up = commandParameters(upCmd)
providerMetadata.Down = commandParameters(downCmd)

jsonMetadata, err := json.Marshal(providerMetadata)
if err != nil {
return err
}
fmt.Printf(string(jsonMetadata))
return nil
},
}
return c
}

@@ -188,3 +211,36 @@ func sendInfo(s string) error {
_, err = fmt.Println(string(marshal))
return err
}

func commandParameters(cmd *cobra.Command) CommandMetadata {
cmdMetadata := CommandMetadata{}
cmd.Flags().VisitAll(func(f *pflag.Flag) {
_, isRequired := f.Annotations[cobra.BashCompOneRequiredFlag]
cmdMetadata.Parameters = append(cmdMetadata.Parameters, ParameterMetadata{
Name: f.Name,
Description: f.Usage,
Required: isRequired,
Type: f.Value.Type(),
Default: f.DefValue,
})
})
return cmdMetadata
}

type ProviderMetadata struct {
Description string `json:"description"`
Up CommandMetadata `json:"up"`
Down CommandMetadata `json:"down"`
}

type CommandMetadata struct {
Parameters []ParameterMetadata `json:"parameters"`
}

type ParameterMetadata struct {
Name string `json:"name"`
Description string `json:"description"`
Required bool `json:"required"`
Type string `json:"type"`
Default string `json:"default,omitempty"`
}
2 changes: 2 additions & 0 deletions docs/reference/docker_model_compose.yaml
Original file line number Diff line number Diff line change
@@ -3,9 +3,11 @@ pname: docker model
plink: docker_model.yaml
cname:
- docker model compose down
- docker model compose metadata
- docker model compose up
clink:
- docker_model_compose_down.yaml
- docker_model_compose_metadata.yaml
- docker_model_compose_up.yaml
options:
- option: project-name
11 changes: 0 additions & 11 deletions docs/reference/docker_model_compose_down.yaml
Original file line number Diff line number Diff line change
@@ -2,17 +2,6 @@ command: docker model compose down
usage: docker model compose down
pname: docker model compose
plink: docker_model_compose.yaml
options:
- option: model
value_type: stringArray
default_value: '[]'
description: model to use
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
inherited_options:
- option: project-name
value_type: string
23 changes: 23 additions & 0 deletions docs/reference/docker_model_compose_metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
command: docker model compose metadata
short: Metadata for Docker Compose
long: Metadata for Docker Compose
usage: docker model compose metadata
pname: docker model compose
plink: docker_model_compose.yaml
inherited_options:
- option: project-name
value_type: string
description: compose project name
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: true
experimental: false
experimentalcli: true
kubernetes: false
swarm: false