Re2 (Re-Reading) is a technique that asks the model to read the question again.
<?php
$loader = require 'vendor/autoload.php';
$loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/');
use Cognesy\Instructor\Instructor;
use Cognesy\Instructor\Schema\Attributes\Description;
class Response {
#[Description("Repeat user's query.")]
public string $query;
#[Description("Let's think step by step.")]
public string $thoughts;
public int $answer;
}
class RereadAndRespond {
public function __invoke(string $query) : Response {
return (new Instructor)->respond(
messages: $query,
responseModel: Response::class,
);
}
}
$response = (new RereadAndRespond)(
query: <<<QUERY
Roger has 5 tennis balls. He buys 2 more cans of tennis balls.
Each can has 3 tennis balls.
How many tennis balls does he have now?
QUERY,
);
echo "Answer:\n";
dump($response);
?>