vllm.entrypoints.openai.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.
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
__init__ ¶
__init__(tokenizer: AnyTokenizer)
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
adjust_request ¶
adjust_request(
request: ChatCompletionRequest,
) -> ChatCompletionRequest
Static method that used to adjust the request parameters.
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
extract_tool_calls ¶
extract_tool_calls(
model_output: str, request: ChatCompletionRequest
) -> ExtractedToolCallInformation
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.
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
extract_tool_calls_streaming ¶
extract_tool_calls_streaming(
previous_text: str,
current_text: str,
delta_text: str,
previous_token_ids: Sequence[int],
current_token_ids: Sequence[int],
delta_token_ids: Sequence[int],
request: ChatCompletionRequest,
) -> DeltaMessage | None
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)
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
ToolParserManager ¶
Central registry for ToolParser implementations.
Supports two modes
- Eager (immediate) registration via
register_module - Lazy registration via
register_lazy_module
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
_load_lazy_parser classmethod ¶
_load_lazy_parser(name: str) -> type[ToolParser]
Import and register a lazily loaded parser.
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
_register_module classmethod ¶
_register_module(
module: type[ToolParser],
module_name: str | list[str] | None = None,
force: bool = True,
) -> None
Register a ToolParser class immediately.
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
get_tool_parser classmethod ¶
get_tool_parser(name: str) -> type[ToolParser]
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.
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
import_tool_parser classmethod ¶
import_tool_parser(plugin_path: str) -> None
Import a user-defined parser file from arbitrary path.
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
list_registered classmethod ¶
Return names of all eagerly and lazily registered tool parsers.
register_lazy_module classmethod ¶
Register a lazy module mapping.
Example
ToolParserManager.register_lazy_module( name="kimi_k2", module_path="vllm.entrypoints.openai.tool_parsers.kimi_k2_parser", class_name="KimiK2ToolParser", )
Source code in vllm/entrypoints/openai/tool_parsers/abstract_tool_parser.py
register_module classmethod ¶
register_module(
name: str | list[str] | None = None,
force: bool = True,
module: type[ToolParser] | None = None,
) -> (
type[ToolParser]
| Callable[[type[ToolParser]], type[ToolParser]]
)
Register module immediately or lazily (as a decorator).
Usage
@ToolParserManager.register_module("kimi_k2") class KimiK2ToolParser(ToolParser): ...
Or
ToolParserManager.register_module(module=SomeToolParser)