lpgcast.extract¶
One extraction call: an episode and a slice in, the model's flat reply out.
The reply is parsed into the wire models below and nothing more. Whether a type exists, a property belongs to its vertex, a value fits its field or a quote is in the text are checked afterwards; the wire models only make sure the reply has the flat shape.
Attributes¶
CHARS_PER_TOKEN = 4
module-attribute
¶
INSTANCE_SCHEMA_NAME = 'lpg_instance'
module-attribute
¶
Scalar = str | int | float | bool
module-attribute
¶
Classes¶
EpisodeTooLongError
¶
Bases: ValueError
An episode over max_episode_tokens; episodes are never chunked.
Source code in lpgcast/extract.py
Extraction
¶
Bases: BaseModel
One episode's reply, with how it was obtained.
Source code in lpgcast/extract.py
WireEdge
¶
Bases: BaseModel
An edge the model read, between two refs.
Source code in lpgcast/extract.py
Attributes¶
from_ = Field(alias='from')
class-attribute
instance-attribute
¶
model_config = ConfigDict(extra='ignore', populate_by_name=True)
class-attribute
instance-attribute
¶
props = Field(default_factory=list)
class-attribute
instance-attribute
¶
quote = ''
class-attribute
instance-attribute
¶
relation = None
class-attribute
instance-attribute
¶
to
instance-attribute
¶
WireExtraction
¶
Bases: BaseModel
The model's whole reply. Missing lists read as empty; unknown keys are ignored.
Source code in lpgcast/extract.py
Attributes¶
edges = Field(default_factory=list)
class-attribute
instance-attribute
¶
model_config = ConfigDict(extra='ignore')
class-attribute
instance-attribute
¶
unmapped = Field(default_factory=list)
class-attribute
instance-attribute
¶
vertices = Field(default_factory=list)
class-attribute
instance-attribute
¶
WireProp
¶
Bases: BaseModel
A property the model read: name, value as written, and its quote.
Source code in lpgcast/extract.py
WireShapeError
¶
Bases: ValueError
A reply that is JSON but not the flat extraction shape.
Source code in lpgcast/extract.py
WireUnmapped
¶
Bases: BaseModel
Something the model saw and could not type.
Source code in lpgcast/extract.py
WireVertex
¶
Bases: BaseModel
A vertex the model read.
Source code in lpgcast/extract.py
Attributes¶
mention = False
class-attribute
instance-attribute
¶
model_config = ConfigDict(extra='ignore')
class-attribute
instance-attribute
¶
props = Field(default_factory=list)
class-attribute
instance-attribute
¶
quote = ''
class-attribute
instance-attribute
¶
ref
instance-attribute
¶
type
instance-attribute
¶
Functions:¶
estimate_episode_tokens(episode)
¶
Estimated tokens of the text and its context.
extract(client, slice_, episode, *, user_instruction=None, max_episode_tokens=None)
async
¶
Make the one extraction call for episode against slice_.
Raises:
| Type | Description |
|---|---|
EpisodeTooLongError
|
before any call, when the episode is over the ceiling. |
WireShapeError
|
the reply is a JSON object of the wrong shape. |
Any error of
|
|