Skip to content

Commit 4830663

Browse files
committed
feat(cli): add configure show subcommand
Add `docker model configure show [MODEL]` to display active model configurations. Also alias `configure` to `config` for convenience. Signed-off-by: Dorin Geman <[email protected]>
1 parent db831fd commit 4830663

File tree

5 files changed

+89
-5
lines changed

5 files changed

+89
-5
lines changed

cmd/cli/commands/configure.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ func newConfigureCmd() *cobra.Command {
1111
var flags ConfigureFlags
1212

1313
c := &cobra.Command{
14-
Use: "configure [--context-size=<n>] [--speculative-draft-model=<model>] [--hf_overrides=<json>] [--gpu-memory-utilization=<float>] [--mode=<mode>] [--think] MODEL [-- <runtime-flags...>]",
15-
Short: "Configure runtime options for a model",
16-
Hidden: true,
14+
Use: "configure [--context-size=<n>] [--speculative-draft-model=<model>] [--hf_overrides=<json>] [--gpu-memory-utilization=<float>] [--mode=<mode>] [--think] MODEL [-- <runtime-flags...>]",
15+
Aliases: []string{"config"},
16+
Short: "Manage model runtime configurations",
17+
Hidden: true,
1718
Args: func(cmd *cobra.Command, args []string) error {
1819
argsBeforeDash := cmd.ArgsLenAtDash()
1920
if argsBeforeDash == -1 {
@@ -48,5 +49,6 @@ func newConfigureCmd() *cobra.Command {
4849
}
4950

5051
flags.RegisterFlags(c)
52+
c.AddCommand(newConfigureShowCmd())
5153
return c
5254
}

cmd/cli/commands/configure_show.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package commands
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/docker/model-runner/cmd/cli/commands/completion"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func newConfigureShowCmd() *cobra.Command {
12+
c := &cobra.Command{
13+
Use: "show [MODEL]",
14+
Short: "Show model configurations",
15+
Args: cobra.MaximumNArgs(1),
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
var modelFilter string
18+
if len(args) > 0 {
19+
modelFilter = args[0]
20+
}
21+
configs, err := desktopClient.ShowConfigs(modelFilter)
22+
if err != nil {
23+
return err
24+
}
25+
jsonResult, err := json.MarshalIndent(configs, "", " ")
26+
if err != nil {
27+
return fmt.Errorf("failed to marshal configs to JSON: %w", err)
28+
}
29+
cmd.Println(string(jsonResult))
30+
return nil
31+
},
32+
ValidArgsFunction: completion.ModelNames(getDesktopClient, 1),
33+
}
34+
return c
35+
}

cmd/cli/desktop/desktop.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,35 @@ func (c *Client) Unload(req UnloadRequest) (UnloadResponse, error) {
670670
return unloadResp, nil
671671
}
672672

673+
func (c *Client) ShowConfigs(modelFilter string) ([]scheduling.ModelConfigEntry, error) {
674+
configureBackendPath := inference.InferencePrefix + "/_configure"
675+
if modelFilter != "" {
676+
configureBackendPath += "?model=" + url.QueryEscape(modelFilter)
677+
}
678+
resp, err := c.doRequest(http.MethodGet, configureBackendPath, nil)
679+
if err != nil {
680+
return nil, c.handleQueryError(err, configureBackendPath)
681+
}
682+
defer resp.Body.Close()
683+
684+
if resp.StatusCode != http.StatusOK {
685+
body, _ := io.ReadAll(resp.Body)
686+
return nil, fmt.Errorf("listing configs failed with status %s: %s", resp.Status, string(body))
687+
}
688+
689+
body, err := io.ReadAll(resp.Body)
690+
if err != nil {
691+
return nil, fmt.Errorf("failed to read response body: %w", err)
692+
}
693+
694+
var configs []scheduling.ModelConfigEntry
695+
if err := json.Unmarshal(body, &configs); err != nil {
696+
return nil, fmt.Errorf("failed to unmarshal response body: %w", err)
697+
}
698+
699+
return configs, nil
700+
}
701+
673702
func (c *Client) ConfigureBackend(request scheduling.ConfigureRequest) error {
674703
configureBackendPath := inference.InferencePrefix + "/_configure"
675704
jsonData, err := json.Marshal(request)

cmd/cli/docs/reference/docker_model_configure.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
command: docker model configure
2-
short: Configure runtime options for a model
3-
long: Configure runtime options for a model
2+
aliases: docker model configure, docker model config
3+
short: Manage model runtime configurations
4+
long: Manage model runtime configurations
45
usage: docker model configure [--context-size=<n>] [--speculative-draft-model=<model>] [--hf_overrides=<json>] [--gpu-memory-utilization=<float>] [--mode=<mode>] [--think] MODEL [-- <runtime-flags...>]
56
pname: docker model
67
plink: docker_model.yaml
8+
cname:
9+
- docker model configure show
10+
clink:
11+
- docker_model_configure_show.yaml
712
options:
813
- option: context-size
914
value_type: int32
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
command: docker model configure show
2+
short: Show model configurations
3+
long: Show model configurations
4+
usage: docker model configure show [MODEL]
5+
pname: docker model configure
6+
plink: docker_model_configure.yaml
7+
deprecated: false
8+
hidden: true
9+
experimental: false
10+
experimentalcli: false
11+
kubernetes: false
12+
swarm: false
13+

0 commit comments

Comments
 (0)