Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/python-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ with mlxcel.LLM("mlx-community/Qwen3-4B-4bit") as llm:
print(delta, end="", flush=True)
```

A runnable version of this example lives at [`python/examples/streaming.py`](../python/examples/streaming.py).

## Chat

`chat` returns the assistant message content as a string.
Expand Down Expand Up @@ -147,6 +149,8 @@ reply = llm.chat(
person = json.loads(reply)
```

A runnable version of this example lives at [`python/examples/structured_output.py`](../python/examples/structured_output.py); it also issues the same request through the raw `openai_client`.

## The `openai_client` escape hatch

For anything the convenience methods do not cover (tools, logprobs, vision and audio inputs, the Responses API), reach for the configured OpenAI client directly. It is wired to the same transport, so TCP and Unix-socket setups both work.
Expand Down
8 changes: 8 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ llm = mlxcel.LLM(socket="/tmp/mlxcel.sock") # Unix socket

Async usage mirrors the sync API via `mlxcel.AsyncLLM` (`await llm.generate(...)`, `async for delta in llm.stream(...)`).

## Examples

Runnable scripts live in [`examples/`](examples/). Each expects the `mlxcel` binary on `PATH` (or `MLXCEL_BIN`) and a model available locally or downloadable from Hugging Face; run them from the repo root:

- [`quickstart.py`](examples/quickstart.py) — managed-mode tour: spawn a local server, then `generate`, `chat`, `models`, and `tokenize`/`detokenize`. `python python/examples/quickstart.py`
- [`streaming.py`](examples/streaming.py) — print `stream` and `chat_stream` deltas as they arrive. `python python/examples/streaming.py`
- [`structured_output.py`](examples/structured_output.py) — schema-constrained JSON via `response_format`, plus the same request through the raw `openai_client`. `python python/examples/structured_output.py`

## Modes

- **Managed mode** (default when `model=` is given): the client spawns `mlxcel serve`, waits until `/health` returns ready, forwards server logs to the `mlxcel.server` Python logger, and stops the process on exit.
Expand Down