Skip to main content

Module common

Module common 

Source

Functions§

append_normalized_reasoning_detail_items
assistant_interleaved_history_text
Rehydrates assistant history into the tagged form expected by interleaved thinking models.
collect_history_system_directives
Collects non-empty history system directives that should be preserved when a provider accepts a separate top-level system prompt but cannot reliably consume follow-up system chat messages.
convert_usage_to_llm_types
Converts provider Usage to llm_types::Usage. Shared by all LLMClient implementations.
ensure_model
Ensures the request has a non-empty model, falling back to the provider’s default. Mutates the request in place and returns the resolved model string.
execute_token_count_request
Execute an exact token-count request when provider endpoint is available. Returns Ok(None) when endpoint appears unsupported.
extract_content_from_message
Extracts content from a message value, handling both string and array formats.
extract_prompt_cache_settings
extract_prompt_cache_settings_default
extract_reasoning_text_from_detail_values
extract_reasoning_text_from_serialized_details
forward_prompt_cache_with_state
get_http_client_for_timeouts
Get or create HTTP client with custom timeouts
is_interleaved_thinking_model
Returns true when the model family relies on interleaved <think>...</think> history to maintain reasoning quality across turns.
is_minimax_m2_model
Returns true when the model identifier points to MiniMax M2 family models. Works across direct model ids and provider-qualified ids.
make_anthropic_thinking_config
Generates the interleaved thinking configuration for Anthropic models. This provides consistent thinking configuration across all Anthropic provider implementations.
make_default_request
Creates a default LLM request with a single user message. Used by all providers for their LLMClient implementation.
map_finish_reason_common
Maps common finish reason strings to FinishReason enum. Handles standard OpenAI-compatible finish reasons.
merge_system_prompt_with_history_directives
Merges a base system prompt with history directives using a simple bulleted section. Providers with custom cache shaping can reuse the collected directives and apply their own section placement.
normalize_reasoning_detail_object
Normalizes a reasoning detail into an object payload. Accepts native objects or stringified JSON objects, and rejects everything else.
normalize_reasoning_detail_objects
override_base_url
parse_chat_request_openai_format
Parses chat request from OpenAI-compatible JSON format. Used by DeepSeek, ZAI, OpenRouter, and other OpenAI-compatible providers.
parse_chat_request_openai_format_with_extractor
Parses chat request with custom content extraction logic. Use this when provider has special content format (e.g., array of content blocks).
parse_client_prompt_common
Parses a client prompt that may be a JSON chat request or plain text. Returns a parsed LLMRequest from JSON if valid, or a default request with the prompt.
parse_json_response
Parses a JSON response body from an HTTP response, mapping errors to LLMError::Provider with a formatted message including the provider name.
parse_prompt_tokens_from_count_response
Parse prompt/input token counts from common response shapes.
parse_response_openai_format
Parses OpenAI-compatible response format. Used by DeepSeek, Moonshot, and other OpenAI-compatible providers.
parse_tool_call_openai_format
Parses a tool call from OpenAI-compatible JSON format. Works for DeepSeek, ZAI, and other OpenAI-compatible providers.
parse_usage_openai_format
Parses usage information from OpenAI-compatible response format.
preserve_interleaved_content_in_reasoning_details
Stores the exact interleaved assistant content alongside normalized reasoning so later turns can replay the original tagged history.
resolve_model
serialize_message_content_openai
Serialize message content for OpenAI-compatible chat payloads. Falls back to a string when there are no image parts.
serialize_message_content_openai_for_model
Serialize message content for OpenAI-compatible payloads while preserving interleaved thinking history for supported assistant models.
serialize_message_content_openai_for_role
Serialize message content for OpenAI-compatible payloads and normalize tool response content to plain text where required.
serialize_messages_openai_format
Serializes messages to OpenAI-compatible JSON format. Used by DeepSeek, Moonshot, and other OpenAI-compatible providers.
serialize_reasoning_detail_values
serialize_reasoning_details_field
serialize_tools_openai_format
Serializes tool definitions to OpenAI-compatible JSON format. Used by DeepSeek, ZAI, Moonshot, and other OpenAI-compatible providers. For OpenAI-specific features (GPT-5.1 native tools), use OpenAIProvider’s serialize_tools.
spawn_openai_compatible_stream
Spawns an OpenAI-compatible streaming response handler. Returns an LLMStream backed by a tokio task that processes chunks via process_openai_stream with the handle_openai_compatible_chunk handler.
strip_generation_controls_for_token_count
Remove generation-only controls from a payload before exact prompt-token counting. Token-count endpoints generally require only prompt-side fields.
validate_request_common
Validates an LLM request with common checks. Checks for empty messages and validates each message for the given provider.
validate_supported_models
Validates a request against a static list of supported model strings. Convenience wrapper around validate_request_common that converts &[&str] to Vec<String> internally.