Expand description
OpenAI-compatible /chat/completions adapter with native tool-calling.
RFC 0006 §canonical-wire.
Canonical because it covers vLLM / Ollama / LM Studio / most hosted
gateways and gives the model first-class tools + tool_calls. This
module is pure translation: neutral Request → OpenAI JSON, and OpenAI
JSON → neutral Response. No I/O (that’s intel/client.rs).
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 (RFC 0018 §5.4 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 (RFC 0018 §5.4) 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. - parse_
models - Parse an OpenAI-compatible
/v1/modelsresponse body into the list of modelids (RFC 0018 §5.4). The shape is{ "data": [ { "id": "…" }, … ] }. Any missing/empty/non-arraydata, or a non-JSON body, yields an empty list — discovery degrades silently (it is never a failover-class failure, §5.4). - 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.