Skip to main content

Module chat

Module chat 

Source
Expand description

Chat completion data types.

These types are the wire contract between the [ChatProvider] trait and its callers. All provider implementations produce and consume these shapes; nothing in tools/ or agent/ depends on provider internals.

Structs§

Completion
One step of model output.
ContextBreakdown
Locally-estimated per-component token breakdown of the prompt sent to the provider.
StructuredRequest
Request for a structured JSON response conforming to a JSON schema.
TokenUsage
Token usage data from an LLM response.
ToolCall
A structured request to invoke one of the registered tools.
ToolSpec
JSON-schema description of a tool, sent verbatim to the model.

Enums§

StreamChunk
A single streamed delta emitted by a provider during a streaming LLM call.

Functions§

estimate_tokens
Rough token estimate for budget/breakdown display. Uses a bytes/4 heuristic (≈4 bytes/token for English; over-counts CJK ~3× because CJK chars are 3 UTF-8 bytes each). This is intentionally byte-based for speed (no char iteration) and is only an estimate — exact tokenization would require the provider’s tokenizer. Do not use for billing.

Type Aliases§

StreamSender
Channel sender for streaming partial deltas during a streaming LLM call. Each StreamChunk is a delta emitted by the provider.