This repository was archived by the owner on Oct 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Add requests monitoring #151
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
89218c5
chore: bump model-runner
doringeman 3fa1028
feat: add requests monitoring
doringeman e806cc4
refactor: combine the requests endpoints
doringeman b1cf0b0
docs: add `docker model requess`
doringeman 5b21281
deps: fix build by manually adding the patched go-winjob to support w…
doringeman 2a43e46
fix(requests): URL encode model filter parameter
doringeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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--> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.