vllm.tool_parsers.streaming
¶
Functions:
-
extract_named_tool_call_streaming–Build a streaming tool-call delta for forced named tool choice.
-
extract_required_tool_call_streaming–Stream the tool calls of a
tool_choice="required"JSON array.
_RequiredToolCallSpan
dataclass
¶
Where one element of a tool_choice="required" array sits in the text.
The model output for tool_choice="required" is a JSON array of
{"name": ..., "parameters": ...} objects. name is only set once
its string value is closed and decodes as JSON; name_end is the
offset just past that closing quote. args_start/args_end are the
character offsets of the parameters value (args_end is None
while the value is still being generated).
All offsets are prefix-stable: scanning any prefix of the text yields the same spans truncated to that prefix. That is what lets one scan of the current text tell what an earlier, shorter text had already revealed.
Methods:
-
ready_at–Whether the first
lengthcharacters of the text already made
Source code in vllm/tool_parsers/streaming.py
ready_at(length)
¶
Whether the first length characters of the text already made
this call streamable: its name was complete and its parameters value
had started.
Source code in vllm/tool_parsers/streaming.py
_scan_required_tool_calls(text)
¶
Locate every tool call of a (possibly partial) required-tool-call array.
A single string- and nesting-aware pass over text that records, for
each top-level array element, its name (once complete) and the
character span of its parameters value. Text after the closing ]
of the array is ignored. Only the element level of the array is
interpreted, so braces, brackets and quotes inside nested values and
strings cannot confuse it.
Source code in vllm/tool_parsers/streaming.py
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 | |
extract_named_tool_call_streaming(*, delta_text, function_name, function_name_returned, tool_call_idx, tool_call_id_type, tokenizer, tool_call_array_index=0)
¶
Build a streaming tool-call delta for forced named tool choice.
Source code in vllm/tool_parsers/streaming.py
extract_required_tool_call_streaming(*, previous_text, current_text, tool_call_idx, tool_call_id_type)
¶
Stream the tool calls of a tool_choice="required" JSON array.
previous_text must be a prefix of current_text (the accumulated
text before and after this delta). Every array element that has something
not yet sent is emitted, in array order, so a delta may carry several
DeltaToolCall entries: the first chunk of a call carries its id, name
and the arguments generated so far; later chunks carry only new argument
text. What was already sent is read off the same scan, since the spans
are prefix-stable, so no state is needed beyond the two texts.
Returns the delta (None when nothing is new) and whether at least one
call has been announced so far.