Skip to content

Commit 695c2b8

Browse files
committed
chore(cli): remove unused backend flag
Reverts docker/model-cli#126. Signed-off-by: Dorin Geman <[email protected]>
1 parent 1087b82 commit 695c2b8

File tree

7 files changed

+42
-167
lines changed

7 files changed

+42
-167
lines changed

cmd/cli/commands/backend.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

cmd/cli/commands/list.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,19 @@ import (
1919

2020
func newListCmd() *cobra.Command {
2121
var jsonFormat, openai, quiet bool
22-
var backend string
2322
c := &cobra.Command{
2423
Use: "list [OPTIONS]",
2524
Aliases: []string{"ls"},
2625
Short: "List the models pulled to your local environment",
2726
RunE: func(cmd *cobra.Command, args []string) error {
28-
// Validate backend if specified
29-
if backend != "" {
30-
if err := validateBackend(backend); err != nil {
31-
return err
32-
}
33-
}
34-
35-
if (backend == "openai" || openai) && quiet {
27+
if openai && quiet {
3628
return fmt.Errorf("--quiet flag cannot be used with --openai flag or OpenAI backend")
3729
}
3830

39-
// Validate API key for OpenAI backend
40-
apiKey, err := ensureAPIKey(backend)
41-
if err != nil {
42-
return err
43-
}
44-
4531
// If we're doing an automatic install, only show the installation
4632
// status if it won't corrupt machine-readable output.
4733
var standaloneInstallPrinter standalone.StatusPrinter
48-
if !jsonFormat && !openai && !quiet && backend == "" {
34+
if !jsonFormat && !openai && !quiet {
4935
standaloneInstallPrinter = cmd
5036
}
5137
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), standaloneInstallPrinter); err != nil {
@@ -55,7 +41,7 @@ func newListCmd() *cobra.Command {
5541
if len(args) > 0 {
5642
modelFilter = args[0]
5743
}
58-
models, err := listModels(openai, backend, desktopClient, quiet, jsonFormat, apiKey, modelFilter)
44+
models, err := listModels(openai, desktopClient, quiet, jsonFormat, modelFilter)
5945
if err != nil {
6046
return err
6147
}
@@ -67,14 +53,12 @@ func newListCmd() *cobra.Command {
6753
c.Flags().BoolVar(&jsonFormat, "json", false, "List models in a JSON format")
6854
c.Flags().BoolVar(&openai, "openai", false, "List models in an OpenAI format")
6955
c.Flags().BoolVarP(&quiet, "quiet", "q", false, "Only show model IDs")
70-
c.Flags().StringVar(&backend, "backend", "", fmt.Sprintf("Specify the backend to use (%s)", ValidBackendsKeys()))
71-
c.Flags().MarkHidden("backend")
7256
return c
7357
}
7458

75-
func listModels(openai bool, backend string, desktopClient *desktop.Client, quiet bool, jsonFormat bool, apiKey string, modelFilter string) (string, error) {
76-
if openai || backend == "openai" {
77-
models, err := desktopClient.ListOpenAI(backend, apiKey)
59+
func listModels(openai bool, desktopClient *desktop.Client, quiet bool, jsonFormat bool, modelFilter string) (string, error) {
60+
if openai {
61+
models, err := desktopClient.ListOpenAI()
7862
if err != nil {
7963
err = handleClientError(err, "Failed to list models")
8064
return "", handleNotRunningError(err)

cmd/cli/commands/run.go

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func readMultilineInput(cmd *cobra.Command, scanner *bufio.Scanner) (string, err
8787
}
8888

8989
// generateInteractiveWithReadline provides an enhanced interactive mode with readline support
90-
func generateInteractiveWithReadline(cmd *cobra.Command, desktopClient *desktop.Client, backend, model, apiKey string) error {
90+
func generateInteractiveWithReadline(cmd *cobra.Command, desktopClient *desktop.Client, model string) error {
9191
usage := func() {
9292
fmt.Fprintln(os.Stderr, "Available Commands:")
9393
fmt.Fprintln(os.Stderr, " /bye Exit")
@@ -122,7 +122,7 @@ func generateInteractiveWithReadline(cmd *cobra.Command, desktopClient *desktop.
122122
})
123123
if err != nil {
124124
// Fall back to basic input mode if readline initialization fails
125-
return generateInteractiveBasic(cmd, desktopClient, backend, model, apiKey)
125+
return generateInteractiveBasic(cmd, desktopClient, model)
126126
}
127127

128128
// Disable history if the environment variable is set
@@ -221,7 +221,7 @@ func generateInteractiveWithReadline(cmd *cobra.Command, desktopClient *desktop.
221221
}
222222
}()
223223

224-
err := chatWithMarkdownContext(chatCtx, cmd, desktopClient, backend, model, userInput, apiKey)
224+
err := chatWithMarkdownContext(chatCtx, cmd, desktopClient, model, userInput)
225225

226226
// Clean up signal handler
227227
signal.Stop(sigChan)
@@ -246,7 +246,7 @@ func generateInteractiveWithReadline(cmd *cobra.Command, desktopClient *desktop.
246246
}
247247

248248
// generateInteractiveBasic provides a basic interactive mode (fallback)
249-
func generateInteractiveBasic(cmd *cobra.Command, desktopClient *desktop.Client, backend, model, apiKey string) error {
249+
func generateInteractiveBasic(cmd *cobra.Command, desktopClient *desktop.Client, model string) error {
250250
scanner := bufio.NewScanner(os.Stdin)
251251
for {
252252
userInput, err := readMultilineInput(cmd, scanner)
@@ -282,7 +282,7 @@ func generateInteractiveBasic(cmd *cobra.Command, desktopClient *desktop.Client,
282282
}
283283
}()
284284

285-
err = chatWithMarkdownContext(chatCtx, cmd, desktopClient, backend, model, userInput, apiKey)
285+
err = chatWithMarkdownContext(chatCtx, cmd, desktopClient, model, userInput)
286286

287287
cancelChat()
288288
signal.Stop(sigChan)
@@ -484,12 +484,12 @@ func renderMarkdown(content string) (string, error) {
484484
}
485485

486486
// chatWithMarkdown performs chat and streams the response with selective markdown rendering.
487-
func chatWithMarkdown(cmd *cobra.Command, client *desktop.Client, backend, model, prompt, apiKey string) error {
488-
return chatWithMarkdownContext(cmd.Context(), cmd, client, backend, model, prompt, apiKey)
487+
func chatWithMarkdown(cmd *cobra.Command, client *desktop.Client, model, prompt string) error {
488+
return chatWithMarkdownContext(cmd.Context(), cmd, client, model, prompt)
489489
}
490490

491491
// chatWithMarkdownContext performs chat with context support and streams the response with selective markdown rendering.
492-
func chatWithMarkdownContext(ctx context.Context, cmd *cobra.Command, client *desktop.Client, backend, model, prompt, apiKey string) error {
492+
func chatWithMarkdownContext(ctx context.Context, cmd *cobra.Command, client *desktop.Client, model, prompt string) error {
493493
colorMode, _ := cmd.Flags().GetString("color")
494494
useMarkdown := shouldUseMarkdown(colorMode)
495495
debug, _ := cmd.Flags().GetBool("debug")
@@ -504,15 +504,15 @@ func chatWithMarkdownContext(ctx context.Context, cmd *cobra.Command, client *de
504504

505505
if !useMarkdown {
506506
// Simple case: just stream as plain text
507-
return client.ChatWithContext(ctx, backend, model, prompt, apiKey, imageURLs, func(content string) {
507+
return client.ChatWithContext(ctx, model, prompt, imageURLs, func(content string) {
508508
cmd.Print(content)
509509
}, false)
510510
}
511511

512512
// For markdown: use streaming buffer to render code blocks as they complete
513513
markdownBuffer := NewStreamingMarkdownBuffer()
514514

515-
err = client.ChatWithContext(ctx, backend, model, prompt, apiKey, imageURLs, func(content string) {
515+
err = client.ChatWithContext(ctx, model, prompt, imageURLs, func(content string) {
516516
// Use the streaming markdown buffer to intelligently render content
517517
rendered, err := markdownBuffer.AddContent(content, true)
518518
if err != nil {
@@ -539,7 +539,6 @@ func chatWithMarkdownContext(ctx context.Context, cmd *cobra.Command, client *de
539539

540540
func newRunCmd() *cobra.Command {
541541
var debug bool
542-
var backend string
543542
var ignoreRuntimeMemoryCheck bool
544543
var colorMode string
545544
var detach bool
@@ -557,19 +556,6 @@ func newRunCmd() *cobra.Command {
557556
}
558557
},
559558
RunE: func(cmd *cobra.Command, args []string) error {
560-
// Validate backend if specified
561-
if backend != "" {
562-
if err := validateBackend(backend); err != nil {
563-
return err
564-
}
565-
}
566-
567-
// Validate API key for OpenAI backend
568-
apiKey, err := ensureAPIKey(backend)
569-
if err != nil {
570-
return err
571-
}
572-
573559
// Normalize model name to add default org and tag if missing
574560
model := models.NormalizeModelName(args[0])
575561
prompt := ""
@@ -607,24 +593,21 @@ func newRunCmd() *cobra.Command {
607593
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
608594
}
609595

610-
// Do not validate the model in case of using OpenAI's backend, let OpenAI handle it
611-
if backend != "openai" {
612-
_, err := desktopClient.Inspect(model, false)
613-
if err != nil {
614-
if !errors.Is(err, desktop.ErrNotFound) {
615-
return handleNotRunningError(handleClientError(err, "Failed to inspect model"))
616-
}
617-
cmd.Println("Unable to find model '" + model + "' locally. Pulling from the server.")
618-
if err := pullModel(cmd, desktopClient, model, ignoreRuntimeMemoryCheck); err != nil {
619-
return err
620-
}
596+
_, err := desktopClient.Inspect(model, false)
597+
if err != nil {
598+
if !errors.Is(err, desktop.ErrNotFound) {
599+
return handleNotRunningError(handleClientError(err, "Failed to inspect model"))
600+
}
601+
cmd.Println("Unable to find model '" + model + "' locally. Pulling from the server.")
602+
if err := pullModel(cmd, desktopClient, model, ignoreRuntimeMemoryCheck); err != nil {
603+
return err
621604
}
622605
}
623606

624607
// Handle --detach flag: just load the model without interaction
625608
if detach {
626609
// Make a minimal request to load the model into memory
627-
err := desktopClient.Chat(backend, model, "", apiKey, nil, func(content string) {
610+
err := desktopClient.Chat(model, "", nil, func(content string) {
628611
// Silently discard output in detach mode
629612
}, false)
630613
if err != nil {
@@ -637,7 +620,7 @@ func newRunCmd() *cobra.Command {
637620
}
638621

639622
if prompt != "" {
640-
if err := chatWithMarkdown(cmd, desktopClient, backend, model, prompt, apiKey); err != nil {
623+
if err := chatWithMarkdown(cmd, desktopClient, model, prompt); err != nil {
641624
return handleClientError(err, "Failed to generate a response")
642625
}
643626
cmd.Println()
@@ -646,11 +629,11 @@ func newRunCmd() *cobra.Command {
646629

647630
// Use enhanced readline-based interactive mode when terminal is available
648631
if term.IsTerminal(int(os.Stdin.Fd())) {
649-
return generateInteractiveWithReadline(cmd, desktopClient, backend, model, apiKey)
632+
return generateInteractiveWithReadline(cmd, desktopClient, model)
650633
}
651634

652635
// Fall back to basic mode if not a terminal
653-
return generateInteractiveBasic(cmd, desktopClient, backend, model, apiKey)
636+
return generateInteractiveBasic(cmd, desktopClient, model)
654637
},
655638
ValidArgsFunction: completion.ModelNames(getDesktopClient, 1),
656639
}
@@ -667,8 +650,6 @@ func newRunCmd() *cobra.Command {
667650
}
668651

669652
c.Flags().BoolVar(&debug, "debug", false, "Enable debug logging")
670-
c.Flags().StringVar(&backend, "backend", "", fmt.Sprintf("Specify the backend to use (%s)", ValidBackendsKeys()))
671-
c.Flags().MarkHidden("backend")
672653
c.Flags().BoolVar(&ignoreRuntimeMemoryCheck, "ignore-runtime-memory-check", false, "Do not block pull if estimated runtime memory for model exceeds system resources.")
673654
c.Flags().StringVar(&colorMode, "color", "auto", "Use colored output (auto|yes|no)")
674655
c.Flags().BoolVarP(&detach, "detach", "d", false, "Load the model in the background without interaction")

cmd/cli/desktop/desktop.go

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"go.opentelemetry.io/otel"
2525
)
2626

27-
const DefaultBackend = "llama.cpp"
28-
2927
var (
3028
ErrNotFound = errors.New("model not found")
3129
ErrServiceUnavailable = errors.New("service unavailable")
@@ -233,32 +231,18 @@ func (c *Client) List() ([]dmrm.Model, error) {
233231
return modelsJson, nil
234232
}
235233

236-
func (c *Client) ListOpenAI(backend, apiKey string) (dmrm.OpenAIModelList, error) {
237-
if backend == "" {
238-
backend = DefaultBackend
239-
}
240-
modelsRoute := fmt.Sprintf("%s/%s/v1/models", inference.InferencePrefix, backend)
241-
242-
// Use doRequestWithAuth to support API key authentication
243-
resp, err := c.doRequestWithAuth(http.MethodGet, modelsRoute, nil, "openai", apiKey)
244-
if err != nil {
245-
return dmrm.OpenAIModelList{}, c.handleQueryError(err, modelsRoute)
246-
}
247-
defer resp.Body.Close()
248-
249-
if resp.StatusCode != http.StatusOK {
250-
return dmrm.OpenAIModelList{}, fmt.Errorf("failed to list models: %s", resp.Status)
251-
}
252-
253-
body, err := io.ReadAll(resp.Body)
234+
func (c *Client) ListOpenAI() (dmrm.OpenAIModelList, error) {
235+
modelsRoute := inference.InferencePrefix + "/v1/models"
236+
body, err := c.listRaw(modelsRoute, "")
254237
if err != nil {
255-
return dmrm.OpenAIModelList{}, fmt.Errorf("failed to read response body: %w", err)
238+
return dmrm.OpenAIModelList{}, err
256239
}
257240

258241
var modelsJson dmrm.OpenAIModelList
259242
if err := json.Unmarshal(body, &modelsJson); err != nil {
260243
return modelsJson, fmt.Errorf("failed to unmarshal response body: %w", err)
261244
}
245+
262246
return modelsJson, nil
263247
}
264248

@@ -357,12 +341,12 @@ func (c *Client) fullModelID(id string) (string, error) {
357341
}
358342

359343
// Chat performs a chat request and streams the response content with selective markdown rendering.
360-
func (c *Client) Chat(backend, model, prompt, apiKey string, imageURLs []string, outputFunc func(string), shouldUseMarkdown bool) error {
361-
return c.ChatWithContext(context.Background(), backend, model, prompt, apiKey, imageURLs, outputFunc, shouldUseMarkdown)
344+
func (c *Client) Chat(model, prompt string, imageURLs []string, outputFunc func(string), shouldUseMarkdown bool) error {
345+
return c.ChatWithContext(context.Background(), model, prompt, imageURLs, outputFunc, shouldUseMarkdown)
362346
}
363347

364348
// ChatWithContext performs a chat request with context support for cancellation and streams the response content with selective markdown rendering.
365-
func (c *Client) ChatWithContext(ctx context.Context, backend, model, prompt, apiKey string, imageURLs []string, outputFunc func(string), shouldUseMarkdown bool) error {
349+
func (c *Client) ChatWithContext(ctx context.Context, model, prompt string, imageURLs []string, outputFunc func(string), shouldUseMarkdown bool) error {
366350
model = dmrm.NormalizeModelName(model)
367351
if !strings.Contains(strings.Trim(model, "/"), "/") {
368352
// Do an extra API call to check if the model parameter isn't a model ID.
@@ -417,20 +401,13 @@ func (c *Client) ChatWithContext(ctx context.Context, backend, model, prompt, ap
417401
return fmt.Errorf("error marshaling request: %w", err)
418402
}
419403

420-
var completionsPath string
421-
if backend != "" {
422-
completionsPath = inference.InferencePrefix + "/" + backend + "/v1/chat/completions"
423-
} else {
424-
completionsPath = inference.InferencePrefix + "/v1/chat/completions"
425-
}
404+
completionsPath := inference.InferencePrefix + "/v1/chat/completions"
426405

427406
resp, err := c.doRequestWithAuthContext(
428407
ctx,
429408
http.MethodPost,
430409
completionsPath,
431410
bytes.NewReader(jsonData),
432-
backend,
433-
apiKey,
434411
)
435412
if err != nil {
436413
return c.handleQueryError(err, completionsPath)
@@ -785,15 +762,15 @@ func (c *Client) Requests(modelFilter string, streaming bool, includeExisting bo
785762

786763
// doRequest is a helper function that performs HTTP requests and handles 503 responses
787764
func (c *Client) doRequest(method, path string, body io.Reader) (*http.Response, error) {
788-
return c.doRequestWithAuth(method, path, body, "", "")
765+
return c.doRequestWithAuth(method, path, body)
789766
}
790767

791768
// doRequestWithAuth is a helper function that performs HTTP requests with optional authentication
792-
func (c *Client) doRequestWithAuth(method, path string, body io.Reader, backend, apiKey string) (*http.Response, error) {
793-
return c.doRequestWithAuthContext(context.Background(), method, path, body, backend, apiKey)
769+
func (c *Client) doRequestWithAuth(method, path string, body io.Reader) (*http.Response, error) {
770+
return c.doRequestWithAuthContext(context.Background(), method, path, body)
794771
}
795772

796-
func (c *Client) doRequestWithAuthContext(ctx context.Context, method, path string, body io.Reader, backend, apiKey string) (*http.Response, error) {
773+
func (c *Client) doRequestWithAuthContext(ctx context.Context, method, path string, body io.Reader) (*http.Response, error) {
797774
req, err := http.NewRequestWithContext(ctx, method, c.modelRunner.URL(path), body)
798775
if err != nil {
799776
return nil, fmt.Errorf("error creating request: %w", err)
@@ -804,11 +781,6 @@ func (c *Client) doRequestWithAuthContext(ctx context.Context, method, path stri
804781

805782
req.Header.Set("User-Agent", "docker-model-cli/"+Version)
806783

807-
// Add Authorization header for OpenAI backend
808-
if apiKey != "" {
809-
req.Header.Set("Authorization", "Bearer "+apiKey)
810-
}
811-
812784
resp, err := c.modelRunner.Client().Do(req)
813785
if err != nil {
814786
return nil, err

0 commit comments

Comments
 (0)