Skip to content

Commit

Permalink
Merge pull request #182 from lappis-unb/devel
Browse files Browse the repository at this point in the history
v1.1.2
  • Loading branch information
arthurTemporim authored Dec 4, 2020
2 parents 683b614 + f250415 commit 1ce76a8
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 123 deletions.
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ build-coach:
docker-compose build --no-cache coach

build-analytics:
docker-compose up -d elasticsearch
docker-compose up -d rabbitmq
docker-compose up -d rabbitmq-consumer
docker-compose up -d kibana
make run-analytics
make config-elastic
# This line should be removed ASAP
sleep 10
# Run this command only when kibana is up and ready. A script is needed.
make config-kibana

config-elastic:
Expand All @@ -45,6 +45,12 @@ config-kibana:
$(info Acesse o KIBANA em: http://localhost:5601)
$(info )

run-analytics:
docker-compose up -d elasticsearch
docker-compose up -d rabbitmq
docker-compose up -d rabbitmq-consumer
docker-compose up -d kibana

run-shell:
docker-compose run --rm --service-ports bot make shell

Expand All @@ -55,18 +61,17 @@ run-actions:
docker-compose run --rm --service-ports bot make actions

run-x:
docker-compose run --rm --service-ports bot make x
docker-compose run --rm --service-ports x make x

run-webchat:
$(info )
$(info Executando Bot com Webchat.)
$(info )
docker-compose run -d --rm --service-ports bot-webchat
docker-compose up -d webchat
$(info )
$(info Caso o FIREFOX não seja iniciado automáticamente, abra o seguinte arquivo com seu navegador:)
$(info modules/webchat/index.html)
$(info Acesse o WEBCHAT em: http://localhost:5010)
$(info )
firefox modules/webchat/index.html

run-telegram:
docker-compose run -d --rm --service-ports bot_telegram make telegram
Expand All @@ -77,6 +82,12 @@ run-notebooks:
$(info Acesse o KIBANA em: http://localhost:8888)
$(info )

run-rocket:
docker-compose up -d rocketchat bot-rocket
$(info )
$(info Acesse o ROCKETCHAT em: http://localhost:5003)
$(info )

train:
mkdir -p bot/models
docker-compose up --build coach
Expand Down
11 changes: 8 additions & 3 deletions bot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ validate:

# MENSAGEIROS
shell:
rasa shell -m models/ -vv --endpoints endpoints.yml --port 5004
rasa shell -m models/ -vv --endpoints endpoints.yml --port 5006

telegram:
rasa run -m models/ -vv --port 5001 --credentials credentials.yml \
--endpoints endpoints.yml

webchat:
rasa run -m models/ -vv --endpoints endpoints.yml --credentials credentials.yml --port 5005 --cors '*'
rasa run -m models/ -vv --endpoints endpoints.yml --credentials credentials.yml --port 5007 --cors '*'

api:
rasa run -m models/ -vv --endpoints endpoints.yml --enable-api
rasa run -m models/ -vv --endpoints endpoints.yml --enable-api --port 5006

rocket:
python /modules/rocketchat/bot_config.py
rasa run -m models/ -vv --endpoints endpoints.yml --credentials credentials.yml --port 5005 --cors '*'


# ACTIONS
actions:
Expand Down
2 changes: 1 addition & 1 deletion bot/actions/action_telefone.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run(
domain: Dict[Text, Any],
) -> List[Dict[Text, Any]]:

telefone = tracker.get_slot('telefone')
telefone = tracker.get_slot("telefone")

try:
dispatcher.utter_message("O seu telefone é {}?".format(telefone))
Expand Down
11 changes: 5 additions & 6 deletions bot/actions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def required_slots(tracker: Tracker) -> List[Text]:

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
"""A dictionary to map required slots to
- an extracted entity
- intent: value pairs
- a whole message
or a list of them, where a first match will be picked"""
- an extracted entity
- intent: value pairs
- a whole message
or a list of them, where a first match will be picked"""
return {
"cpf": self.from_text(not_intent="cancelar"),
"data_nascimento": self.from_text(not_intent="cancelar"),
Expand All @@ -45,7 +45,7 @@ def submit(
domain: Dict[Text, Any],
) -> List[Dict]:
"""Define what the login form will do after
all required slots are filled"""
all required slots are filled"""

cpf = tracker.get_slot("cpf")
data_nascimento = tracker.get_slot("data_nascimento")
Expand Down Expand Up @@ -94,4 +94,3 @@ def validate_data_nascimento(
# validation failed, set this slot to None, meaning the
# user will be asked for the slot again
return {"data_nascimento": None}

6 changes: 6 additions & 0 deletions bot/credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ socketio:
bot_message_evt: bot_uttered
session_persistence: true


rocketchat:
user: "bot"
password: "bot"
server_url: "http://rocketchat:3000"

rest:
30 changes: 17 additions & 13 deletions bot/domain.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
session_config:
session_expiration_time: 60.0
session_expiration_time: 60
carry_over_slots_to_new_session: true
intents:
- cumprimentar
Expand Down Expand Up @@ -53,13 +53,14 @@ entities:
- telefone
- cpf
- dada_nascimento
- relationship
slots:
telefone:
type: unfeaturized
cpf:
type: unfeaturized
data_nascimento:
type: unfeaturized
telefone:
type: unfeaturized
responses:
utter_fallback:
- text: "Desculpe, ainda não sei falar sobre isso ou talvez não consegui entender\
Expand Down Expand Up @@ -176,25 +177,28 @@ responses:
\ aprender! Acessa lá: https://github.com/lappis-unb/rasa-ptbr-boilerplate\n\
\n Ah e eu sou Open Source ;)"
utter_pergunta_cancelar:
- text: Entendi. Você deseja cancelar?
- text: Entendi. Você deseja cancelar?
utter_login_form:
- text: Ok, Vou te pedir algumas informações.
- text: Ok, Vou te pedir algumas informações.
utter_ask_cpf:
- text: Qual o seu CPF?
- text: Qual o seu CPF?
utter_errado_cpf_formato:
- text: Desculpe, o formato informado do CPF não está correto, digite apenas números ou usando '000.000.000-00'.
- text: Desculpe, o formato informado do CPF não está correto, digite apenas números
ou usando '000.000.000-00'.
utter_errado_cpf_invalido:
- text: Desculpe, o valor informado do CPF está inválido.
- text: Desculpe, o valor informado do CPF está inválido.
utter_ask_data_nascimento:
- text: Qual a sua data de nascimento?
- text: Qual a sua data de nascimento?
utter_errado_data_nascimento:
- text: Desculpe, o valor informado para a data de nascimento não está correto, digite usando 'dd/mm/aaaa'.
- text: Desculpe, o valor informado para a data de nascimento não está correto,
digite usando 'dd/mm/aaaa'.
utter_finaliza_forms:
- text: Ótimo, seus dados estão armazenado nos meus slots. Terminei o formulário ;)
- text: Ótimo, seus dados estão armazenado nos meus slots. Terminei o formulário
;)
utter_forms_cancelado:
- text: Ok, forms cancelado. Podemos voltar a conversar sobre outros assuntos ;)
- text: Ok, forms cancelado. Podemos voltar a conversar sobre outros assuntos ;)
actions:
- action_teste
- action_telefone
forms:
- login_form
- login_form
85 changes: 83 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
volumes:
- ./bot/:/bot/
ports:
- 5004:5004
- 5006:5006
depends_on:
- actions

Expand All @@ -37,6 +37,8 @@ services:
- ./bot/:/bot/
ports:
- 5002:5002
env_file:
- env/rasax.env
depends_on:
- actions
command: sh -c "make x"
Expand All @@ -62,11 +64,25 @@ services:
volumes:
- ./bot/:/bot/
ports:
- 5005:5005
- 5007:5007
depends_on:
- actions
command: sh -c "make webchat"

# ============================ WebChat Bot =================================
# Specific Rasa bot integrated with WebChat.
bot-rocket:
build:
context: .
dockerfile: ./docker/bot.Dockerfile
volumes:
- ./bot/:/bot/
ports:
- 5005:5005
depends_on:
- actions
command: sh -c "make rocket"

# =============================== Analytics =================================
# Analitics ElasticSearch Stack.
elasticsearch:
Expand Down Expand Up @@ -125,6 +141,16 @@ services:
- env/rabbitmq-consumer.env
command: python3 /opt/scripts/consume_bot_messages.py


# ============================ Webchat Page =================================
# A container to run webchat html page
webchat:
image: nginx
ports:
- 5010:80
volumes:
- ./modules/webchat:/usr/share/nginx/html

# ============================ Telegram Bot =================================
# Specific Rasa bot integrated with Telegram.
bot_telegram:
Expand Down Expand Up @@ -155,10 +181,65 @@ services:
ports:
- 8888:8888

# =============================== Rocket.Chat =================================
# Rocket.Chat instance and database
rocketchat:
image: rocketchat/rocket.chat:3.7.1
command: >
bash -c
"for i in `seq 1 30`; do
node main.js &&
s=$$? && break || s=$$?;
echo \"Tried $$i times. Waiting 5 secs...\";
sleep 5;
done; (exit $$s)"
restart: unless-stopped
volumes:
- rocket_uploads:/app/uploads
environment:
- PORT=3000
- ROOT_URL=http://localhost:3000
- MONGO_URL=mongodb://mongo:27017/rocketchat
- MONGO_OPLOG_URL=mongodb://mongo:27017/local
- ADMIN_USERNAME=admin
- ADMIN_PASS=admin
- [email protected]
depends_on:
- mongo
- mongo-init-replica
ports:
- 5003:3000

mongo:
image: mongo:4.0
restart: unless-stopped
volumes:
- mongo_data:/data/db
command: mongod --smallfiles --oplogSize 128 --replSet rs0 --storageEngine=mmapv1

# this container's job is just run the command to initialize the replica set.
# it will run the command and remove himself (it will not stay running)
mongo-init-replica:
image: mongo:4.0
command: >
bash -c
"for i in `seq 1 30`; do
mongo mongo/rocketchat --eval \"
rs.initiate({
_id: 'rs0',
members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
s=$$? && break || s=$$?;
echo \"Tried $$i times. Waiting 5 secs...\";
sleep 5;
done; (exit $$s)"
depends_on:
- mongo

volumes:
notebook_models:
mongo_data:
rabbit_data:
esbackup:
esdata:
driver: local
rocket_uploads:
2 changes: 1 addition & 1 deletion docker/actions.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM botrequirements

COPY ./bot/actions/actions.py /bot/actions/actions.py
COPY ./bot/actions/ /bot/actions/
COPY ./bot/Makefile /bot/Makefile

WORKDIR /bot
Expand Down
2 changes: 1 addition & 1 deletion docker/requirements.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY ./requirements.txt /tmp
COPY ./x-requirements.txt /tmp

RUN apt-get update && \
apt-get install -y gcc make build-essential && \
apt-get install -y gcc make build-essential git && \
python -m pip install --upgrade pip && \
pip install --no-cache-dir -r /tmp/requirements.txt && \
pip install --no-cache-dir -r /tmp/x-requirements.txt && \
Expand Down
1 change: 1 addition & 0 deletions env/rasax.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GIT_PYTHON_REFRESH=quiet
5 changes: 4 additions & 1 deletion modules/analytics/setup_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
if not es.indices.exists(index_name):
logger.debug(
es.indices.create(
index=index_name, ignore=400, params=param, body=settings,
index=index_name,
ignore=400,
params=param,
body=settings,
)
)
logger.info("Created Index")
Expand Down
5 changes: 4 additions & 1 deletion modules/rabbitmq/consumer/consume_bot_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

connection = pika.BlockingConnection(
pika.ConnectionParameters(
host="rabbitmq", credentials=credentials, connection_attempts=20, retry_delay=5,
host="rabbitmq",
credentials=credentials,
connection_attempts=20,
retry_delay=5,
)
)

Expand Down
Loading

0 comments on commit 1ce76a8

Please sign in to comment.