├── app ├── actions │ ├── __init__.py │ └── actions.py ├── data │ ├── rules.yml │ ├── stories.yml │ └── nlu.yml ├── config.yml ├── domain.yml ├── credentials.yml ├── endpoints.yml └── tests │ └── test_stories.yml ├── heroku.yml ├── server.sh ├── Dockerfile ├── app.json ├── .gitignore └── README.md /app/actions/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /heroku.yml: -------------------------------------------------------------------------------- 1 | build: 2 | docker: 3 | web: Dockerfile -------------------------------------------------------------------------------- /server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$PORT"] 4 | then 5 | PORT=5005 6 | fi 7 | 8 | rasa run --enable-api --port $PORT -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rasa/rasa:latest 2 | 3 | COPY app /app 4 | COPY server.sh /app/server.sh 5 | 6 | USER root 7 | RUN chmod -R 777 /app 8 | USER 1001 9 | 10 | RUN rasa train nlu 11 | 12 | ENTRYPOINT ["/app/server.sh"] -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Rasa NLU Heroku template", 3 | "description": "A barebones Rasa NLU server installation using Docker", 4 | "repository": "https://github.com/just-ai/rasa-heroku-template", 5 | "logo": "https://s3-us-west-2.amazonaws.com/spaceocanadawp/2019/12/rasa-framework.png", 6 | "stack": "container" 7 | } -------------------------------------------------------------------------------- /app/data/rules.yml: -------------------------------------------------------------------------------- 1 | version: "2.0" 2 | 3 | rules: 4 | 5 | - rule: Say goodbye anytime the user says goodbye 6 | steps: 7 | - intent: goodbye 8 | - action: utter_goodbye 9 | 10 | - rule: Say 'I am a bot' anytime the user challenges 11 | steps: 12 | - intent: bot_challenge 13 | - action: utter_iamabot 14 | -------------------------------------------------------------------------------- /app/config.yml: -------------------------------------------------------------------------------- 1 | # Configuration for Rasa NLU. 2 | # https://rasa.com/docs/rasa/nlu/components/ 3 | language: en 4 | 5 | pipeline: 6 | # This key can be left empty. The pipeline will then be provided from a default configuration during training. 7 | 8 | # Configuration for Rasa Core. 9 | # https://rasa.com/docs/rasa/core/policies/ 10 | policies: 11 | # This key can be left empty. Policies will then be provided from a default configuration during training. 12 | -------------------------------------------------------------------------------- /app/data/stories.yml: -------------------------------------------------------------------------------- 1 | version: "2.0" 2 | 3 | stories: 4 | 5 | - story: happy path 6 | steps: 7 | - intent: greet 8 | - action: utter_greet 9 | - intent: mood_great 10 | - action: utter_happy 11 | 12 | - story: sad path 1 13 | steps: 14 | - intent: greet 15 | - action: utter_greet 16 | - intent: mood_unhappy 17 | - action: utter_cheer_up 18 | - action: utter_did_that_help 19 | - intent: affirm 20 | - action: utter_happy 21 | 22 | - story: sad path 2 23 | steps: 24 | - intent: greet 25 | - action: utter_greet 26 | - intent: mood_unhappy 27 | - action: utter_cheer_up 28 | - action: utter_did_that_help 29 | - intent: deny 30 | - action: utter_goodbye 31 | -------------------------------------------------------------------------------- /app/domain.yml: -------------------------------------------------------------------------------- 1 | version: "2.0" 2 | 3 | intents: 4 | - greet 5 | - goodbye 6 | - affirm 7 | - deny 8 | - mood_great 9 | - mood_unhappy 10 | - bot_challenge 11 | 12 | responses: 13 | utter_greet: 14 | - text: "Hey! How are you?" 15 | 16 | utter_cheer_up: 17 | - text: "Here is something to cheer you up:" 18 | image: "https://i.imgur.com/nGF1K8f.jpg" 19 | 20 | utter_did_that_help: 21 | - text: "Did that help you?" 22 | 23 | utter_happy: 24 | - text: "Great, carry on!" 25 | 26 | utter_goodbye: 27 | - text: "Bye" 28 | 29 | utter_iamabot: 30 | - text: "I am a bot, powered by Rasa." 31 | 32 | session_config: 33 | session_expiration_time: 60 34 | carry_over_slots_to_new_session: true 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | models/ 3 | 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging 13 | .Python 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | pip-wheel-metadata/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt -------------------------------------------------------------------------------- /app/actions/actions.py: -------------------------------------------------------------------------------- 1 | # This files contains your custom actions which can be used to run 2 | # custom Python code. 3 | # 4 | # See this guide on how to implement these action: 5 | # https://rasa.com/docs/rasa/custom-actions 6 | 7 | 8 | # This is a simple example for a custom action which utters "Hello World!" 9 | 10 | # from typing import Any, Text, Dict, List 11 | # 12 | # from rasa_sdk import Action, Tracker 13 | # from rasa_sdk.executor import CollectingDispatcher 14 | # 15 | # 16 | # class ActionHelloWorld(Action): 17 | # 18 | # def name(self) -> Text: 19 | # return "action_hello_world" 20 | # 21 | # def run(self, dispatcher: CollectingDispatcher, 22 | # tracker: Tracker, 23 | # domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: 24 | # 25 | # dispatcher.utter_message(text="Hello World!") 26 | # 27 | # return [] 28 | -------------------------------------------------------------------------------- /app/credentials.yml: -------------------------------------------------------------------------------- 1 | # This file contains the credentials for the voice & chat platforms 2 | # which your bot is using. 3 | # https://rasa.com/docs/rasa/messaging-and-voice-channels 4 | 5 | rest: 6 | # # you don't need to provide anything here - this channel doesn't 7 | # # require any credentials 8 | 9 | 10 | #facebook: 11 | # verify: "" 12 | # secret: "" 13 | # page-access-token: "" 14 | 15 | #slack: 16 | # slack_token: "" 17 | # slack_channel: "" 18 | # proxy: "" 19 | 20 | #socketio: 21 | # user_message_evt: 22 | # bot_message_evt: 23 | # session_persistence: 24 | 25 | #mattermost: 26 | # url: "https:///api/v4" 27 | # token: "" 28 | # webhook_url: "" 29 | 30 | # This entry is needed if you are using Rasa X. The entry represents credentials 31 | # for the Rasa X "channel", i.e. Talk to your bot and Share with guest testers. 32 | rasa: 33 | url: "http://localhost:5002/api" 34 | -------------------------------------------------------------------------------- /app/endpoints.yml: -------------------------------------------------------------------------------- 1 | # This file contains the different endpoints your bot can use. 2 | 3 | # Server where the models are pulled from. 4 | # https://rasa.com/docs/rasa/model-storage#fetching-models-from-a-server 5 | 6 | #models: 7 | # url: http://my-server.com/models/default_core@latest 8 | # wait_time_between_pulls: 10 # [optional](default: 100) 9 | 10 | # Server which runs your custom actions. 11 | # https://rasa.com/docs/rasa/custom-actions 12 | 13 | #action_endpoint: 14 | # url: "http://localhost:5055/webhook" 15 | 16 | # Tracker store which is used to store the conversations. 17 | # By default the conversations are stored in memory. 18 | # https://rasa.com/docs/rasa/tracker-stores 19 | 20 | #tracker_store: 21 | # type: redis 22 | # url: 23 | # port: 24 | # db: 25 | # password: 26 | # use_ssl: 27 | 28 | #tracker_store: 29 | # type: mongod 30 | # url: 31 | # db: 32 | # username: 33 | # password: 34 | 35 | # Event broker which all conversation events should be streamed to. 36 | # https://rasa.com/docs/rasa/event-brokers 37 | 38 | #event_broker: 39 | # url: localhost 40 | # username: username 41 | # password: password 42 | # queue: queue 43 | -------------------------------------------------------------------------------- /app/data/nlu.yml: -------------------------------------------------------------------------------- 1 | version: "2.0" 2 | 3 | nlu: 4 | - intent: greet 5 | examples: | 6 | - hey 7 | - hello 8 | - hi 9 | - hello there 10 | - good morning 11 | - good evening 12 | - moin 13 | - hey there 14 | - let's go 15 | - hey dude 16 | - goodmorning 17 | - goodevening 18 | - good afternoon 19 | 20 | - intent: goodbye 21 | examples: | 22 | - good afternoon 23 | - cu 24 | - good by 25 | - cee you later 26 | - good night 27 | - bye 28 | - goodbye 29 | - have a nice day 30 | - see you around 31 | - bye bye 32 | - see you later 33 | 34 | - intent: affirm 35 | examples: | 36 | - yes 37 | - y 38 | - indeed 39 | - of course 40 | - that sounds good 41 | - correct 42 | 43 | - intent: deny 44 | examples: | 45 | - no 46 | - n 47 | - never 48 | - I don't think so 49 | - don't like that 50 | - no way 51 | - not really 52 | 53 | - intent: mood_great 54 | examples: | 55 | - perfect 56 | - great 57 | - amazing 58 | - feeling like a king 59 | - wonderful 60 | - I am feeling very good 61 | - I am great 62 | - I am amazing 63 | - I am going to save the world 64 | - super stoked 65 | - extremely good 66 | - so so perfect 67 | - so good 68 | - so perfect 69 | 70 | - intent: mood_unhappy 71 | examples: | 72 | - my day was horrible 73 | - I am sad 74 | - I don't feel very well 75 | - I am disappointed 76 | - super sad 77 | - I'm so sad 78 | - sad 79 | - very sad 80 | - unhappy 81 | - not good 82 | - not very good 83 | - extremly sad 84 | - so saad 85 | - so sad 86 | 87 | - intent: bot_challenge 88 | examples: | 89 | - are you a bot? 90 | - are you a human? 91 | - am I talking to a bot? 92 | - am I talking to a human? 93 | -------------------------------------------------------------------------------- /app/tests/test_stories.yml: -------------------------------------------------------------------------------- 1 | #### This file contains tests to evaluate that your bot behaves as expected. 2 | #### If you want to learn more, please see the docs: https://rasa.com/docs/rasa/testing-your-assistant 3 | 4 | stories: 5 | - story: happy path 1 6 | steps: 7 | - user: | 8 | hello there! 9 | intent: greet 10 | - action: utter_greet 11 | - user: | 12 | amazing 13 | intent: mood_great 14 | - action: utter_happy 15 | 16 | - story: happy path 2 17 | steps: 18 | - user: | 19 | hello there! 20 | intent: greet 21 | - action: utter_greet 22 | - user: | 23 | amazing 24 | intent: mood_great 25 | - action: utter_happy 26 | - user: | 27 | bye-bye! 28 | intent: goodbye 29 | - action: utter_goodbye 30 | 31 | - story: sad path 1 32 | steps: 33 | - user: | 34 | hello 35 | intent: greet 36 | - action: utter_greet 37 | - user: | 38 | not good 39 | intent: mood_unhappy 40 | - action: utter_cheer_up 41 | - action: utter_did_that_help 42 | - user: | 43 | yes 44 | intent: affirm 45 | - action: utter_happy 46 | 47 | - story: sad path 2 48 | steps: 49 | - user: | 50 | hello 51 | intent: greet 52 | - action: utter_greet 53 | - user: | 54 | not good 55 | intent: mood_unhappy 56 | - action: utter_cheer_up 57 | - action: utter_did_that_help 58 | - user: | 59 | not really 60 | intent: deny 61 | - action: utter_goodbye 62 | 63 | - story: sad path 3 64 | steps: 65 | - user: | 66 | hi 67 | intent: greet 68 | - action: utter_greet 69 | - user: | 70 | very terrible 71 | intent: mood_unhappy 72 | - action: utter_cheer_up 73 | - action: utter_did_that_help 74 | - user: | 75 | no 76 | intent: deny 77 | - action: utter_goodbye 78 | 79 | - story: say goodbye 80 | steps: 81 | - user: | 82 | bye-bye! 83 | intent: goodbye 84 | - action: utter_goodbye 85 | 86 | - story: bot challenge 87 | steps: 88 | - user: | 89 | are you a bot? 90 | intent: bot_challenge 91 | - action: utter_iamabot 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rasa NLU server template 2 | 3 | This template contains all you need to deploy [Rasa NLU](https://rasa.com/) server on [Heroku cloud](https://heroku.com) to make your Rasa project visible globally. 4 | 5 | ## How to use 6 | 7 | Click on the button below to deploy this template on your Heroku instance. 8 | Heroku will automatically build the Docker image and your project's NLU model. 9 | 10 | [![Deploy to Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 11 | 12 | _It takes a couple of minutes to build and start the server. You can see the progress in Heroku logs._ 13 | 14 | ## How to make requests 15 | 16 | Once your server is deployed, you can make requests to your NLU model via [Rasa HTTP API](https://rasa.com/docs/rasa/api/http-api/#operation/parseModelMessage) 17 | For example: 18 | 19 | `curl https://.herokuapp.com/model/parse -d '{"text":"hello"}'` 20 | 21 | ## How to change the model 22 | 23 | Once you've deployed and tested your NLU server, you can then clone it to your machine and make changes in NLU model. 24 | 25 | ### 1. Clone the application 26 | 27 | Install [git](https://git-scm.com/downloads) and [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli#download-and-install). 28 | Run a terminal (or console) on your machine and type 29 | 30 | ``` 31 | heroku login 32 | heroku git:clone -a 33 | cd 34 | git remote add origin https://github.com/just-ai/rasa-heroku-template 35 | git pull origin master 36 | ``` 37 | 38 | _You have to do these steps only once per project._ 39 | 40 | ### 2. Make changes 41 | 42 | #### Install Rasa 43 | 44 | Install Rasa on your machine. Here is a great [installation guide](https://rasa.com/docs/rasa/user-guide/installation/). 45 | 46 | #### Train NLU model 47 | 48 | Then go to the directory of your application (cloned on the previous step) and make some changes in the model. 49 | Please refer to the [Rasa documentaion](https://rasa.com/docs/rasa/user-guide/rasa-tutorial/) to learn how to build and evaluate NLU model. 50 | 51 | > Please note that you don't have to run **rasa init** command once your template project is already cloned from Heroku. 52 | Also note that NLU server doesn't run any actions - it only runs your NLU model. Thus you can use only **rasa train nlu** command. 53 | 54 | #### Evaluate changes 55 | 56 | To evaluate your changes on your local machine just run NLU server locally and make some HTTP requests to the [Rasa HTTP API endpoint](https://rasa.com/docs/rasa/http-api). 57 | You can also use [shell command](https://rasa.com/docs/rasa/command-line-interface#rasa-shell) to try your mddel without running a server. 58 | 59 | #### Push changes to Heroku 60 | 61 | Once you've trained and evaluated your NLU model, you can push changes to Heroku. 62 | 63 | Run the next commands in the terminal 64 | 65 | ``` 66 | git add . 67 | git commit -am "some comments" 68 | git push 69 | ``` 70 | 71 | Heroku will automatically handle the changes, re-build NLU model and re-start the server. 72 | 73 | > Please note that locally trained NLU models won't be pushed to the Heroku repository. 74 | --------------------------------------------------------------------------------