Skip to content

Add server-aware generate and chat CLIs - #1823

Closed
Lazarus-931 wants to merge 1 commit into
Blaizzy:mainfrom
Lazarus-931:server-aware-generate-cli
Closed

Lazarus-931 wants to merge 1 commit into
Blaizzy:mainfrom
Lazarus-931:server-aware-generate-cli

Conversation

@Lazarus-931

Copy link
Copy Markdown
Collaborator

Summary

  • Add optional server reuse to mlx_vlm generate and mlx_vlm chat.
  • Reuse a running mlx-vlm server through its OpenAI-compatible
    /v1/chat/completions API instead of cold-loading the model again.
  • Add --base-url, --api-key, --server, and --local.
  • Preserve the existing local path for unsupported or local-only options.

Behavior

For plain text and vision generation, the CLI probes a running server and
streams its response when available. --server requires remote execution;
--local explicitly bypasses the server.

Options that cannot be represented faithfully by the request API remain local.
A reachable server that returns an authentication or HTTP error is surfaced,
rather than silently falling back to a separate local model load.

Validation

  • uv run --with pytest python -m pytest mlx_vlm/tests/test_cli.py mlx_vlm/tests/test_server.py -q
    • 283 passed
  • Formatted with Black; pre-commit Black, isort, and autoflake passed.
  • End-to-end verified on an M4 Mac mini against a real mlx-vlm server using
    mlx-community/Qwen3-1.7B-4bit.

Related

This provides the engine-side server-aware CLI behavior needed by the Nativ CLI:
Blaizzy/nativ#228

@Lazarus-931
Lazarus-931 requested a review from Blaizzy August 9, 2026 19:40
@Lazarus-931
Lazarus-931 marked this pull request as ready for review August 9, 2026 19:40

@Blaizzy Blaizzy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the direction, let's just increase the quality of the thinking and manual review.

Comment thread mlx_vlm/chat.py
action="store_true",
help="Require a running server instead of loading the model locally.",
)
server_mode.add_argument(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this flag

If server url is not present, it gets skipped

help="Require the server: send the request over HTTP instead of loading "
"the model locally (errors if the server is unreachable).",
)
server_mode.add_argument(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

import urllib.request

DEFAULT_BASE_URL = "http://127.0.0.1:8080"
DEFAULT_PREFILL_STEP_SIZE = 2048

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inherits from generate or server

This is a duplicate

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't seem well thought out.

Let's not let agents handle everything. Careful system planning and thinking should have precedence.

return False


def eligible_for_server(args):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, the server handles most of it

return prefill_step_size in (None, DEFAULT_PREFILL_STEP_SIZE)


def _image_url(path):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server already handles it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants