diff --git a/docs/python-client.md b/docs/python-client.md index fec151503..37e5cace0 100644 --- a/docs/python-client.md +++ b/docs/python-client.md @@ -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. @@ -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. diff --git a/python/README.md b/python/README.md index ad1ec9a6a..6dbb89d56 100644 --- a/python/README.md +++ b/python/README.md @@ -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.