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 theTo receive sequence updates provide a callback via Instructor’sstream
option to be set totrue
.
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).