Sequences
Extracting Sequences of Objects
Sequence is a wrapper class that can be used to represent a list of objects to be extracted by Instructor from provided context.
It is usually more convenient not create a dedicated class with a single array property just to handle a list of objects of a given class.
Streaming Sequences
Additional, unique feature of sequences is that they can be streamed per each completed item in a sequence, rather than on any property update.
NOTE This feature requires the
stream
option to be set totrue
.
To receive sequence updates provide a callback via Instructor’s
onSequenceUpdate()
that will be called each time a new item is received from LLM.
The callback provided a full sequence that has been retrieved so far. You can
get the last added object from the sequence via $sequence->last()
.
Remember that while the sequence is being updated, the data is not validated - only when the sequence is fully extracted, the objects are validated and a full sequence is returned (see example below).
Working with Sequences
Sequences offer array access (via ArrayAccess) and convenience methods to work with the list of extracted objects.
Streaming sequence updates
See: Streaming and partial updates for more information on how to get partial updates and streaming of sequences.