<?php
require 'examples/boot.php';
use Cognesy\Instructor\Extras\Sequence\Sequence;
use Cognesy\Instructor\StructuredOutput;
class Person
{
public string $name;
public int $age;
}
$text = <<<TEXT
Jason is 25 years old. Jane is 18 yo. John is 30 years old. Anna is 2 years younger than him.
TEXT;
print("INPUT:\n$text\n\n");
print("OUTPUT:\n");
$stream = StructuredOutput::using('openai')
//->wiretap(fn($e) => $e->print())
->with(
messages: $text,
responseModel: Sequence::of(Person::class),
options: ['stream' => true],
)
->stream();
foreach ($stream->sequence() as $sequence) {
dump($sequence->last());
}
$list = $stream->finalValue();
dump(count($list));
assert(count($list) === 4);
?>