-
Notifications
You must be signed in to change notification settings - Fork 79
Add --detach flag to docker model run command #231
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
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -307,6 +307,7 @@ func newRunCmd() *cobra.Command { | |
| var backend string | ||
| var ignoreRuntimeMemoryCheck bool | ||
| var colorMode string | ||
| var detach bool | ||
|
|
||
| const cmdArgs = "MODEL [PROMPT]" | ||
| c := &cobra.Command{ | ||
|
|
@@ -341,17 +342,20 @@ func newRunCmd() *cobra.Command { | |
| prompt = strings.Join(args[1:], " ") | ||
| } | ||
|
|
||
| fi, err := os.Stdin.Stat() | ||
| if err == nil && (fi.Mode()&os.ModeCharDevice) == 0 { | ||
| // Read all from stdin | ||
| reader := bufio.NewReader(os.Stdin) | ||
| input, err := io.ReadAll(reader) | ||
| if err == nil { | ||
| if prompt != "" { | ||
| prompt += "\n\n" | ||
| // Only read from stdin if not in detach mode | ||
| if !detach { | ||
| fi, err := os.Stdin.Stat() | ||
| if err == nil && (fi.Mode()&os.ModeCharDevice) == 0 { | ||
| // Read all from stdin | ||
| reader := bufio.NewReader(os.Stdin) | ||
| input, err := io.ReadAll(reader) | ||
| if err == nil { | ||
| if prompt != "" { | ||
| prompt += "\n\n" | ||
| } | ||
|
|
||
| prompt += string(input) | ||
| } | ||
|
|
||
| prompt += string(input) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -381,6 +385,21 @@ func newRunCmd() *cobra.Command { | |
| } | ||
| } | ||
|
|
||
| // Handle --detach flag: just load the model without interaction | ||
| if detach { | ||
| // Make a minimal request to load the model into memory | ||
ericcurtin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| err := desktopClient.Chat(backend, model, "", apiKey, func(content string) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The request will be recorded, not a big deal, but to keep in mind
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes me think do we have a way of forking without chatting? 🤔 |
||
| // Silently discard output in detach mode | ||
| }, false) | ||
| if err != nil { | ||
| return handleClientError(err, "Failed to load model") | ||
| } | ||
| if debug { | ||
| cmd.Printf("Model %s loaded successfully\n", model) | ||
| } | ||
| return nil | ||
| } | ||
ericcurtin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if prompt != "" { | ||
| if err := chatWithMarkdown(cmd, desktopClient, backend, model, prompt, apiKey); err != nil { | ||
| return handleClientError(err, "Failed to generate a response") | ||
|
|
@@ -439,6 +458,7 @@ func newRunCmd() *cobra.Command { | |
| c.Flags().MarkHidden("backend") | ||
| c.Flags().BoolVar(&ignoreRuntimeMemoryCheck, "ignore-runtime-memory-check", false, "Do not block pull if estimated runtime memory for model exceeds system resources.") | ||
| c.Flags().StringVar(&colorMode, "color", "auto", "Use colored output (auto|yes|no)") | ||
| c.Flags().BoolVarP(&detach, "detach", "d", false, "Load the model in the background without interaction") | ||
|
|
||
| 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this have been placed at the beginning of the function so we don't need another
if !detach?