Overview

This example demonstrates how to modify the settings path for the Instructor library. This is useful when you want to use a custom configuration directory instead of the default one.

Example

<?php
require 'examples/boot.php';

use Cognesy\Config\Settings;
use Cognesy\Instructor\StructuredOutput;

class UserDetail
{
    public int $age;
    public string $firstName;
    public ?string $lastName;
}

// set the configuration path to custom directory
Settings::setPath(__DIR__ . '/config');

$user = (new StructuredOutput)
    ->withDebugPreset('on') // we reconfigured local debug settings to dump only request URL
    ->withMessages('Jason is 25 years old.')
    ->withResponseClass(UserDetail::class)
    ->get();

dump($user);

assert(!isset($user->lastName) || $user->lastName === '');
?>