Skip to main content

Module utils

Module utils 

Source

Structs§

RequestLog

Enums§

ImageFormat

Constants§

LOGS_TO_KEEP

Functions§

convert_image
Convert an image content into an image json based on format
detect_image_path
Detect if a string contains a path to an image file
filter_extensions_from_system_prompt
get_model
Extract the model name from a JSON object. Common with most providers to have this top level attribute.
handle_response_google_compat
Handle response from Google Gemini API-compatible endpoints.
handle_response_openai_compat
handle_status_openai_compat
is_google_model
is_valid_function_name
json_escape_control_chars_in_string
Helper to escape control characters in a string that is supposed to be a JSON document. This function iterates through the input string s and replaces any literal control characters (U+0000 to U+001F) with their JSON-escaped equivalents (e.g., ‘\n’ becomes “\n”, ‘\u0001’ becomes “\u0001”).
load_image_file
Convert a local image file to base64 encoded ImageContent
map_http_error_to_provider_error
safely_parse_json
Safely parse a JSON string that may contain doubly-encoded or malformed JSON. This function first attempts to parse the input string as-is. If that fails, it applies control character escaping and tries again.
sanitize_function_name
stream_openai_compat
unescape_json_values