This feature requires theTo receive partial results definestream
option to be set totrue
.
onPartialUpdate()
callback that will be called
on every update of the deserializad object.
Instructor is smart about updates, it calculates and compares hashes of the previous
and newly deserialized version of the model, so you won’t get them on every token
received, but only when any property of the object is updated.
get()
call is fully validated, so you can safely work
with it, e.g. save it to the database.
stream()
method instead of get()
. The stream()
method is available on both StructuredOutput
and PendingStructuredOutput
instances.
StructuredOutputStream
object, which gives you access to the response streamed from LLM and processed by Instructor into structured data.
StructuredOutputStream
class provides comprehensive methods for processing streaming responses:
partials()
: Returns an iterable of partial updates from the stream. Only final update is validated, partial updates are only deserialized and transformed.sequence()
: Dedicated to processing Sequence
response models - returns only completed items in the sequence.responses()
: Generator of partial LLM responses as they are received.finalValue()
: Get the final parsed result (blocks until completion).finalResponse()
: Get the final LLM response (blocks until completion).lastUpdate()
: Returns the last object received and processed by Instructor.lastResponse()
: Returns the last received LLM response.usage()
: Get token usage statistics from the streaming response.