Version: Latest

Custom Rephraser Prompt Template in Kubernetes Deployment

Rasa Pro CALM allows you to use a custom prompt for the Contextual Response Rephraser to improve the conversational experience for your users, such as maintaining a consistent personality for your assistant.

This guide will explain how to configure a Rasa CALM bot to use a custom prompt template for the Contextual Response Rephraser in a Kubernetes environment.

We will use a ConfigMap to store the custom prompt template and a volume mount to make it accessible to the Rasa pod.

This approach has two benefits:

  • It allows Rasa to dynamically use the custom prompt without embedding it in the container image.
  • Simplifies updates to the prompt template as you only need to update the ConfigMap and restart the pod to apply any changes.

Prerequisites

  1. Kubernetes cluster with kubectl configured.
  2. Rasa deployment running in your Kubernetes cluster. This guide is specific to Rasa deployed using the Rasa Pro helm charts.
  3. A custom rephraser prompt file in Jinja2 format.

Steps to Use a Custom Rephraser Prompt Template

Step 1: Create a ConfigMap

Store your custom rephraser prompt in a ConfigMap to make it accessible to the Rasa pod.

  1. Save your prompt in a .jinja2 file, e.g., custom-rephraser-template.jinja2.
  2. Run:
    kubectl -n <namespace> create configmap custom-prompts --from-file=rephraser-template=<path-to-rephraser-prompt-jinja-file>
    Replace:
    • <namespace> with your Rasa namespace.
    • <path-to-rephraser-prompt-jinja-file> with the file path.

Step 2: Update Values File

Why Add a Volume and Mount?

A volume attaches external resources (e.g., ConfigMaps) to the pod, while a volume mount makes those resources accessible inside the container. In this case, we are adding a volume and volume mount to attach the ConfigMap containing the custom rephraser prompt to the Rasa pod. For more detail, see the Kubernetes documentation.

Modify values.yaml

Using the Rasa Pro helm charts, add the following under the rasa section:

rasa:
volumes:
# Define a volume sourced from the ConfigMap
- name: rephraser-prompt
configMap:
name: custom-prompts # Reference the ConfigMap created earlier
items:
- key: rephraser-template # Key in the ConfigMap holding the template
path: custom-rephraser-template.jinja2 # Filename inside the volume
volumeMounts:
# Map the volume to the container's filesystem
- name: rephraser-prompt # Match the volume name
mountPath: /app/prompts/custom-rephraser-template.jinja2 # Location inside the container
subPath: custom-rephraser-template.jinja2 # Mount only this file from the volume
readOnly: true # Ensure the file is not writable inside the container

Step 3: Deploy Changes

Redeploy your Rasa assistant to apply the configuration:

  1. Run:

    helm upgrade --install <release-name> <chart-name> -f values.yaml

    Replace:

    • <release-name> with your Rasa Helm release name.
    • <chart-name> with the name of your Helm chart.
  1. Verify the configuration with:

    kubectl -n <namespace> describe pod <rasa-pod-name>

Step 4: Verify the Custom Prompt

Test your Rasa assistant to ensure the custom prompt is being used. You should see the the rephraser prompt in the debug logs.

You can update the prompt by editing the .jinja2 file, recreating the ConfigMap, and redeploying using helm upgrade.