<?php
$text = <<<TEXT
Jason is 25 years old, he is an engineer and tech lead. He lives in
San Francisco. He likes to play soccer and climb mountains.
TEXT;
$stream = (new StructuredOutput)
//->wiretap(fn(Event $e) => $e->print())
->withMessages($text)
->withResponseClass(UserDetail::class)
->withStreaming()
->withOutputMode(OutputMode::Json)
->stream();
foreach ($stream->partials() as $partial) {
partialUpdate($partial);
}
$user = $stream->lastUpdate();
assert($user->name === 'Jason');
assert($user->age === 25);
?>