vllm.tool_parsers.abstract_tool_parser
¶
ToolParser
¶
Abstract ToolParser class that should not be used directly. Provided properties and methods should be used in derived classes.
Methods:
-
extract_tool_calls–Static method that should be implemented for extracting tool calls from
-
extract_tool_calls_streaming–Instance method that should be implemented for extracting tool calls
-
get_remaining_unstreamed_args–Return tool call arguments parsed but not yet streamed.
extract_tool_calls(model_output, request)
¶
Static method that should be implemented for extracting tool calls from a complete model-generated string. Used for non-streaming responses where we have the entire model response available before sending to the client. Static because it's stateless.
extract_tool_calls_streaming(previous_text, current_text, delta_text, previous_token_ids, current_token_ids, delta_token_ids, request)
¶
Instance method that should be implemented for extracting tool calls from an incomplete response; for use when handling tool calls and streaming. Has to be an instance method because it requires state - the current tokens/diffs, but also the information about what has previously been parsed and extracted (see constructor)
get_remaining_unstreamed_args()
¶
Return tool call arguments parsed but not yet streamed.
ToolParserManager
¶
Central registry for ToolParser implementations.
Supports two modes
- Eager (immediate) registration via
register_module - Lazy registration via
register_lazy_module
Methods:
-
get_tool_parser–Retrieve a registered or lazily registered ToolParser class.
-
import_tool_parser–Import a user-defined tool parser.
-
list_registered–Return names of all eagerly and lazily registered tool parsers.
-
register_lazy_module–Register a lazy module mapping.
-
register_module–Register module immediately or lazily (as a decorator).
_load_lazy_parser(name)
classmethod
¶
Import and register a lazily loaded parser.
_register_module(module, module_name=None, force=True)
classmethod
¶
Register a ToolParser class immediately.
get_tool_parser(name)
classmethod
¶
Retrieve a registered or lazily registered ToolParser class.
If the parser is lazily registered, it will be imported and cached on first access. Raises KeyError if not found.
import_tool_parser(plugin_path)
classmethod
¶
Import a user-defined tool parser.
list_registered()
classmethod
¶
Return names of all eagerly and lazily registered tool parsers.
register_lazy_module(name, module_path, class_name)
classmethod
¶
Register a lazy module mapping.
Example
ToolParserManager.register_lazy_module( name="kimi_k2", module_path="vllm.tool_parsers.kimi_k2_parser", class_name="KimiK2ToolParser", )
register_module(name=None, force=True, module=None)
classmethod
¶
Register module immediately or lazily (as a decorator).
Usage
@ToolParserManager.register_module("kimi_k2") class KimiK2ToolParser(ToolParser): ...
Or
ToolParserManager.register_module(module=SomeToolParser)