How to use external dependencies for custom actions in droplet server with rasa x

I am really struggling with developing custom actions in droplet (digital ocean).

Through the lesson (Rasa Tutorials - Install Rasa X with Docker Compose on Digital Ocean - YouTube), managed to finish setting up rasa x and Github connection. However, couldn’t find a way to enable my “simple custom actions” as shown below (it is all saved in etc/rasa/actions with empty init.py):

from typing import Any, Text, Dict, List
import pandas as pd
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher

class ActionRephraseResponse(Action):

    def name(self) -> Text:
        return "action_pandas"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        df = pd.DataFrame({"A": ["this dataframe is working", "dataframe is working", 7], "B": [2, 5, 8], "C": [3, 6, 9]})
        dispatcher.utter_message(text=df["A"].tolist()[0])

        return []

Seems it’s an issue with adding dependencies to rasa, but I’ve installed pandas for sure by

sudo apt-get install python3-pandas

and made “docker-compose.override.yml” with the content:

version: '3.4'
services:
  app:
    image: 'rasa/rasa-sdk:latest'
    volumes:
      - './actions:/app/actions'
    expose:
      - '5055'
    depends_on:
      - rasa-production

and ran “sudo docker-compose down” and “sudo docker-compose up -d”. As a result, my model can understand when to “action_pandas” without saying “this dataframe is working”.

To fix this, I’ve found some answers talking about using Dockerfile like:

touch Dockerfile
nano Dockerfile
FROM rasa/rasa-sdk:2.8.2

# Switch to root user
USER root

#RUN apt-get update && apt-get install -y git

# Do other stuff, e.g.: add python dependencies, etc.
RUN pip3 install --no-cache-dir numpy
RUN pip3 install --no-cache-dir pandas

# Switch back to a non-root user
USER 1001

and I ran

docker build .

However, it’s not working despite showing:

Installing collected packages: six, pytz, python-dateutil, pandas
Successfully installed pandas-1.3.3 python-dateutil-2.8.2 pytz-2021.3 six-1.16.0
Removing intermediate container 3b3c9b58f2b2
 ---> 3460c743a5b9
Step 6/6 : USER 1001
 ---> Running in 1c1f30c821e0
Removing intermediate container 1c1f30c821e0
 ---> c427dd668ea7
Successfully built c427dd668ea7

I have no idea how to work with the docker things in droplet… Could you please help me with this?

Any help would be greatly appreciated.

@miner Please can you add requirements.txt and mention pandas in the file.

COPY requirement.txt requirement.txt

Isn’t it the same as RUN pip3 install --no-cache-dir pandas works in the Dockerfile? Plus, why do we need to repeat requirement.txt?

@miner Yes, my bad its installed successfully, can you share endpoints.yml file.?

Here:

  GNU nano 4.8                                       endpoints.yml                                                  
models:
  url: ${RASA_MODEL_SERVER}
  token: ${RASA_X_TOKEN}
  wait_time_between_pulls: ${RASA_MODEL_PULL_INTERVAL}
tracker_store:
  type: sql
  dialect: "postgresql"
  url: ${DB_HOST}
  port: ${DB_PORT}
  username: ${DB_USER}
  password: ${DB_PASSWORD}
  db: ${DB_DATABASE}
  login_db: ${DB_LOGIN_DB}
lock_store:
  type: "redis"
  url: ${REDIS_HOST}
  port: ${REDIS_PORT}
  password: ${REDIS_PASSWORD}
  db: ${REDIS_DB}
cache:
  type: "redis"
  url: ${REDIS_HOST}
  port: ${REDIS_PORT}
  password: ${REDIS_PASSWORD}
  db: ${REDIS_CACHE_DB}
  key_prefix: "rasax_cache"
event_broker:
  type: "pika"
  url: ${RABBITMQ_HOST}
  username: ${RABBITMQ_USERNAME}
  password: ${RABBITMQ_PASSWORD}
  queues:
  - ${RABBITMQ_QUEUE}
action_endpoint:
  url: ${RASA_USER_APP}/webhook
  token:  ""

but I want you to know that my custom action works without modifying it when I don’t use pandas…

@miner are you sure this is your endpoint file where actions_endpoint mention? @miner what do you mean by last line in previous post? can you explain more

Ah, please ignore the port thing. I’ve edited the comment. And, yes. That’s my endpoints.yml in the etc/rasa.