pig_protocol/codec/chat

Values

pub fn build_request_body(
  messages: List(message.Message),
  tools: List(tool_definition.ToolDefinition),
  model: String,
) -> String

Build the JSON request body for the OpenAI Chat Completions API. Pure function — no IO.

pub fn build_request_body_with_thinking(
  messages: List(message.Message),
  tools: List(tool_definition.ToolDefinition),
  model: String,
  thinking_level: option.Option(thinking.ThinkingLevel),
) -> String

Build a Chat Completions request with an optional thinking level.

OpenAI-shaped APIs receive this as reasoning_effort. Unsupported levels are reported by the provider API.

pub fn build_stream_request_body(
  messages: List(message.Message),
  tools: List(tool_definition.ToolDefinition),
  model: String,
) -> String

Build a Chat Completions request body for an SSE response.

The buffered builder remains unchanged for callers that own the request lifecycle. Streaming requests opt into the usage trailer explicitly.

pub fn build_stream_request_body_with_thinking(
  messages: List(message.Message),
  tools: List(tool_definition.ToolDefinition),
  model: String,
  thinking_level: option.Option(thinking.ThinkingLevel),
) -> String

Build a streaming Chat Completions request with an optional thinking level.

pub fn parse_response(
  raw: String,
) -> Result(inference.InferenceResult, error.AiError)

Parse an OpenAI Chat Completions JSON response into an InferenceResult. Pure function — no IO.

Search Document