A small Rust HTTP gateway shaped like an inference service.
The default engine is a mock implementation. That is intentional: the HTTP surface, request bounds, metrics, and engine trait can be checked before pulling in Candle, tokenizers, model weights, or GPU-specific setup.
GET /healthzGET /metricsin a simple Prometheus-style text formatPOST /v1/completions- Enforces bounded prompt length.
- Tracks request count, error count, generated tokens, and total latency.
- Keeps HTTP handling separate from the
InferenceEnginetrait, so the mock engine can be replaced by a Candle-backed engine later.
cargo run -- --host 127.0.0.1 --port 8090Request:
curl -s http://127.0.0.1:8090/v1/completions \
-H 'content-type: application/json' \
-d '{"prompt":"Explain KV cache in one sentence","max_tokens":32}'Metrics:
curl -s http://127.0.0.1:8090/metricscargo test
cargo checkThe current unit tests cover the mock engine token limits, rough token counting, metrics rendering, and the small HTTP parsing/JSON escaping helpers. They do not start a socket server yet, so they run quickly and do not need a model download.
To make this a real Candle service:
- Add optional Candle dependencies to
Cargo.toml. - Implement
InferenceEnginefor aCandleEnginethat owns model weights, tokenizer, device, and generation config. - Preserve the same HTTP contract, timeouts, bounded prompt checks, and metrics.
- Benchmark CPU, Metal, or CUDA backends with the same request payload.
- This repo does not include model weights or a tokenizer yet.
- The mock engine is there to keep the service runnable while the gateway code is being shaped.
- The next real step is adding a
CandleEnginebehind the existing trait and then comparing CPU/Metal/CUDA runs with the same request payloads.