markup

package
v1.833.384 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Quotes added in v1.833.377

func Quotes(model, text string) bool

Quotes reports whether text holds an opener of the family serving model: a request that already carries one could be asking the model to echo a call.

func Reads added in v1.833.377

func Reads(model string) bool

Reads reports whether the family serving model has markup that is lifted.

Types

type Call

type Call struct {
	ID        string
	Name      string
	Arguments string
}

Call is one lifted tool call. Arguments is a JSON object, encoded.

func Lift

func Lift(content string, r Rules) (string, []Call)

Lift returns content with its trailing tool-call blocks removed and the calls they held. Content with no liftable block is returned as it came.

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

func RulesFor(body []byte, upstream string, strict bool) (Rules, bool)

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

func NewScanner(r Rules) *Scanner

NewScanner returns a scanner lifting the calls r allows.

func (*Scanner) Feed

func (s *Scanner) Feed(delta string) string

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

func (s *Scanner) Flush() (string, []Call)

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.

func (*Scanner) Held

func (s *Scanner) Held() bool

Held reports whether the scanner is keeping text back.

func (*Scanner) Release added in v1.833.377

func (s *Scanner) Release() string

Release ends the stream and returns whatever was held as text, lifting nothing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL