input
field of Instructor’s create()
method
can be an object, but also an array or just a string.
<?php
require 'examples/boot.php';
use Cognesy\Instructor\StructuredOutput;
class Email {
public function __construct(
public string $address = '',
public string $subject = '',
public string $body = '',
) {}
}
$email = new Email(
address: 'joe@gmail',
subject: 'Status update',
body: 'Your account has been updated.'
);
$translatedEmail = (new StructuredOutput)
->withInput($email)
->withResponseClass(Email::class)
->withPrompt('Translate the text fields of email to Spanish. Keep other fields unchanged.')
->get();
dump($translatedEmail);
assert($translatedEmail->address === $email->address);
assert($translatedEmail->subject !== $email->subject);
assert($translatedEmail->body !== $email->body);
?>