Skip to main content

Module helpers

Module helpers 

Source

Functions§

ends_with_partial_token
Check if a buffer ends with a partial occurrence of a token Returns Some(length) if there’s a partial match, None otherwise
ensure_capacity
Ensure arrays have capacity for the given tool ID
find_common_prefix
Find the common prefix of two strings Used for incremental argument streaming when partial JSON returns different intermediate states
get_tool_indices
Get a mapping of tool names to their indices
get_unstreamed_args
Get unstreamed tool call arguments Returns tool call items for arguments that have been parsed but not yet streamed This ensures tool calls are properly completed even if the model generates final arguments in the last chunk
is_complete_json
Check if a string contains complete, valid JSON
normalize_arguments_field
Normalize the arguments/parameters field in a tool call object. If the object has “parameters” but not “arguments”, copy parameters to arguments.
normalize_name_field
Normalize the name/tool_name field in a tool call object. If the object has “tool_name” but not “name”, copy tool_name to name.
normalize_tool_call_fields
Normalize all tool call fields (both name and arguments). Combines normalize_name_field and normalize_arguments_field.
reset_current_tool_state
Reset state for the current tool being parsed (used when skipping invalid tools). This preserves the parser’s overall state (current_tool_id, prev_tool_call_arr) but clears the state specific to the current incomplete tool.
reset_parser_state
Reset the entire parser state (used at the start of a new request). Clears all accumulated tool calls and resets all state to initial values.