Commit 432c93b2 authored by SingLi's avatar SingLi Committed by GitHub

Merge pull request #2 from sshniro/master

Updating repository with official docker image and RASA CLI support
parents fe9b16c2 b25178f0
from arthurtemporim/rasa_rocketchat
add . /opt/bot_rasa
workdir /opt/bot_rasa
cmd bash -c "make train && make run_conversation"
run_conversation:
python -m rasa_core.run -d bot_rasa/models/dialogue -u bot_rasa/models/nlu/current -p ${PORT} --connector ${CONNECTOR} --credentials credentials.yml
run_server:
python -m rasa_core.server -d models/dialogue -u models/nlu/default/current -o out_server.log
train:
python -m rasa_nlu.train --config bot_rasa/config_spacy.yml --data bot_rasa/data/bot_rasa_nlu.md --fixed_model_name current --path bot_rasa/models/ --project nlu
python -m rasa_core.train -s bot_rasa/data/bot_rasa_stories.md -d bot_rasa/domain.yml -o bot_rasa/models/dialogue --epochs ${TRAINING_EPOCHS}
# bot_rasa
# rasa-rocketchat-kickstarter
A simple bot to test the integration with Rocket.Chat.
## Quickstart
### 1. Install Rocket.Chat
If you already have a Rocket.Chat instance you can skip this step
```sh
docker-compose up -d mongo
docker-compose up -d mongo-init-replica
docker-compose up -d rocketchat
```
Acess http://localhost:3000/
Access http://localhost:3000/
Create an `admin` user with the password `admin`.
### 2. Rocket.Chat Bot User Configurations
Create a Rasa bot user in Rocket.Chat. You can either manually login to Rocket.Chat and create a bot user via the
user management page or can use the following script to create the bot user.
Run the following command to create the RASA bot.
**Note:** Please replace the user name and password of the RocketChat admin and bot user accordingly.
```sh
python3 scripts/bot_config.py -an admin_username -ap admin_password -bn bot_username -bp bot_pass -r http://rocketchaturl
```
Create an `admin` user with the password `admin` and run the command:
If you are using docker-compose following is a sample usage
```sh
python3 scripts/bot_config.py -an admin -ap admin -bn bot_rasa -bp bot_rasa -r http://localhost:3000
```
### WebHook
### 3. Configure Rasa Bot
* Configure the Credentials file
Update your `credentials.yml` file inside the `bot_rasa` folder with Rasa bot's username and password.
```sh
rocketchat:
user: "bot_rasa"
password: "bot_rasa"
server_url: "http://localhost:3000"
```
* Train the Machine Learning Model
The Rasa bots machine learning model can built by using either Rasa CLI or Docker. After the training a machine
learning model will be created inside the `bot_rasa/models` folder.
* **If using Docker**
```sh
docker run -it -v $(pwd)/bot_rasa:/app rasa/rasa train
```
* **If using Rasa CLI**
```bash
pip3 install rasa
cd bot_rasa
rasa train
```
### 4. Start Rasa server
Rasa bot can be started via the Docker or Rasa CLI.
* **If using Docker-compose**
```sh
docker-compose up -d bot_rasa
```
* **If using Rasa CLI**
```python
cd bot_rasa
rasa run
```
#### 5. Make Rasa Bot accessible by Rocket.Chat
The Rasa bot should be reachable via Rocket.Chat.
* If you are following the tutorial with docker-compose file then following is the URL to access the Rasa bot.
```bash
http://bot_rasa:5005
```
* If you are trying to connect to a standalone Rocker.Chat instance or using Rasa CLI, lets user ngrok to get a
public url for the Rasa Bot.
Install ngrok via: https://ngrok.com/download
After downloading the ngrok navigate to the ngrok file in the downloded content and execute the following command.
This will provide a public URL to the Rasa bot
```bash
./ngork http 5005
```
Following will be the output of ngrok
```sh
Session Status online
Session Expires 7 hours, 59 minutes
Version 2.3.30
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://e3d5a17b.ngrok.io -> http://localhost:5005
Forwarding https://e3d5a17b.ngrok.io -> http://localhost:5005
```
Copy the http URL provided by ngrok: `http://e3d5a17b.ngrok.io`
### 6. Configure Rocket.Chat webhook
Go to **Administration > New Integration > Outgoing webhook**.
Inside the configuration insert this:
......@@ -25,23 +124,35 @@ Inside the configuration insert this:
```
Event Trigger: Message Sent
Enabled: True
Channel: @bot_rasa
URLs: http://bot_rasa:5005/webhook
Channel: #general
URLs: http://bot_rasa:5005/webhooks/rocketchat/webhook
Post as: bot_rasa
```
If you are using ngrok then replace the URL `http://bot:5005`, with the url obtained by ngrok.
```bash
URLs: http://ngrok_public_url/webhooks/rocketchat/webhook
```
**Save** all the changes.
### Credentials
### Example
Update your `credentials.yml` file.
Type `@bot_rasa hello` to start a conversation with the Rasa bot
![example]
### Running
[example]: rasa_bot_example.png
```sh
docker-compose up bot_rasa
```
### Example
### Additional Information
![example](https://github.com/arthurTemporim/testrasarocketchat/wiki/images/example.gif)
If you want the Rasa bot to direct message with the users create another webhook with the following configurations
```
Event Trigger: Message Sent
Enabled: True
Channel: all_direct_messages
URLs: http://bot_rasa:5005/webhooks/rocketchat/webhook
Post as: bot_rasa
```
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en
pipeline: supervised_embeddings
# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
- name: MemoizationPolicy
- name: KerasPolicy
- name: MappingPolicy
pipeline: "spacy_sklearn"
language : "en"
# This file contains the credentials for the voice & chat platforms
# which your bot is using.
# https://rasa.com/docs/rasa/user-guide/messaging-and-voice-channels/
rest:
# # you don't need to provide anything here - this channel doesn't
# # require any credentials
rasa:
url: "http://localhost:5002/api"
rocketchat:
user: "bot_rasa"
password: "bot_rasa"
server_url: "http://rocketchat:3000"
## happy path <!-- name of the story - just for debugging -->
* greet
- utter_greet
* mood_great <!-- user utterance, in format _intent[entities] -->
- utter_happy
## sad path 1 <!-- this is already the start of the next story -->
* greet
- utter_greet <!-- action of the bot to execute -->
* mood_unhappy
- utter_cheer_up
- utter_did_that_help
* mood_affirm
- utter_happy
......@@ -2,73 +2,49 @@
- hey
- hello
- hi
- hello there
- good morning
- good evening
- moin
- hey there
- let's go
- hey dude
- goodmorning
- goodevening
- good afternoon
## intent:goodbye
- cu
- good by
- cee you later
- good night
- good afternoon
- bye
- goodbye
- have a nice day
- see you around
- bye bye
- see you later
## intent:mood_affirm
## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct
## intent:mood_deny
## intent:deny
- no
- never
- I don't think so
- don't like that
- no way
- not really
## intent:mood_great
- perfect
- very good
- great
- amazing
- feeling like a king
- wonderful
- I am feeling very good
- I am great
- I am amazing
- I am going to save the world
- super
- extremely good
- so so perfect
- so good
- so perfect
- I'm good
## intent:mood_unhappy
- my day was horrible
- I am sad
- I don't feel very well
- I am disappointed
- super sad
- I'm so sad
- sad
- very sad
- unhappy
- not so good
- bad
- very bad
- awful
- terrible
- not very good
- extremly sad
- so saad
- so sad
- extremely sad
- so sad
\ No newline at end of file
## happy path
* greet
- utter_greet
* mood_great
- utter_happy
## sad path 1
* greet
- utter_greet
* mood_unhappy
- utter_cheer_up
- utter_did_that_help
* affirm
- utter_happy
## sad path 2
* greet
- utter_greet
* mood_unhappy
- utter_cheer_up
- utter_did_that_help
* deny
- utter_goodbye
## say goodbye
* goodbye
- utter_goodbye
intents:
- greet
- goodbye
- mood_affirm
- mood_deny
- affirm
- deny
- mood_great
- mood_unhappy
......@@ -15,22 +15,17 @@ actions:
templates:
utter_greet:
- text: "Human Hello! A bot RASA am I."
buttons:
- title: "great"
payload: "great"
- title: "super sad"
payload: "super sad"
- text: "Hey! How are you?"
utter_cheer_up:
- text: "Is Danger the dark side of the Force."
- text: "Here is something to cheer you up:"
image: "https://i.imgur.com/nGF1K8f.jpg"
utter_did_that_help:
- text: "Did that help you?"
utter_happy:
- text: "Correct path, light side is."
- text: "Great carry on!"
utter_goodbye:
- text: "May the Force be with you."
- text: "Bye"
# This file contains the different endpoints your bot can use.
# Server where the models are pulled from.
# https://rasa.com/docs/rasa/user-guide/running-the-server/#fetching-models-from-a-server/
#models:
# url: http://my-server.com/models/default_core@latest
# wait_time_between_pulls: 10 # [optional](default: 100)
# Server which runs your custom actions.
# https://rasa.com/docs/rasa/core/actions/#custom-actions/
#action_endpoint:
# url: "http://localhost:5055/webhook"
# Tracker store which is used to store the conversations.
# By default the conversations are stored in memory.
# https://rasa.com/docs/rasa/api/tracker-stores/
#tracker_store:
# type: redis
# url: <host of the redis instance, e.g. localhost>
# port: <port of your redis instance, usually 6379>
# db: <number of your database within redis, e.g. 0>
# password: <password used for authentication>
#tracker_store:
# type: mongod
# url: <url to your mongo instance, e.g. mongodb://localhost:27017>
# db: <name of the db within your mongo instance, e.g. rasa>
# username: <username used for authentication>
# password: <password used for authentication>
# Event broker which all conversation events should be streamed to.
# https://rasa.com/docs/rasa/api/event-brokers/
#event_broker:
# url: localhost
# username: username
# password: password
# queue: queue
{
"states": [
"intent_greet",
"intent_goodbye",
"intent_mood_affirm",
"intent_mood_deny",
"intent_mood_great",
"intent_mood_unhappy",
"prev_action_listen",
"prev_action_restart",
"prev_action_default_fallback",
"prev_utter_greet",
"prev_utter_cheer_up",
"prev_utter_did_that_help",
"prev_utter_happy",
"prev_utter_goodbye"
]
}
\ No newline at end of file
action_factory: null
action_names:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye
actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye
config:
store_entities_as_slots: true
entities: []
intents:
- greet
- goodbye
- mood_affirm
- mood_deny
- mood_great
- mood_unhappy
slots: {}
templates:
utter_cheer_up:
- image: https://i.imgur.com/nGF1K8f.jpg
text: Is Danger the dark side of the Force.
utter_did_that_help:
- text: Did that help you?
utter_goodbye:
- text: May the Force be with you.
utter_greet:
- buttons:
- payload: great
title: great
- payload: super sad
title: super sad
text: Human Hello! A bot RASA am I.
utter_happy:
- text: Correct path, light side is.
{"py/object": "rasa_core.featurizers.MaxHistoryTrackerFeaturizer", "max_history": 3, "remove_duplicates": true, "state_featurizer": {"py/object": "rasa_core.featurizers.SingleStateFeaturizer", "slot_feature_len": null, "user_feature_len": null}, "use_intent_probabilities": false}
\ No newline at end of file
{"py/object": "rasa_core.featurizers.MaxHistoryTrackerFeaturizer", "max_history": 3, "remove_duplicates": true, "state_featurizer": {"py/object": "rasa_core.featurizers.BinarySingleStateFeaturizer", "input_state_map": {"intent_goodbye": 1, "intent_greet": 0, "intent_mood_affirm": 2, "intent_mood_deny": 3, "intent_mood_great": 4, "intent_mood_unhappy": 5, "prev_action_default_fallback": 8, "prev_action_listen": 6, "prev_action_restart": 7, "prev_utter_cheer_up": 10, "prev_utter_did_that_help": 11, "prev_utter_goodbye": 13, "prev_utter_greet": 9, "prev_utter_happy": 12}, "num_features": 14, "slot_feature_len": 0, "user_feature_len": 6}, "use_intent_probabilities": false}
\ No newline at end of file
{"class_name": "Sequential", "config": [{"class_name": "Masking", "config": {"name": "masking_1", "trainable": true, "batch_input_shape": [null, 3, 14], "dtype": "float32", "mask_value": -1}}, {"class_name": "LSTM", "config": {"name": "lstm_1", "trainable": true, "return_sequences": false, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "units": 32, "activation": "tanh", "recurrent_activation": "hard_sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.2, "recurrent_dropout": 0.0, "implementation": 1}}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "batch_input_shape": [null, 32], "dtype": "float32", "units": 8, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"scale": 1.0, "mode": "fan_avg", "distribution": "uniform", "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Activation", "config": {"name": "activation_1", "trainable": true, "activation": "softmax"}}], "keras_version": "2.1.6", "backend": "tensorflow"}
\ No newline at end of file
{
"arch": "keras_arch.json",
"weights": "keras_weights.h5",
"epochs": 300
}
\ No newline at end of file
{
"rasa_nlu_data": {
"common_examples": [
{
"intent": "greet",
"text": "hey"
},
{
"intent": "greet",
"text": "hello"
},
{
"intent": "greet",
"text": "hi"
},
{
"intent": "greet",
"text": "hello there"
},
{
"intent": "greet",
"text": "good morning"
},
{
"intent": "greet",
"text": "good evening"
},
{
"intent": "greet",
"text": "moin"
},
{
"intent": "greet",
"text": "hey there"
},
{
"intent": "greet",
"text": "let's go"
},
{
"intent": "greet",
"text": "hey dude"
},
{
"intent": "greet",
"text": "goodmorning"
},
{
"intent": "greet",
"text": "goodevening"
},
{
"intent": "greet",
"text": "good afternoon"
},
{
"intent": "goodbye",
"text": "cu"
},
{
"intent": "goodbye",
"text": "good by"
},
{
"intent": "goodbye",
"text": "cee you later"
},
{
"intent": "goodbye",
"text": "good night"
},
{
"intent": "goodbye",
"text": "good afternoon"
},
{
"intent": "goodbye",
"text": "bye"
},
{
"intent": "goodbye",
"text": "goodbye"
},
{
"intent": "goodbye",
"text": "have a nice day"
},
{
"intent": "goodbye",
"text": "see you around"
},
{
"intent": "goodbye",
"text": "bye bye"
},
{
"intent": "goodbye",
"text": "see you later"
},
{
"intent": "mood_affirm",
"text": "yes"
},
{
"intent": "mood_affirm",
"text": "indeed"
},
{
"intent": "mood_affirm",
"text": "of course"
},
{
"intent": "mood_affirm",
"text": "that sounds good"
},
{
"intent": "mood_affirm",
"text": "correct"
},
{
"intent": "mood_deny",
"text": "no"
},
{
"intent": "mood_deny",
"text": "never"
},
{
"intent": "mood_deny",
"text": "I don't think so"
},
{
"intent": "mood_deny",
"text": "don't like that"
},
{
"intent": "mood_deny",
"text": "no way"
},
{
"intent": "mood_great",
"text": "perfect"
},
{
"intent": "mood_great",
"text": "very good"
},
{
"intent": "mood_great",
"text": "great"
},
{
"intent": "mood_great",
"text": "amazing"
},
{
"intent": "mood_great",
"text": "feeling like a king"
},
{
"intent": "mood_great",
"text": "wonderful"
},
{
"intent": "mood_great",
"text": "I am feeling very good"
},
{
"intent": "mood_great",
"text": "I am great"
},
{
"intent": "mood_great",
"text": "I am amazing"
},
{
"intent": "mood_great",
"text": "I am going to save the world"
},
{
"intent": "mood_great",
"text": "super"
},
{
"intent": "mood_great",
"text": "extremely good"
},
{
"intent": "mood_great",
"text": "so so perfect"
},
{
"intent": "mood_great",
"text": "so good"
},
{
"intent": "mood_great",
"text": "so perfect"
},
{
"intent": "mood_unhappy",
"text": "my day was horrible"
},
{
"intent": "mood_unhappy",
"text": "I am sad"
},
{
"intent": "mood_unhappy",
"text": "I don't feel very well"
},
{
"intent": "mood_unhappy",
"text": "I am disappointed"
},
{
"intent": "mood_unhappy",
"text": "super sad"
},
{
"intent": "mood_unhappy",
"text": "I'm so sad"
},
{
"intent": "mood_unhappy",
"text": "sad"
},
{
"intent": "mood_unhappy",
"text": "very sad"
},
{