Use nullable types to indicate that given field is optional.
examples/A01_Basics/BasicPrivateVsPublicFields/run.php
to check the details on the behavior
of extraction for classes with private and public fields,examples/A01_Basics/BasicGetSet/run.php
to see how Instructor uses getter and setter methods,examples/A01_Basics/BasicConstructor/run.php
to see how Instructor uses constructor parameters.#[Description]
and #[Instructions]
attributes to provide more
context to the language model or to provide additional instructions to the model.
#[Description]
attribute is used to describe a class or property in your data model.
Instructor will use this text to provide more context to the language model.
#[Instructions]
attribute is used to provide additional instructions to the language
model, such as how to process the data.
You can add multiple attributes to a class or property - Instructor will merge
them into a single block of text.
Instructor will still include any PHPDoc comments provided in the class, but
using attributes might be more convenient and easier to read.
NOTE: Technically both#[Description]
and#[Instructions]
attributes do the same thing - they provide additional context to the language model. Yet, providing them in separate attributes allows you to better organize your code and make it more readable. In the future, we may extend the functionality of these attributes to provide more specific instructions to the language model, so it is a good idea to use them now.
Structure
classStructure
class to define the data model.
See Structures for more details on how to work with dynamic data schemas.
Maybe
classMaybe
class provides a way to handle optional data that may or may not be present in the input text. It wraps a value type and indicates whether the data was found or not, along with an error message when the data is missing.
Maybe::is(class, name?, description?)
- Static factory method to create a Maybe instanceget()
- Get the value if present, or null if not founderror()
- Get the error message explaining why the value wasn’t foundhasValue()
- Check if a value was successfully extractedtoJsonSchema()
- Generate JSON schema for the Maybe wrapper