Instructor
class¶
Instructor
class is the main entry point to the library. It is responsible for handling all interactions with the client code and internal Instructor components.
One of the essential tasks of the Instructor
class is to read the configuration and use it to retrieve a component implementing CanHandleRequest
interface (specified in the configuration) to process the request and return the response.
Instructor
class dispatches several high level events during initialization and processing of the request and response:
InstructorStarted
- dispatched when Instructor is createdInstructorReady
- dispatched when Instructor is configured and ready to process the requestRequestReceived
- dispatched when the request is receivedResponseGenerated
- dispatched when the response is generatedErrorRaised
- dispatched when an uncaught error occurs
Instructor
class contains top level try-catch block to let user handle any uncaught errors before throwing them to the client code.
Instructor
class provides several methods allowing client code to plug into Instructor event system, including: - onEvent()
- to receive a callback when specified type of event is dispatched - wiretap()
- to receive any event dispatched by Instructor - onError()
- to receive callback on any uncaught error
Additionally, Instructor
class provides convenience methods allowing client code to receive model updates when streaming is enabled:
onPartialUpdate()
- to handle partial model updates of the responseonSequenceUpdate()
- to handle partial sequence updates of the response