This is a simple example demonstrating how Instructor retrieves structured information from provided text (or chat message sequence).
Response model class is a plain PHP class with typehints specifying the types of fields of the object.
NOTE: By default, Instructor looks for OPENAI_API_KEY environment variable to get your API key. You can also provide the API key explicitly when creating the Instructor instance.
!!! note
Currently, Instructor for PHP only supports classes / objects as response models. In case you want to extract simple types or arrays, you need to wrap them in a class (or use Scalar
helper class).
You can provide a string instead of an array of messages. This is useful when you want to extract data from a single block of text and want to keep your code simple.
Instructor offers a way to use structured data as an input. This is useful when you want to use object data as input and get another object with a result of LLM inference.
The input
field of Instructor’s create()
method
can be an object, but also an array or just a string.
Instructor supports streaming of partial results, allowing you to start processing the data as soon as it is available.
See Scalar responses for more information on how to generate scalar responses with Scalar
adapter class.
See Streaming and partial updates for more information on how to work with partial updates and streaming.
See FunctionCall helper class for more information on how to extract arguments for callable objects.
This is a simple example demonstrating how Instructor retrieves structured information from provided text (or chat message sequence).
Response model class is a plain PHP class with typehints specifying the types of fields of the object.
NOTE: By default, Instructor looks for OPENAI_API_KEY environment variable to get your API key. You can also provide the API key explicitly when creating the Instructor instance.
!!! note
Currently, Instructor for PHP only supports classes / objects as response models. In case you want to extract simple types or arrays, you need to wrap them in a class (or use Scalar
helper class).
You can provide a string instead of an array of messages. This is useful when you want to extract data from a single block of text and want to keep your code simple.
Instructor offers a way to use structured data as an input. This is useful when you want to use object data as input and get another object with a result of LLM inference.
The input
field of Instructor’s create()
method
can be an object, but also an array or just a string.
Instructor supports streaming of partial results, allowing you to start processing the data as soon as it is available.
See Scalar responses for more information on how to generate scalar responses with Scalar
adapter class.
See Streaming and partial updates for more information on how to work with partial updates and streaming.
See FunctionCall helper class for more information on how to extract arguments for callable objects.