Event emitter
Defines the event emitter module used throughout the Gen AI applications.
References
NONE
EventEmitter(handlers, event_level=EventLevel.INFO)
Handles events emitting using event handlers with various levels and types.
The EventEmitter
class is responsible for handling and emitting events using a list of event handlers.
Events are processed based on their severity level and type, with the option to disable specific handlers.
Attributes:
Name | Type | Description |
---|---|---|
handlers |
list[BaseEventHandler]
|
A list of event handlers to process emitted events. |
severity |
int
|
The minimum severity level of events to be processed. |
Raises:
Type | Description |
---|---|
ValueError
|
If the event handlers list is empty. |
ValueError
|
If an invalid event level is provided. |
Initializes a new instance of the EventEmitter class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handlers |
list[BaseEventHandler]
|
A list of event handlers to process emitted events. |
required |
event_level |
EventLevel
|
The minimum severity level of events to be processed. Defaults to EventLevel.INFO. |
INFO
|
close()
async
Closes all handlers in the handler list.
This method iterates through the list of handlers and calls the close
method on each handler.
Returns:
Type | Description |
---|---|
None
|
None |
emit(value, event_level=EventLevel.DEBUG, event_type=EventType.STATUS, disabled_handlers=None)
async
Emits an event using the event handlers with the specified severity and type.
This method emits an event by creating an Event
object with the provided message, severity level,
and event type. It then passes the event to the available handlers, unless they are listed in the disabled
handlers. The event will only be processed if its severity is greater than or equal to the configured
severity level of the EventEmitter
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
The event message to be emitted. |
required |
event_level |
EventLevel
|
The severity level of the event. Defaults to EventLevel.DEBUG. |
DEBUG
|
event_type |
EventType
|
The type of event (e.g., status, response). Defaults to EventType.STATUS. |
STATUS
|
disabled_handlers |
list[str]
|
The list of handler names to be disabled. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided |
ValueError
|
If the provided |