Skip to main content

Module utils

Module utils 

Source
Expand description

Shared utilities for LLM request/response processing

This module provides common functions used across multiple providers to eliminate duplicate code and reduce allocations.

Functionsยง

estimate_token_count
Estimate token count from string (rough approximation)
extract_reasoning_content
Extract reasoning content from text (for providers that support reasoning)
format_llm_error
Create a consistent error message for LLM errors
parse_chat_request_openai_format
Parse chat request from OpenAI-compatible format
parse_response_openai_format
Parse response from OpenAI-compatible format
parse_stream_event_openai_format
Parse stream event from OpenAI-compatible format
truncate_to_token_limit
Truncate string to approximate token limit
validate_model_string
Validate that a model string is not empty and reasonable