Skip to main content

Crate sim_codec_chat

Crate sim_codec_chat 

Source
Expand description

Canonical chat transcript codec for SIM.

This crate provides codec:chat, a provider-neutral text format for model request, response, event, and card transcripts represented as Expr::Map values.

Re-exports§

pub use providers::anthropic::AnthropicCodec;
pub use providers::anthropic::AnthropicCodecLib;
pub use providers::anthropic::AnthropicCodecOptions;
pub use providers::anthropic::AnthropicRequestOptions;
pub use providers::anthropic::anthropic_codec_symbol;
pub use providers::anthropic::decode_anthropic_request;
pub use providers::anthropic::decode_anthropic_response;
pub use providers::anthropic::decode_anthropic_stream;
pub use providers::anthropic::decode_anthropic_stream_events;
pub use providers::anthropic::encode_anthropic_request;
pub use providers::anthropic::encode_anthropic_response;
pub use providers::lemonade::LemonadeCodec;
pub use providers::lemonade::LemonadeCodecLib;
pub use providers::lemonade::LemonadeCodecOptions;
pub use providers::lemonade::LemonadeRequestOptions;
pub use providers::lemonade::decode_lemonade_request;
pub use providers::lemonade::decode_lemonade_response;
pub use providers::lemonade::decode_lemonade_stream;
pub use providers::lemonade::encode_lemonade_request;
pub use providers::lemonade::encode_lemonade_response;
pub use providers::lemonade::lemonade_codec_symbol;
pub use providers::lm_studio::LmStudioCodec;
pub use providers::lm_studio::LmStudioCodecLib;
pub use providers::lm_studio::LmStudioCodecOptions;
pub use providers::lm_studio::LmStudioRequestOptions;
pub use providers::lm_studio::decode_lm_studio_request;
pub use providers::lm_studio::decode_lm_studio_response;
pub use providers::lm_studio::decode_lm_studio_stream;
pub use providers::lm_studio::encode_lm_studio_request;
pub use providers::lm_studio::encode_lm_studio_response;
pub use providers::lm_studio::lm_studio_codec_symbol;
pub use providers::openai::OpenAiCodec;
pub use providers::openai::OpenAiCodecLib;
pub use providers::openai::OpenAiCodecOptions;
pub use providers::openai::OpenAiRequestOptions;
pub use providers::openai::decode_openai_request;
pub use providers::openai::decode_openai_response;
pub use providers::openai::decode_openai_stream;
pub use providers::openai::encode_openai_request;
pub use providers::openai::encode_openai_response;
pub use providers::openai::openai_codec_symbol;
pub use providers::profile::CodecProfile;
pub use providers::profile::RequestWire;
pub use providers::profile::StreamWire;
pub use providers::profile::anthropic_profile;
pub use providers::profile::lemonade_profile;
pub use providers::profile::lm_studio_profile;
pub use providers::profile::ollama_profile;
pub use providers::profile::openai_profile;

Modules§

providers
Provider-specific chat wire codecs built on the canonical transcript shape.

Structs§

ChatCodec
Provider-neutral transcript codec.
ChatCodecLib
Host-registered lib for codec:chat, built on the shared DomainCodecLib scaffold.
OllamaCodec
Runtime codec for Ollama chat JSON and NDJSON response bodies.
OllamaCodecLib
Host-registered lib for codec:ollama.
OllamaRequestOptions
Options controlling how a chat model-request transcript is projected into an Ollama JSON request body.

Statics§

RECIPES
Cookbook recipes for this codec, embedded at build time.

Functions§

decode_ollama_response
Decodes a non-streamed Ollama JSON response body into a canonical model-response transcript attributed to runner and model.
decode_ollama_stream
Decodes a newline-delimited Ollama streaming response body into a single canonical model-response transcript attributed to runner and model.
encode_ollama_request
Encodes a chat model-request transcript into an Ollama JSON request body.
is_model_request_expr
Returns true when expr is a chat transcript map carrying a true model-request marker.
model_card_expr
Builds a model-card transcript map describing a model’s identity and capabilities (provider, locality, modalities, and stream/tool/JSON/shape support), with conservative defaults the caller can override.
model_error_expr
Builds a model-response transcript carrying an error: a single text content part holding message, a stop-reason of error, and text/shape-ok fields recording the failure.
model_request_messages_expr
Returns the messages list of a model-request transcript, erroring if expr is not a valid request or its messages field is not a list.
model_response_expr
Builds a model-response transcript map from a runner, model name, content parts, and stop_reason.
number_field
A numbers/f64-domain map entry (name, value) for usage and metric records.
text_part
A chat text content part: the map {type: text, text: <text>}.
usage_record
The canonical token-usage entries built from optional counts, in the fixed order input-tokens, output-tokens, total-tokens. Each present count becomes one number_field; absent counts are skipped. The caller decides how to wrap the result, because providers differ: some emit a usage map even when empty, others omit usage entirely when no counts are present.
validate_chat_transcript
Validates that expr is a well-formed chat transcript and fails closed otherwise.