Event handler
Defines an abstract base class for all event handlers used throughout the Gen AI applications.
References
NONE
BaseEventHandler(name=None, color_map=None)
Bases: ABC
An abstract base class for all event handlers used throughout the Gen AI applications.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name assigned to the event handler. |
color_map |
dict[str, str]
|
The dictionary that maps certain event types to their corresponding colors in Rich format. |
Initializes a new instance of the BaseEventHandler class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str | None
|
The name assigned to the event handler. Defaults to None, in which case the class name will be used. |
None
|
color_map |
dict[str, str]
|
The dictionary that maps certain event types to their corresponding colors in Rich format. Defaults to None, in which case the default color map will be used. |
None
|
close()
async
Closes the event handler.
By default, this method does nothing. Subclasses can override this method to perform cleanup tasks (e.g., closing connections or releasing resources) when needed. Event handlers that do not require cleanup can inherit this default behavior without any changes.
Returns:
| Type | Description |
|---|---|
None
|
None |
emit(event)
abstractmethod
async
Emits the given event.
This abstract method must be implemented by subclasses to define how an event is emitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event |
Event
|
The event to be emitted. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented in a subclass. |