Output Transformer
Modules concerning the output transformers used in Gen AI applications.
IdentityOutputTransformer(event_emitter=None)
Bases: BaseOutputTransformer
An output transformer that transforms the output of a language model into an identity function.
This transformer simply returns the output and stream events of the language model as is.
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
|
ThinkTagOutputTransformer(event_emitter=None)
Bases: BaseOutputTransformer
An output transformer that handles special thinking tags used in certain open source language models.
Some open source language models, such as Qwen3-30B-A3B, emits their thinking tokens as part of the text tokens,
These thinking tokens are wrapped in special XML-like thinking tags to indicate the start and end of thinking.
This transformer detects and separates these thinking tags from the text output to handle the thinking properly.
Attributes:
| Name | Type | Description |
|---|---|---|
event_emitter |
EventEmitter | None
|
The event emitter to use for streaming events. |
thinking |
bool
|
Whether the transformer is currently in thinking mode. |
thinking_id |
str
|
The ID of the current thinking. |
Examples:
LMOutput transformation:
Input:
python
LMOutput(outputs=[
LMOutputItem(type="text", output="<think>I'm thinking...</think>I'm responding..."),
])
Output:
```python
LMOutput(outputs=[
LMOutputItem(type="thinking", output=Reasoning(reasoning="I'm thinking...")),
LMOutputItem(type="text", output="I'm responding..."),
])
```
Streaming event transformation:
Input:
python
Event(id=None, type="response", value="<think>")
Event(id=None, type="response", value="I'm thinking...")
Event(id=None, type="response", value="leading text</think>trailing text")
Event(id=None, type="response", value="I'm responding...")
Output:
```python
Event(id=None, type="thinking_start", value="<think>")
Event(id=None, type="thinking", value="I'm thinking...")
Event(id=None, type="thinking", value="leading text")
Event(id=None, type="thinking_end", value="</think>")
Event(id=None, type="response", value="trailing text")
Event(id=None, type="response", value="I'm responding...")
```
Initializes a new instance of the ThinkTagOutputTransformer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_emitter |
EventEmitter | None
|
The event emitter to use for streaming events. Defaults to None. |
None
|