Rasa X: Custom Pipline Element

Hi Rasa X Team,

I am using:

Rasa OSS: 1.10.0
Rasa X: 0.28.x
Deployment: Docker-Compose Manual

First of all: everything works as described and expected besides the following question. I am able to train, modify, connect to a remote Repository and all that stuff.

I am currently facing the issue that I want to use one single custom pipeline element in my config.yml that is not shipped with the default rasa image, e.g. like:

 - name: DIETClassifier
   random_seed: 42
   intent_classification: True
   entity_recognition: True
   use_masked_language_model: False
   epochs: 300
 - name: EntitySynonymMapper
 - name: "my_custom_component.CustomExtractorOfChoice"

Can someone describe the most convenient way to add this element to the image and make sure, that the folder lies in the PYTHONPATH environment variable?

Kind regards
Julian

I’m not in the Rasa X Team but I went through the same process as you are now ;). The Rasa blog on custom components describes the steps to take to add a component:

  • add it to the config.yml
  • add the component directory the PYTHONPATH

You need to convert those steps into a Dockerfile to build a custom container:

# Extend the official Rasa SDK image (change the version to whatever you need)
FROM rasa/rasa:1.8.2-full

# Switch to root user
USER root

# Add a folder to python path
ENV PYTHONPATH "${PYTHONPATH}:/app/my_custom_component"

# Do other stuff, e.g.: add python dependencies, etc.

# Switch back to a non-root user
USER 1001

Then:

  • Build the container: docker build . -t foobar:version
  • Copy the custom components to the rasa-x installation directory cp -r /code/dir/my_custom_component/* /etc/rasa/my_custom_component
  • Add a docker-compose.override.yml file to /etc/rasa and include the custom container (Note that the specific setup of the container depends on what you are trying to extend):

EDIT (fixed the docker-compose example):

services:
  rasa-worker:
    volumes:
      - ./directory/my_custom_component.py:/app/my_custom_component.py

docker-compose rasa-x, and you’re done!

3 Likes

Hey @flythe,

thanks - I will give that a try. As far as I have seen, it’s the Rasa image itsself that has to be extended, isnt it?

Kind regards
Julian

Hi everyone,

if you stumble upon this Issue, @flythe 's answer does the job. In specific, you need to modify:

  rasa-worker:
    <<: *default-rasa-service
    volumes:
       - ./custom_component:/app/custom_component
    environment:
      <<: *rasa-credentials
      PYTHONPATH: "${PYTHONPATH}:/app/custom_component"
      RASA_ENVIRONMENT: "worker"
      DB_DATABASE: "worker_tracker"
      RASA_MODEL_SERVER: "http://rasa-x:5002/api/projects/default/models/tags/production"

Make sure that the component of choice lies inside the mounted volume folder.

Kind regards
Julian

You are right I copied the wrong override example. This is the correct setup:

services:
  rasa-worker:
    volumes:
      - ./directory/my_custom_component.py:/app/my_custom_component.py

Preferably you don’t edit the docker-compose.yml file directly because it will get overwritten when it is changed in a rasa-x update. Just place a docker-compose.override.yml file in the same root directory and docker will sort out the overriden settings.

1 Like

Very Informative guys, good job.

This solution does not fit in the way rasa x uses version control. When you now change this custom component you need to make sure to also place it in the rasa x server… There needs to be a way of marking files that rasa x needs to place in worker containers.

But for now I think this is the best we’ve got…

Hey guys @flythe @JulianGerhard,
might you be able to take a look at the way I am trying to extend the image? Something is going wrong, as training and uploading models fails without an error log. \

This is my docker file:

# Extend the official Rasa SDK image
FROM rasa/rasa:latest-full

USER root

# Use subdirectory as working directory
WORKDIR /app


# add as environment variable
ENV PYTHONPATH=$PYTHONPATH:/app

# Copy any additional custom requirements, if necessary (uncomment next line)
COPY requirements.txt ./

# Install extra requirements for worker, if necessary (uncomment next line)
RUN pip install -r requirements.txt
RUN python -m nltk.downloader vader_lexicon
# Copy sentiment analyzer to working directory
COPY sentiment_analyzer.py /app

#
CMD ["start","--actions","actions"]

# By best practices, don't run the code with root user
USER 1001

This is my docker-compose.override.yml:

version: '3.4'
services:
  app:
    image: janfeldmann/customactionserver:e1.3
  rasa-production:
    image: janfeldmann/rasa_se:0.5
  rasa-worker:
    image: janfeldmann/rasa_se:0.5

Is there something I am doing wrong?

Hi @Taufred, you should probably check your docker-compose output. Are the containers actually running? In my solution I only need to create a custom image for the app service so it seems less complex than your application.

Hey @flythe thanks for the response. I already solved my problem, it had something to do with the cache location of the sentiment analyzer and the folder in which the vader lexicon was being stored.

@Taufred do you mind explaining how you fixed this? I am stuck on it currently, so any help would be nice! :slight_smile:

@fabrice-toussaint I did two things: added the line chache_dir: /tmp to the BERT transformer in the config file and this line RUN python -m nltk.downloader -d /usr/local/share/nltk_data vader_lexicon to the dockerfile.

Thanks! I got it working now :slight_smile:

Hey, I was following this to setup my customcomponent, but unfortunately am stuck with this. I am using an helm chart to deploy…

This is my custom component image

And this is my dockerfile used to extend the image, can you point me to what I am doing wrong? I am not get any error message in the pods but not getting any response either

FROM rasa/rasa:2.1.3-full

#USER root
#
#COPY ./customComp /customComp/
#ENV PYTHONPATH=$PYTHONPATH:/customComp/
#
#
#RUN pip install --trusted-host pypi.python.org fuzzywuzzy==0.18.0 rapidfuzz==0.13.4
#
## Switch back to non-root to run code
#USER 1001

#ENTRYPOINT rasa run

USER root

# Use subdirectory as working directory
WORKDIR /app


# add as environment variable
ENV PYTHONPATH=$PYTHONPATH:/app

# Install extra requirements for worker, if necessary (uncomment next line)
RUN pip install --trusted-host pypi.python.org fuzzywuzzy==0.18.0 rapidfuzz==0.13.4

# Copy sentiment analyzer to working directory
COPY ./customComp/DateParser.py /app

#
#CMD ["start","--actions","actions"]

# By best practices, don't run the code with root user
USER 1001