vllm.reasoning.abs_reasoning_parsers ¶
ReasoningParser ¶
Abstract reasoning parser class that should not be used directly. Provided and methods should be used in derived classes.
It is used to extract reasoning content from the model output.
Source code in vllm/reasoning/abs_reasoning_parsers.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 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 | |
__init__ ¶
__init__(tokenizer: AnyTokenizer, *args, **kwargs)
extract_content_ids abstractmethod ¶
Extract content token ids from the input_ids. Parameters: input_ids: list[int] The input_ids of the model output. Returns: list[int] The extracted content from the input_ids.
Source code in vllm/reasoning/abs_reasoning_parsers.py
extract_reasoning_content abstractmethod ¶
extract_reasoning_content(
model_output: str,
request: ChatCompletionRequest | ResponsesRequest,
) -> tuple[str | None, str | None]
Extract reasoning content from a complete model-generated string.
Used for non-streaming responses where we have the entire model response available before sending to the client.
model_output: str The model-generated string to extract reasoning content from.
ChatCompletionRequest
The request object that was used to generate the model_output.
tuple[Optional[str], Optional[str]] A tuple containing the reasoning content and the content.
Source code in vllm/reasoning/abs_reasoning_parsers.py
extract_reasoning_content_streaming abstractmethod ¶
extract_reasoning_content_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],
) -> DeltaMessage | None
Instance method that should be implemented for extracting reasoning from an incomplete response; for use when handling reasoning 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/reasoning/abs_reasoning_parsers.py
is_reasoning_end abstractmethod ¶
Check if the reasoning content ends in the input_ids.
It is used in structured engines like xgrammar to check if the reasoning content ends in the model output.
input_ids: list[int] The input_ids of the model output.
bool True if the reasoning content ends in the input_ids.
Source code in vllm/reasoning/abs_reasoning_parsers.py
prepare_structured_tag ¶
prepare_structured_tag(
original_tag: str | None, tool_server: ToolServer | None
) -> str
Instance method that is implemented for preparing the structured tag Otherwise, None is returned
Source code in vllm/reasoning/abs_reasoning_parsers.py
ReasoningParserManager ¶
Central registry for ReasoningParser implementations.
Supports two registration modes
- Eager registration via
register_module - Lazy registration via
register_lazy_module
Each reasoning parser must inherit from ReasoningParser.
Source code in vllm/reasoning/abs_reasoning_parsers.py
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 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
reasoning_parsers class-attribute instance-attribute ¶
reasoning_parsers: dict[str, type[ReasoningParser]] = {}
_load_lazy_parser classmethod ¶
_load_lazy_parser(name: str) -> type[ReasoningParser]
Import and register a lazily loaded reasoning parser.
Source code in vllm/reasoning/abs_reasoning_parsers.py
_register_module classmethod ¶
_register_module(
module: type[ReasoningParser],
module_name: str | list[str] | None = None,
force: bool = True,
) -> None
Register a ReasoningParser class immediately.
Source code in vllm/reasoning/abs_reasoning_parsers.py
get_reasoning_parser classmethod ¶
get_reasoning_parser(name: str) -> type[ReasoningParser]
Retrieve a registered or lazily registered ReasoningParser class.
If the parser is lazily registered, it will be imported and cached on first access.
Raises:
| Type | Description |
|---|---|
KeyError | if no parser is found under the given name. |
Source code in vllm/reasoning/abs_reasoning_parsers.py
import_reasoning_parser classmethod ¶
import_reasoning_parser(plugin_path: str) -> None
Import a user-defined reasoning parser by the path of the reasoning parser define file.
Source code in vllm/reasoning/abs_reasoning_parsers.py
list_registered classmethod ¶
Return names of all eagerly and lazily registered reasoning parsers.
register_lazy_module classmethod ¶
Register a lazy module mapping for delayed import.
Example
ReasoningParserManager.register_lazy_module( name="qwen3", module_path="vllm.reasoning.parsers.qwen3_reasoning_parser", class_name="Qwen3ReasoningParser", )
Source code in vllm/reasoning/abs_reasoning_parsers.py
register_module classmethod ¶
register_module(
name: str | list[str] | None = None,
force: bool = True,
module: type[ReasoningParser] | None = None,
) -> (
type[ReasoningParser]
| Callable[
[type[ReasoningParser]], type[ReasoningParser]
]
)
Register module with the given name or name list. it can be used as a decoder(with module as None) or normal function(with module as not None).