Output transformer
Defines a base class for output transformers used in Gen AI applications.
References
NONE
BaseOutputTransformer(event_emitter=None)
Bases: ABC
A base class for output transformers used in Gen AI applications.
The BaseOutputTransformer class defines the interface for transforming the output of language models.
Subclasses must implement the following methods:
1. _transform_output_item: Transforms an output item of a language model.
2. _transform_event: Transforms a stream event of a language model before it is emitted.
Attributes:
| Name | Type | Description |
|---|---|---|
event_emitter |
EventEmitter | None
|
The event emitter to use for streaming events. |
Initializes a new instance of the BaseOutputTransformer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_emitter |
EventEmitter | None
|
The event emitter to use for streaming events. Defaults to None. |
None
|
emit(event)
async
Transforms a stream event and emits it using the event emitter.
This method transforms a stream event and emits it using the event emitter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event |
Event
|
The event to transform and emit. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the event emitter is not set. |
transform(output)
Transforms the output of a language model.
This method transforms each output item of the language model output sequentially.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output |
LMOutput
|
The output of a language model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
LMOutput |
LMOutput
|
The transformed output of a language model. |