I’ve installed rasa x on a server using docker-compose. I added a custom action following rasa master class using docker-compose.override and it worked fine. Now I’ve updated my custom action and it uses pymongo (a python library) to connect to a mongoDB database and it doesn’t work as intended. The price slot is not being set. The logs display an error pymongo module not found .One point to note is that it works fine locally on rasa x.
actions.py
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet
from pymongo import MongoClient
client = MongoClient(url)
db = client.floc
class ActionOrderSize(Action):
def name(self) -> Text:
return "action_order_size"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
items = tracker.get_slot("items")
serving_size = tracker.get_slot("serving_size")
price = 0
for i in range(len(items)):
item = items[i].lower().replace(" ", "")
if serving_size[i]:
size = serving_size[i].lower()
else:
size = "-"
itemPrice = db.menu.find_one({"item":item,"size":size})
price = price + itemPrice['price']
return [SlotSet("price", price)]
Dockerfile
FROM rasa/rasa-sdk:latest
WORKDIR /app
USER root
RUN pip install pymongo
COPY ./actions /app/actions
USER 1001
docker_compose.override.yml
version: '3.4'
services:
app:
build: .
volumes:
- './actions:/app/actions'
expose:
- '5055'
depends_on:
- rasa-production