Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Added docker deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul Del Pozo Moreno committed Jul 13, 2022
1 parent 5a47fd5 commit 45020fd
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 34 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM rasa/rasa:3.1.1
WORKDIR '/app'
COPY . /app
USER root
# WORKDIR /app
# COPY . /app
COPY ./data /app/data
RUN rasa train
VOLUME /app
VOLUME /app/data
VOLUME /app/models
CMD ["run","-m","/app/models","--enable-api","--cors","*","--debug" ,"--endpoints", "endpoints.yml", "--log-file", "out.log", "--debug"]
14 changes: 14 additions & 0 deletions actions/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM rasa/rasa-sdk:3.1.1
WORKDIR /app
COPY requirements.txt requirements.txt
USER root

RUN pip install --upgrade pip
RUN pip install --verbose -r requirements.txt

RUN apt-get update && apt-get install -y locales
RUN locale-gen es_ES
RUN locale-gen es_ES.utf8

EXPOSE 5055
USER 1001
67 changes: 34 additions & 33 deletions actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from rasa_sdk.types import DomainDict
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk import Tracker, FormValidationAction
from os import path
import unidecode # acentos
import datetime
import pathlib
Expand All @@ -13,32 +14,30 @@
locale.setlocale(locale.LC_ALL, 'es_ES.utf8')


names = pathlib.Path("data/diccionarios/nombres.txt").read_text().split("\n")
data_path = "/app/actions"
if not path.exists(data_path):
data_path = "."

names = pathlib.Path(
data_path+"/data/diccionarios/nombres.txt").read_text().split("\n")
malsonantes = pathlib.Path(
"data/diccionarios/malsonante.txt").read_text().split("\n")
data_path+"/data/diccionarios/malsonante.txt").read_text().split("\n")

DIAS_SEMANA = ["lunes", "martes", "miercoles",
"jueves", "viernes", "sabado", "domingo"]
CATEGORIA_MENU = ["entrantes", "carnes", "pescados", "postres", "bebidas"]


def get_data_plato(tipo):
f = open(pathlib.Path("data/menu/"+tipo+".json"))
data = json.load(f)
f.close()
return data


def get_data_generic(path):
f = open(pathlib.Path(path))
data = json.load(f)
f.close()
return data


horario = get_data_generic("data/menu/horario.json")
mesas = get_data_generic("data/tables/mesas.json")
horas = get_data_generic("data/tables/horas.json")
horario = get_data_generic(data_path+"/data/menu/horario.json")
mesas = get_data_generic(data_path+"/data/tables/mesas.json")
horas = get_data_generic(data_path+"/data/tables/horas.json")


# ---------------------------------------------------------------------
Expand Down Expand Up @@ -193,20 +192,20 @@ def run(self, dispatcher, tracker, domain):
elif intent == "horario_concreto":
dia = tracker.get_slot("dia")
if dia is not None:
dia = dia.lower()

if dia == "hoy":
now = datetime.datetime.now()
dia = now.strftime("%A")
elif dia == "mañana":
now = (datetime.datetime.now() +
datetime.timedelta(1)).strftime("%A")
dia = now
elif dia == "pasado mañana":
now = (datetime.datetime.now() +
datetime.timedelta(2)).strftime("%A")
dia = now
dia = unidecode.unidecode(dia)
dia = dia.lower()

if dia == "hoy":
now = datetime.datetime.now()
dia = now.strftime("%A")
elif dia == "mañana":
now = (datetime.datetime.now() +
datetime.timedelta(1)).strftime("%A")
dia = now
elif dia == "pasado mañana":
now = (datetime.datetime.now() +
datetime.timedelta(2)).strftime("%A")
dia = now
dia = unidecode.unidecode(dia)

if dia not in DIAS_SEMANA:
message = "Ese dia de la semana es incorrecto."
Expand Down Expand Up @@ -317,15 +316,15 @@ def name(self):
return 'MenuGet'

def get_menu_plato(Action, tipo):
data = get_data_plato(tipo)
data = get_data_generic(data_path+"/data/menu/"+tipo+".json")
message = tipo.capitalize() + ":" + "\n"
for it in data[tipo]:
message += str(it['id']) + ": " + it['nombre'] + \
" - (" + it['precio'] + ")\n"
return message

def get_submenu_botones(Action, tipo):
data = get_data_plato(tipo)
data = get_data_generic(data_path+"/data/menu/"+tipo+".json")
buttons = []
for it in data[tipo]:
buttons.append({"title": "{}".format(
Expand All @@ -340,7 +339,7 @@ def run(self, dispatcher, tracker, domain):
if intent == "menu_completo":
message = ""
for it in CATEGORIA_MENU:
data = get_data_plato(it)
data = get_data_generic(data_path+"/data/menu/"+it+".json")
message += it.capitalize() + ":\n"
for d in data[it]:
message += "- " + d['nombre'] + \
Expand Down Expand Up @@ -524,7 +523,8 @@ async def extract_menu_plato_id(
menu_plato_categoria = it
break

data = get_data_plato(menu_plato_categoria)
data = get_data_generic(
data_path+"/data/menu/"+menu_plato_categoria+".json")
for it in data[menu_plato_categoria]:
if it['id'] == str(menu_plato_id):
return {"menu_plato_id": menu_plato_id}
Expand Down Expand Up @@ -552,7 +552,8 @@ def validate_menu_plato_id(
menu_plato_categoria = it
break

data = get_data_plato(menu_plato_categoria)
data = get_data_generic(
data_path+"/data/menu/"+menu_plato_categoria+".json")
for it in data[menu_plato_categoria]:
if it['id'] == str(menu_plato_id):
message = "Guardado plato " + menu_plato_categoria + \
Expand Down Expand Up @@ -650,8 +651,8 @@ def run(self, dispatcher, tracker, domain):
dispatcher.utter_message(text=message)

if tracker.get_slot("menu_establecido"):
dispatcher.utter_message(text=f'Tu menu esta compuesto por:')
MenuGetUser.run(self, dispatcher, tracker, domain)
dispatcher.utter_message(text=f'Tu menu esta compuesto por:')
MenuGetUser.run(self, dispatcher, tracker, domain)

return ""

Expand Down
1 change: 1 addition & 0 deletions actions/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unidecode
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.0'
services:
rasa:
container_name: rasa-server
build:
context: .
ports:
- 5005:5005
volumes:
- ./:/app
command:
- run
depends_on:
- action_server
action_server:
container_name: rasa-actions
build:
context: actions
volumes:
- ./actions:/app/actions
ports:
- 5055:5055
2 changes: 1 addition & 1 deletion endpoints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# https://rasa.com/docs/rasa/custom-actions

action_endpoint:
url: "http://localhost:5055/webhook"
url: "http://action_server:5055/webhook"

# Tracker store which is used to store the conversations.
# By default the conversations are stored in memory.
Expand Down

0 comments on commit 45020fd

Please sign in to comment.