Skip to main content

Module openai

Module openai 

Source
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 /v1 API root has a sibling /models next to /chat/completions.

Functions§

build_request
Build the request body (JSON bytes) and the HTTP headers for a chat completion. token, if present, becomes Authorization: Bearer ….
models_path
Derive the model-discovery GET path as the sibling of the configured chat path: swap the trailing …/chat/completions segment for …/models so 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 absolute MODELS_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/models response body into the list of model ids. The expected shape is { "data": [ { "id": "…" }, … ] }. A missing, empty or non-array data, 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/completions response body into the neutral Response. Tolerant: missing usage → zero; unknown finish reason → StopReason::Other; tool-call arguments that aren’t valid JSON are wrapped as {"_raw": "…"} rather than dropped.