Documentation
¶
Overview ¶
Package markup lifts a model's tool calls out of assistant text.
A model writes a tool call in its own markup — DeepSeek's DSML or its fenced form, Qwen's and Hermes's <tool_call> JSON or XML. The stack serving the model turns that markup into structured tool_calls, and when it misses (the model wrote prose first, then the block) the markup arrives as content and the caller never sees a call. Lift and Scanner do that parse here.
A call is lifted only when its name is one the request offered, and a block with any invalid invoke is left as the text it arrived as: this never invents a call. Only the markup of the family serving the model is read, only blocks that end the answer are lifted, and nothing inside a code fence or inline code is: a model quoting a block is not calling it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Rules ¶ added in v1.833.377
type Rules struct {
Offered map[string]bool
Model string // the upstream model id: its family picks the markup read
Only string // when set, the one tool that may be lifted
One bool // at most one call, for a request that forbade parallel calls
}
Rules says what a scanner may lift.
func RulesFor ¶ added in v1.833.381
RulesFor is what may be lifted from the answer to a chat request body served by the upstream model: the tools the request offered, and nothing (false) when it offered none, forbade calling them, named a function the legacy way, asked to be served unchanged (strict), or carries markup of the model's family in a message.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner is Lift over a stream of content deltas. Text passes through as soon as it cannot be the start of a block; from the first byte that could begin one the scanner holds, until the block is known to be text or the stream ends. At the end it lifts the held blocks if they closed and only whitespace follows, and otherwise lets them go as text. Whitespace between the text and a lifted block is dropped, so the text a stream yields equals the text Lift returns, whatever the split.
func NewScanner ¶
NewScanner returns a scanner lifting the calls r allows.
func (*Scanner) Feed ¶
Feed takes the next delta and returns the text now known to be text. The calls come at Flush: a block is lifted only once nothing but whitespace follows it.
func (*Scanner) Flush ¶
Flush ends the stream. When what is held is one or more closed blocks with only whitespace after them, it returns their calls; otherwise it returns what was held as text.