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
__init__
¶
__init__(tokenizer: AnyTokenizer)
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
) -> tuple[Optional[str], Optional[str]]
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],
) -> Union[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
ReasoningParserManager
¶
Source code in vllm/reasoning/abs_reasoning_parsers.py
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 |
|
_register_module
classmethod
¶
_register_module(
module: type,
module_name: Optional[Union[str, list[str]]] = None,
force: bool = True,
) -> None
Source code in vllm/reasoning/abs_reasoning_parsers.py
get_reasoning_parser
classmethod
¶
get_reasoning_parser(
name: str | None,
) -> type[ReasoningParser]
Get reasoning parser by name which is registered by register_module
.
Raise a KeyError exception if the name is not registered.
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
register_module
classmethod
¶
register_module(
name: Optional[Union[str, list[str]]] = None,
force: bool = True,
module: Union[type, None] = None,
) -> Union[type, Callable]
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).