Skip to main content
static public function infer( string|array messages,//(required)Themessage(s)toinferdatafromstringmessages, // (required) The message(s) to infer data from string prompt = ”, // (optional) The prompt to use for inference array examples=[],//(optional)Examplestoincludeinthepromptstringexamples = [], // (optional) Examples to include in the prompt string model = ”, // (optional) The model to use for inference (otherwise - use default) int maxRetries=2,//(optional)ThenumberofretriesincaseofvalidationfailurearraymaxRetries = 2, // (optional) The number of retries in case of validation failure array options = [], // (optional) Additional data to pass to the Instructor or LLM API Mode mode=OutputMode::Tools,//(optional)Themodetouseforinference?LLMmode = OutputMode::Tools, // (optional) The mode to use for inference ?LLM llm = null // (optional) LLM instance to use for inference ) : static;
```php
<?php
require 'examples/boot.php';

use Cognesy\Instructor\Extras\Mixin\HandlesSelfInference;

class User {
    use HandlesSelfInference;

    public int $age;
    public string $name;
}

$user = User::infer("Jason is 25 years old and works as an engineer.");

dump($user);

assert(isset($user->name));
assert(isset($user->age));
assert($user->name === 'Jason');
assert($user->age === 25);
?>