Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
82 changes: 82 additions & 0 deletions commands/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package commands

import (
"bufio"
"fmt"
"io"
"strings"

"github.com/docker/model-cli/commands/completion"
"github.com/spf13/cobra"
)

func newRequestsCmd() *cobra.Command {
var model string
var follow bool
var includeExisting bool
c := &cobra.Command{
Use: "requests [OPTIONS]",
Short: "Fetch requests+responses from Docker Model Runner",
PreRunE: func(cmd *cobra.Command, args []string) error {
// Make --include-existing only available when --follow is set.
if includeExisting && !follow {
return fmt.Errorf("--include-existing can only be used with --follow")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), cmd); err != nil {
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
}

responseBody, cancel, err := desktopClient.Requests(model, follow, includeExisting)
if err != nil {
errMsg := "Failed to get requests"
if model != "" {
errMsg = errMsg + " for " + model
}
err = handleClientError(err, errMsg)
return handleNotRunningError(err)
}
defer cancel()

if follow {
scanner := bufio.NewScanner(responseBody)
cmd.Println("Connected to request stream. Press Ctrl+C to stop.")
var currentEvent string
for scanner.Scan() {
select {
case <-cmd.Context().Done():
return nil
default:
}
line := scanner.Text()
if strings.HasPrefix(line, "event: ") {
currentEvent = strings.TrimPrefix(line, "event: ")
} else if strings.HasPrefix(line, "data: ") &&
(currentEvent == "new_request" || currentEvent == "existing_request") {
data := strings.TrimPrefix(line, "data: ")
cmd.Println(data)
}
}
cmd.Println("Stream closed by server.")
} else {
body, err := io.ReadAll(responseBody)
if err != nil {
return fmt.Errorf("failed to read response body: %w", err)
}
cmd.Print(string(body))
}

return nil
},
ValidArgsFunction: completion.NoComplete,
}
c.Flags().BoolVarP(&follow, "follow", "f", false, "Follow requests stream")
c.Flags().BoolVar(&includeExisting, "include-existing", false,
"Include existing requests when starting to follow (only available with --follow)")
c.Flags().StringVar(&model, "model", "", "Specify the model to filter requests")
// Enable completion for the --model flag.
_ = c.RegisterFlagCompletionFunc("model", completion.ModelNames(getDesktopClient, 1))
return c
}
1 change: 1 addition & 0 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func NewRootCmd(cli *command.DockerCli) *cobra.Command {
newPSCmd(),
newDFCmd(),
newUnloadCmd(),
newRequestsCmd(),
)
return rootCmd
}
58 changes: 58 additions & 0 deletions desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"html"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -657,6 +658,63 @@ func (c *Client) ConfigureBackend(request scheduling.ConfigureRequest) error {
return nil
}

// Requests returns a response body and a cancel function to ensure proper cleanup.
func (c *Client) Requests(modelFilter string, streaming bool, includeExisting bool) (io.ReadCloser, func(), error) {
path := c.modelRunner.URL(inference.InferencePrefix + "/requests")
var queryParams []string
if modelFilter != "" {
queryParams = append(queryParams, "model="+url.QueryEscape(modelFilter))
}
if includeExisting && streaming {
queryParams = append(queryParams, "include_existing=true")
}
if len(queryParams) > 0 {
path += "?" + strings.Join(queryParams, "&")
}

req, err := http.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, fmt.Errorf("failed to create request: %w", err)
}

if streaming {
req.Header.Set("Accept", "text/event-stream")
req.Header.Set("Cache-Control", "no-cache")
} else {
req.Header.Set("Accept", "application/json")
}
req.Header.Set("User-Agent", "docker-model-cli/"+Version)

resp, err := c.modelRunner.Client().Do(req)
if err != nil {
if streaming {
return nil, nil, c.handleQueryError(fmt.Errorf("failed to connect to stream: %w", err), path)
}
return nil, nil, c.handleQueryError(err, path)
}

if resp.StatusCode != http.StatusOK {
if resp.StatusCode == http.StatusNotFound {
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
return nil, nil, fmt.Errorf("%s", strings.TrimSpace(string(body)))
}

resp.Body.Close()
if streaming {
return nil, nil, fmt.Errorf("stream request failed with status: %d", resp.StatusCode)
}
return nil, nil, fmt.Errorf("failed to list requests: %s", resp.Status)
}

// Return the response body and a cancel function that closes it.
cancel := func() {
resp.Body.Close()
}

return resp.Body, cancel, nil
}

// doRequest is a helper function that performs HTTP requests and handles 503 responses
func (c *Client) doRequest(method, path string, body io.Reader) (*http.Response, error) {
return c.doRequestWithAuth(method, path, body, "", "")
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/docker_model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cname:
- docker model ps
- docker model pull
- docker model push
- docker model requests
- docker model rm
- docker model run
- docker model status
Expand All @@ -32,6 +33,7 @@ clink:
- docker_model_ps.yaml
- docker_model_pull.yaml
- docker_model_push.yaml
- docker_model_requests.yaml
- docker_model_rm.yaml
- docker_model_run.yaml
- docker_model_status.yaml
Expand Down
45 changes: 45 additions & 0 deletions docs/reference/docker_model_requests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
command: docker model requests
short: Fetch requests+responses from Docker Model Runner
long: Fetch requests+responses from Docker Model Runner
usage: docker model requests [OPTIONS]
pname: docker model
plink: docker_model.yaml
options:
- option: follow
shorthand: f
value_type: bool
default_value: "false"
description: Follow requests stream
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: include-existing
value_type: bool
default_value: "false"
description: |
Include existing requests when starting to follow (only available with --follow)
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: model
value_type: string
description: Specify the model to filter requests
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false

1 change: 1 addition & 0 deletions docs/reference/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Docker Model Runner
| [`ps`](model_ps.md) | List running models |
| [`pull`](model_pull.md) | Pull a model from Docker Hub or HuggingFace to your local environment |
| [`push`](model_push.md) | Push a model to Docker Hub |
| [`requests`](model_requests.md) | Fetch requests+responses from Docker Model Runner |
| [`rm`](model_rm.md) | Remove local models downloaded from Docker Hub |
| [`run`](model_run.md) | Run a model and interact with it using a submitted prompt or chat mode |
| [`status`](model_status.md) | Check if the Docker Model Runner is running |
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/model_requests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# docker model requests

<!---MARKER_GEN_START-->
Fetch requests+responses from Docker Model Runner

### Options

| Name | Type | Default | Description |
|:---------------------|:---------|:--------|:---------------------------------------------------------------------------------|
| `-f`, `--follow` | `bool` | | Follow requests stream |
| `--include-existing` | `bool` | | Include existing requests when starting to follow (only available with --follow) |
| `--model` | `string` | | Specify the model to filter requests |


<!---MARKER_GEN_END-->

9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/docker/docker v28.2.2+incompatible
github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0
github.com/docker/model-distribution v0.0.0-20250822172258-8fe9daa4a4da
github.com/docker/model-runner v0.0.0-20250822173738-5341c9fc2974
github.com/docker/model-distribution v0.0.0-20250905083217-3f098b3d8058
github.com/docker/model-runner v0.0.0-20250911130340-38bb0171c947
github.com/fatih/color v1.15.0
github.com/google/go-containerregistry v0.20.6
github.com/mattn/go-isatty v0.0.20
Expand Down Expand Up @@ -63,6 +63,7 @@ require (
github.com/jaypipes/pcidb v1.0.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/kolesnikovae/go-winjob v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
Expand Down Expand Up @@ -103,7 +104,7 @@ require (
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/mod v0.25.0 // indirect
golang.org/x/net v0.41.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.26.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.34.0 // indirect
Expand All @@ -117,3 +118,5 @@ require (
gotest.tools/v3 v3.5.2 // indirect
howett.net/plist v1.0.1 // indirect
)

replace github.com/kolesnikovae/go-winjob => github.com/docker/go-winjob v0.0.0-20250829235554-57b487ebcbc5
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQ
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-winjob v0.0.0-20250829235554-57b487ebcbc5 h1:dxSFEb0EEmvceIawSFNDMrvKakRz2t+2WYpY3dFAT04=
github.com/docker/go-winjob v0.0.0-20250829235554-57b487ebcbc5/go.mod h1:ICOGmIXdwhfid7rQP+tLvDJqVg0lHdEk3pI5nsapTtg=
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
github.com/docker/model-distribution v0.0.0-20250822172258-8fe9daa4a4da h1:ml99WBfcLnsy1frXQR4X+5WAC0DoGtwZyGoU/xBsDQM=
github.com/docker/model-distribution v0.0.0-20250822172258-8fe9daa4a4da/go.mod h1:dThpO9JoG5Px3i+rTluAeZcqLGw8C0qepuEL4gL2o/c=
github.com/docker/model-runner v0.0.0-20250822173738-5341c9fc2974 h1:/uF17tBEtsE6T2Xgg4cgrrqNcQ02gY5Lp98je+2K0nQ=
github.com/docker/model-runner v0.0.0-20250822173738-5341c9fc2974/go.mod h1:1Q2QRB5vob542x6P5pQXlGTYs5bYPxNG6ePcjTndA0A=
github.com/docker/model-distribution v0.0.0-20250905083217-3f098b3d8058 h1:whffgQ1pmiMFVrxRhJKA9yyCJXvmVX6iiohU9ezKCx0=
github.com/docker/model-distribution v0.0.0-20250905083217-3f098b3d8058/go.mod h1:dThpO9JoG5Px3i+rTluAeZcqLGw8C0qepuEL4gL2o/c=
github.com/docker/model-runner v0.0.0-20250911130340-38bb0171c947 h1:6Dz1SFZONEd8tlKetn2Gu6v5HDJI/YtUFwkqHGwrsV0=
github.com/docker/model-runner v0.0.0-20250911130340-38bb0171c947/go.mod h1:cl7panafjkSHllYCCGYAzty2aUvbwk55Gi35v06XL80=
github.com/dvsekhvalnov/jose2go v0.0.0-20170216131308-f21a8cedbbae/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM=
github.com/elastic/go-sysinfo v1.15.3 h1:W+RnmhKFkqPTCRoFq2VCTmsT4p/fwpo+3gKNQsn1XU0=
github.com/elastic/go-sysinfo v1.15.3/go.mod h1:K/cNrqYTDrSoMh2oDkYEMS2+a72GRxMvNP+GC+vRIlo=
Expand Down Expand Up @@ -345,8 +347,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading