ontocast.tool.chunk.section_llm¶
LLM section tier: one call labels the document's outline, as weak votes.
The model is shown the document as an ordered list of regions: each headed section once (its heading line and the opening of its text), and each segment of unheaded text on its own. It returns one label per region, chosen from the schema's labels and their descriptions. Every segment of a region receives that label as weak evidence, so the model decides only where no other tier spoke; where it disagrees with another tier, the disagreement is kept in the evidence. A long outline is sent in consecutive windows. A failed call costs the votes of its window and nothing else.
Attributes¶
EXCERPT_MAX_CHARS = 300
module-attribute
¶
__all__ = ['EXCERPT_MAX_CHARS', 'OutlineLabels', 'OutlineRegion', 'RegionLabel', 'llm_label_outline', 'outline_regions', 'text_excerpt']
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
OutlineLabels
¶
Bases: BasePydanticModel
The model's labels for the numbered regions of one outline window.
Source code in ontocast/tool/chunk/section_llm.py
OutlineRegion
dataclass
¶
One region shown to the model and the segments its label applies to.
Source code in ontocast/tool/chunk/section_llm.py
RegionLabel
¶
Bases: BasePydanticModel
The section label the model gives one numbered region.
Source code in ontocast/tool/chunk/section_llm.py
Functions:¶
llm_label_outline(segments, tools, schema, *, document_type_hint=None, window=40)
async
¶
Add the model's vote to every segment and decide again (mutates in place).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments
|
list[PrepareSegment]
|
Prepare segments, in document order. |
required |
tools
|
ToolBox
|
ToolBox providing the LLM. |
required |
schema
|
SectionLabelSchema
|
The schema the document is typed against; labels outside it are discarded. |
required |
document_type_hint
|
str | None
|
Free-text document type, passed to the prompt. |
None
|
window
|
int
|
Regions per call. |
40
|
Returns:
| Type | Description |
|---|---|
OutlineLabelReport
|
How many windows were sent and which failed. |
Source code in ontocast/tool/chunk/section_llm.py
outline_regions(segments)
¶
The document's regions in order: each headed section once, unheaded segments each.
Source code in ontocast/tool/chunk/section_llm.py
text_excerpt(text, limit=EXCERPT_MAX_CHARS)
¶
The opening of text: its first line kept, the rest on one line.
A heading keeps its own line, so the model sees what names the region and what follows it as distinct.