Events
Event classes
Instructor dispatches multiple classes of events during its execution. All of them are descendants of Event
class.
You can listen to these events and react to them in your application, for example to log information or to monitor the execution process.
Check the list of available event classes in the Cognesy\Instructor\Events
namespace.
Event methods
Each Instructor event offers following methods, which make interacting with them more convenient:
print()
- prints a string representation of the event to console outputprintDebug()
- prints a string representation of the event to console output, with additional debug informationasConsole()
- returns the event in a format suitable for console outputasLog()
- returns the event in a format suitable for logging
Receiving notification on internal events
Instructor allows you to receive detailed information at every stage of request and response processing via events.
(new Instructor)->onEvent(string $class, callable $callback)
method - receive callback when specified type of event is dispatched(new Instructor)->wiretap(callable $callback)
method - receive any event dispatched by Instructor, may be useful for debugging or performance analysis
Receiving events can help you to monitor the execution process and makes it easier for a developer to understand and resolve any processing issues.
Convenience methods for get streamed model updates
Instructor
class provides convenience methods allowing client code to receive
model updates when streaming is enabled:
onPartialUpdate(callable $callback)
- to handle partial model updates of the responseonSequenceUpdate(callable $callback)
- to handle partial sequence updates of the response
In both cases your callback will receive updated model, so you don’t have to extract it from the event.