vllm.entrypoints.openai.tool_parsers.utils
consume_space
¶
extract_intermediate_diff
¶
Given two strings, extract the difference in the middle between two strings that are known to have a common prefix and/or suffix.
This function is provided as a UTILITY for extracting information from JSON generated by partial_json_parser, to help in ensuring that the right tokens are returned in streaming, so that close-quotes, close-brackets and close-braces are not returned prematurely. The order of arguments IS important - the new version of the partially-parsed JSON must be the first argument, and the secnod argument must be from the previous generation.
What it returns, is tokens that should be streamed to the client.
e.g. extract_intermediate_diff('{"fruit": "apple"}', '{"fruit": "ap"}') -> 'ple'
Source code in vllm/entrypoints/openai/tool_parsers/utils.py
find_all_indices
¶
Find all (starting) indices of a substring in a given string. Useful for tool call extraction
Source code in vllm/entrypoints/openai/tool_parsers/utils.py
find_common_prefix
¶
Finds a common prefix that is shared between two strings, if there is one. Order of arguments is NOT important.
This function is provided as a UTILITY for extracting information from JSON generated by partial_json_parser, to help in ensuring that the right tokens are returned in streaming, so that close-quotes, close-brackets and close-braces are not returned prematurely.
e.g. find_common_prefix('{"fruit": "ap"}', '{"fruit": "apple"}') -> '{"fruit": "ap'
Source code in vllm/entrypoints/openai/tool_parsers/utils.py
find_common_suffix
¶
Finds a common suffix shared between two strings, if there is one. Order of arguments is NOT important. Stops when the suffix ends OR it hits an alphanumeric character
e.g. find_common_suffix('{"fruit": "ap"}', '{"fruit": "apple"}') -> '"}'