vllm.parser.inkling
¶
Inkling parser: typed content blocks parsed by a single state machine.
Inkling output format (every marker is a dedicated special token)::
<|message_model|><|content_thinking|>...reasoning...<|end_message|>
<|message_model|><|content_text|>...visible text...<|end_message|>
<|message_model|><|content_invoke_tool_json|>
{"name":"get_weather","args":{"city":"SF"}}<|end_message|>
Blocks are self-describing and may repeat in any order; sampling may
also end a block with the standalone <|content_model_end_sampling|>
token. The tool-call payload is a single JSON object whose name is
extracted by the engine's name-from-args path and whose args object
is carved out of the wrapper by _inkling_arg_converter.
Note the terminal labels: THINK_START/THINK_END are what the
engine keys its reasoning plumbing on (is_reasoning_end,
count_reasoning_tokens, initial-state seeding), so <|end_message|>
is labelled THINK_END here even though it ends every block kind —
the transition table, not the label, carries the semantics.
Classes:
InklingParser
¶
Bases: ParserEngine
Methods:
-
adjust_initial_state_from_prompt–Seed the initial parsing state from the prompt tail.
-
adjust_request–Frame an Inkling2 JSON response format with the block grammar.
_inkling2_is_reasoning_end(input_ids)
¶
Whether the latest block is a text block of a model message.
A prompt that ends between messages has not ended reasoning: the model may open a thinking block.
adjust_initial_state_from_prompt(prompt_token_ids)
¶
Seed the initial parsing state from the prompt tail.
Mirrors the Rust parser's initialize(): scanning the prompt
backwards, the last relevant special token decides whether generation
continues inside a thinking block, a text block, a model message
header, or between blocks.
adjust_request(request)
¶
Frame an Inkling2 JSON response format with the block grammar.
As in the reference, any number of free thinking blocks precede the final text block, whose payload alone must match the JSON constraint; the API then returns that payload as the content.
_inkling_arg_converter(raw_args, partial)
¶
Carve the args object out of the tool-call JSON wrapper.
Why a converter at all: the engine's tool_args_json machinery
treats the entire TOOL_ARGS text as the tool arguments, but Inkling's
payload is the {"name":...,"args":{...}} wrapper — without a
converter, _compute_arg_delta streams the wrapper verbatim into
the OpenAI arguments field (converter is None -> raw delta,
unconditionally; stream_arg_deltas=False does not stop it).
extract_json_member_object returns a prefix-stable verbatim
substring, which the engine's argument-delta diffing requires.
_inkling_arg_value_extender(raw_args)
¶
Extend the open trailing value of the args object until it closes.
_inkling_arg_converter returns a verbatim span of raw_args, so while
the last member value is open every delta appends to the converted JSON
as is: a string streams it, other values are held by the engine without
re-running the converter. Returns None before the value starts, so the
converter decides whether a string value may stream.