feat(provider): add mlx provider with local context-window detection#275
Merged
LeeCheneler merged 3 commits intomainfrom Apr 10, 2026
Merged
feat(provider): add mlx provider with local context-window detection#275LeeCheneler merged 3 commits intomainfrom
LeeCheneler merged 3 commits intomainfrom
Conversation
MLX server (mlx_lm.server) exposes an OpenAI-compatible API on http://127.0.0.1:8080 by default. Treating it as its own provider type ensures model listing and context-window detection go through the /v1/models path rather than Ollama's native /api/show endpoint.
mlx_lm.server's /v1/models doesn't expose any context size, so look up max_position_embeddings (falling back through max_sequence_length, seq_length, n_positions, sliding_window) directly from the HuggingFace cache on disk. Checks top-level first, then text_config for multimodal models like gemma-3. Honours HF_HUB_CACHE and HF_HOME, and supports absolute local model paths.
Spinner ticks on an 80ms interval, so hardcoding frame 0 (⠋) races with the flush delay. Match any frame in the cycle instead. Also bump flushInkFrames from 25ms to 50ms for more timing headroom on slower hosts.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds MLX (
mlx_lm.server) as a first-class provider type so users can pointtomo at a local MLX server without masquerading it as Ollama. Also teaches
the provider to read the context window from the HuggingFace cache on disk,
since mlx_lm doesn't expose that info over HTTP.
GitHub Issue
N/A
What Changed
New
mlxprovider type. Adds"mlx"toproviderTypeSchema, wires up adefault URL (
http://127.0.0.1:8080) andMLX_API_KEYenv var inprovider/client.ts, and exposes it in the settings dropdown. Because MLXis OpenAI-compatible, model listing flows through the existing
/v1/modelspath — no new client implementation required. Previously users who selected
"ollama" and pointed the URL at MLX hit Ollama's native
/api/showand/api/tagsendpoints and got confusing results.Context window from HuggingFace config.json.
mlx_lm.server's/v1/modelsreturns only
id/object/created— no context length — and there's noother endpoint that exposes it. Since mlx_lm downloads HF models to the
local cache before serving, we read
config.jsondirectly from~/.cache/huggingface/hub/models--<org>--<repo>/snapshots/*/. Field lookupwalks
max_position_embeddings→max_sequence_length→seq_length→n_positions→sliding_windowat the top level first, then falls back totext_configfor multimodal models (e.g. gemma-3).HF_HUB_CACHEandHF_HOMEenv vars are honoured, and absolute local model paths aresupported. Any failure falls through to the existing 8192 default.
Test-stability fixups. Spinner assertions in chat/model-selector/providers
tests hardcoded frame 0 (
⠋), which raced against the 80ms spinner tick —relaxed to match any frame in the cycle. Also bumped
flushInkFramesfrom25ms to 50ms to give ink input parsing more headroom on slower hosts.
Notes for Reviewers
fetchMlxContextWindowis synchronous (fs reads are cheap) but calledfrom the async
fetchContextWindowwrapper — the outer try/catch stillcatches any unexpected throw.
models--<org>--<repo>/snapshots/<hash>/— wetake the first snapshot directory found. Multiple snapshots from stale
revisions shouldn't matter in practice since
max_position_embeddingsis architectural, not per-revision.