Input Transformer
Modules concerning the input transformers used in Gen AI applications.
FilterEmptyInputTransformer()
Bases: BaseInputTransformer
An input transformer that filters out empty or whitespace-only message contents.
This transformer removes any message content that is an empty string or contains only whitespace characters.
transform(messages)
Transforms the input messages by filtering out empty or whitespace-only contents.
This method filters out any content within a message that is an empty string or contains only whitespace characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
The input messages for the language model. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: The transformed input messages with empty/whitespace contents removed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the message has no non-empty contents. |
IdentityInputTransformer()
Bases: BaseInputTransformer
An input transformer that transforms the input messages of a language model into an identity function.
This transformer simply returns the input messages as is.
transform(messages)
Transforms the input messages of a language model with an identity function.
This method simply returns the input messages as is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
The input messages for the language model. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: The transformed input messages for the language model. |
InputTransformerChain(transformers)
A wrapper to chain a list of input transformers.
The InputTransformerChain class defines the interface for transforming
the input of language models using a chain of input transformers.
Attributes:
| Name | Type | Description |
|---|---|---|
transformers |
list[BaseInputTransformer]
|
The list of input transformers to use. |
Initializes a new instance of the InputTransformerChain class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformers
|
list[BaseInputTransformer]
|
The list of input transformers to use. |
required |
from_configs(configs)
classmethod
Create an input transformer chain from configs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configs
|
list[InputTransformerConfig]
|
The list of input transformer configs to use. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InputTransformerChain |
InputTransformerChain
|
The input transformer chain. |
transform(messages)
Transforms the input messages of a language model.
This method transforms the input messages using the chain of input transformers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
The input messages to transform. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: The transformed input messages of a language model. |
InputTransformerConfig
Bases: BaseModel
Defines the input transformer config schema.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
InputTransformerType
|
The type of input transformer to use. |
kwargs |
dict[str, Any]
|
The additional keyword arguments for the output transformer. |
build()
Build an input transformer from the config.
Returns:
| Name | Type | Description |
|---|---|---|
BaseInputTransformer |
BaseInputTransformer
|
The input transformer. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input transformer type is invalid. |
filter_empty()
classmethod
Create a filter-empty input transformer config.
Returns:
| Name | Type | Description |
|---|---|---|
InputTransformerConfig |
'InputTransformerConfig'
|
The filter-empty input transformer config. |
from_config(config)
classmethod
Create an input transformer config from a string or dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
InputTransformer
|
The input transformer config, can be one of the following: 1. str: The type of the input transformer 2. dict[str, Any]: The input transformer config as a dictionary 3. InputTransformerConfig: The input transformer config itself |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InputTransformerConfig |
'InputTransformerConfig'
|
A new input transformer config. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
identity()
classmethod
Create an identity input transformer config.
Returns:
| Name | Type | Description |
|---|---|---|
InputTransformerConfig |
'InputTransformerConfig'
|
The identity input transformer config. |