This approach to “chain of thought” improves data quality, by eliciting LLM reasoning to
self-explain approach to generating the response.
<?php
$loader = require 'vendor/autoload.php';
$loader->add('Cognesy\\Instructor\\', __DIR__.'../../src/');
use Cognesy\Instructor\Features\Schema\Attributes\Instructions;
use Cognesy\Instructor\Instructor;
class Employee {
#[Instructions('Think step by step to determine the correct year of employment.')]
public string $reasoning;
public int $yearOfEmployment;
}
$text = 'He was working here for 5 years. Now, in 2019, he is a manager.';
$employee = (new Instructor)->respond(
messages: [['role' => 'user', 'content' => $text]],
responseModel: Employee::class
);
dump($employee);
assert($employee->yearOfEmployment === 2014);
?>