yera.models.interfaces.llms._thinking

Utility functions for parsing model reasoning output with delimiters.

Symbols

def can_disable — Return whether reasoning can be disabled for a model.
def effort_to_budget — Map a reasoning effort level to a token budget.
def floor_level — Return the least intensive supported reasoning level.
def resolve_effort — Validate a requested reasoning effort against model capabilities.
class ThinkingParser — A parser for model output that separates thinking and response content.

can_disable

can_disable(
    capabilities: LLMCapabilities,
) → bool

Return whether reasoning can be disabled for a model.

Parameters

capabilities
type: LLMCapabilities

Model reasoning capabilities.

Returns

type: bool

Whether the model accepts the off reasoning level.

effort_to_budget

effort_to_budget(
    level: ReasoningLevel,
) → int

Map a reasoning effort level to a token budget.

Parameters

level
type: ReasoningLevel

Reasoning effort level to translate.

Returns

type: int

The corresponding reasoning-token budget.

Raises

ValueError

If the level has no fixed budget mapping.

floor_level

floor_level(
    capabilities: LLMCapabilities,
) → ReasoningLevel | None

Return the least intensive supported reasoning level.

Parameters

capabilities
type: LLMCapabilities

Model reasoning capabilities.

Returns

type: ReasoningLevel | None

The lowest supported effort level, or None when none is declared.

resolve_effort

resolve_effort(
    requested: ReasoningLevel,
    capabilities: LLMCapabilities,
) → ReasoningLevel

Validate a requested reasoning effort against model capabilities.

Parameters

requested
type: ReasoningLevel

Requested reasoning effort.

capabilities
type: LLMCapabilities

Model reasoning capabilities.

Returns

type: ReasoningLevel

The validated reasoning effort.

Raises

ValueError

If the requested effort is unsupported or reasoning cannot be disabled.

ThinkingParser

A parser for model output that separates thinking and response content.

Attributes

_start

The delimiter marking the start of thinking content.

_end

The delimiter marking the end of thinking content.

_active

Whether the parser is currently in a thinking block.

_starts_thinking

Whether the first block should be considered thinking.

Methods

__init__ — Initialize a streaming reasoning parser.
parse_stream — Convert a stream of raw text chunks into classified tokens.

ThinkingParser.__init__

__init__(
    start_delimiter: str = '',
    end_delimiter: str = '',
    starts_thinking: bool = False,
)

Initialize a streaming reasoning parser.

Parameters

start_delimiter
type: str = ''

Marker opening reasoning content.

end_delimiter
type: str = ''

Marker closing reasoning content.

starts_thinking
type: bool = False

Whether content begins inside a reasoning block.

Raises

ValueError

If either delimiter is empty.

ThinkingParser.parse_stream

parse_stream(
    stream: Iterator[str],
) → Iterator[LLMToken]

Convert a stream of raw text chunks into classified tokens.

Parameters

stream
type: Iterator[str]

Chunks of model output, of any size.