Expand description
OpenAI-compatible /chat/completions adapter with native tool-calling.
This is the default dialect because it covers vLLM, Ollama, LM Studio and
most hosted gateways, and because it gives the model first-class tools and
tool_calls instead of prompt-parsed actions. The module is pure
translation — neutral Request → OpenAI JSON, OpenAI JSON → neutral
Response — and performs no I/O; intel/client.rs owns the socket.
Constants§
- DEFAULT_
PATH - The default endpoint path when the intelligence URL carries no explicit
path (
https://host[:port]with path/). - MODELS_
PATH - The OpenAI-compatible model-list path used by the discovery probe. The
/v1API root has a sibling/modelsnext to/chat/completions.
Functions§
- build_
request - Build the request body (JSON bytes) and the HTTP headers for a chat
completion.
token, if present, becomesAuthorization: Bearer …. - models_
path - Derive the model-discovery
GETpath as the sibling of the configured chat path: swap the trailing…/chat/completionssegment for…/modelsso a non-default API root (e.g. a gateway mounted at/proxy/v1) keeps its prefix. Anything that isn’t the canonical chat suffix falls back to the absoluteMODELS_PATH— discovery is best-effort, never a hard failure, so guessing a plausible path beats refusing to probe. - parse_
models - Parse an OpenAI-compatible
/v1/modelsresponse body into the list of modelids. The expected shape is{ "data": [ { "id": "…" }, … ] }. A missing, empty or non-arraydata, or a body that is not JSON at all, yields an empty list: discovery degrades silently and never counts as a failover-class failure, so a provider without the endpoint must not mark itself unhealthy. - parse_
response - Parse an OpenAI
/chat/completionsresponse body into the neutralResponse. Tolerant: missing usage → zero; unknown finish reason →StopReason::Other; tool-call arguments that aren’t valid JSON are wrapped as{"_raw": "…"}rather than dropped.