Customizing LLM-based Components
Rasa Labs access - New in 3.7.0b1
Rasa Labs features are experimental. We introduce experimental features to co-create with our customers. To find out more about how to participate in our Labs program visit our Rasa Labs page.
We are continuously improving Rasa Labs features based on customer feedback. To benefit from the latest bug fixes and feature improvements, please install the latest pre-release using:
The LLM components can be extended and modified with custom versions. This allows you to customize the behavior of the LLM components to your needs and experiment with different algorithms.
Customizing a component
The LLM components are implemented as a set of classes that can be extended
and modified. The following example shows how to extend the
ContextualResponseRephraser
component to add a custom behavior.
For example, we can change the rephrasing logic to use some more simple rephrasing strategy instead of calling an LLM
in specific cases (e.g., when a certain keyword is present in the response).
This can be done by extending the ContextualResponseRephraser
class and overriding the rephrase
method:
The custom component can then be used in the Rasa configuration file:
To reference a component in the Rasa configuration file, you need to use the
full name of the component class. The full name of the component class is
<module>.<class>
.
All components are well documented in their source code. The code can be found in your local installation of the Rasa Pro python package.
Common functions to be overridden
Below is a list of functions that could be overwritten to customize the LLM components:
ContextualResponseRephraser
rephrase
Rephrases the response generated by the LLM. The default implementation rephrases the response by prompting an LLM to generate a response based on the incoming message and the generated response. The generated response is then replaced with the generated response.
IntentlessPolicy
select_response_examples
Samples responses that fit the current conversation. The default implementation samples responses from the domain that fit the current conversation. The selection is based on the conversation history, the history will be embedded and the most similar responses will be selected.
select_few_shot_conversations
Samples conversations from the training data. The default implementation samples conversations from the training data that fit the current conversation. The selection is based on the conversation history, the history will be embedded and the most similar conversations will be selected.