Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Commit

Permalink
Shifted to RASA NLU + Integrated Bot with Angular Application
Browse files Browse the repository at this point in the history
  • Loading branch information
lunayach committed Aug 10, 2018
1 parent a33aa09 commit 154b2fd
Show file tree
Hide file tree
Showing 73 changed files with 50,827 additions and 27 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,17 @@ Thumbs.db
# Config files storing passwords
/config/settings.js

#English model file required for entity extraction by MITIE
/ChatBot/total_word_feature_extractor.dat

#RASA log files
/ChatBot/out.log
/ChatBot/rasa_core.log

#Python virtual environment
/ChatBot/venv/*
/ChatBot/src/*

#IDE settings
/ChatBot/.idea

21 changes: 21 additions & 0 deletions ChatBot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
run:
python bot.py run

train-nlu:
python bot.py train-nlu

train-dialogue:
python bot.py train-dialogue

describe:
python visualize.py

learn:
python train_online.py

server:
python -m rasa_core.server -d models/current/dialogue -u models/nlu/default/current -o out.log --cors "*"

train-dialogue-default:
python -m rasa_core.train -d domain.yml -s data/stories.md -o models/current/dialogue --epochs 200

Binary file added ChatBot/__pycache__/bot.cpython-36.pyc
Binary file not shown.
Binary file added ChatBot/__pycache__/policy.cpython-36.pyc
Binary file not shown.
195 changes: 195 additions & 0 deletions ChatBot/bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import argparse
import logging

from policy import CustomPolicy
from rasa_core import utils
from rasa_core.actions import Action
from rasa_core.agent import Agent
from rasa_core.channels.console import ConsoleInputChannel
from rasa_core.events import SlotSet
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.actions.forms import (
EntityFormField,
FormAction
)

logger = logging.getLogger(__name__)


class ActionPatientInformation(FormAction):
RANDOMIZE = False

@staticmethod
def required_fields():
return [
EntityFormField("gender", "gender"),
EntityFormField("age", "age"),
]

@classmethod
def name(self):
return 'action_patient_information'

@classmethod
def submit(self, dispatcher, tracker, domain):
return [SlotSet("matches", "text")]


class ActionSuggestNormal(Action):
@classmethod
def name(self):
return 'action_suggest_normal'

@classmethod
def run(self, dispatcher, tracker, domain):
medicines = ['Atovaquone', 'Chloroquine', 'Doxycycline', 'Mefloquine', 'Primaquine']
age = int(tracker.get_slot("age"))
if age < 8:
medicines.remove("Doxycycline")
dispatcher.utter_message("You can take these medicines:\n" + ' '.join(medicines))
return []


class ActionSuggestPregnant(Action):
@classmethod
def name(self):
return 'action_suggest_pregnant'

@classmethod
def run(self, dispatcher, tracker, domain):
medicines = ['Chloroquine', 'Doxycycline', 'Mefloquine']
age = int(tracker.get_slot("age"))
if age < 8:
medicines.remove("Doxycycline")
dispatcher.utter_message("You can take these medicines:\n" + ' '.join(medicines))
return []


class ActionCheckMedicineNormal(Action):
@classmethod
def name(self):
return 'action_check_medicine_normal'

@classmethod
def run(self, dispatcher, tracker, domain):
medicines = ['ATOVAQUONE', 'CHLOROQUINE', 'DOXYCYCLINE', 'MEFLOQUINE', 'PRIMAQUINE']

medicine = str(tracker.get_slot("medicine")).upper()
age = int(tracker.get_slot("age"))
if age < 8:
medicines.remove("DOXYCYCLINE")

if medicine in medicines:
dispatcher.utter_message("Its safe to take the medicine!")
else:
dispatcher.utter_message("The asked medicine is not safe for you. You can take these medicines instead:"
"\n" + ' '.join(medicines))
return []


class ActionCheckMedicinePregnant(Action):
@classmethod
def name(self):
return 'action_check_medicine_pregnant'

@classmethod
def run(self, dispatcher, tracker, domain):
medicines = ['CHLOROQUINE', 'DOXYCYCLINE', 'MEFLOQUINE']
medicine = tracker.get_slot("medicine")
age = int(tracker.get_slot("age"))
if age < 8:
medicines.remove("DOXYCYCLINE")

if medicine in medicines:
dispatcher.utter_message("Its safe to take the medicine!")
else:
dispatcher.utter_message("The asked medicine is not safe for you. You can take these medicines instead:"
"\n" + ' '.join(medicines))
return []


class CheckAge(FormAction):
RANDOMIZE = False

@staticmethod
def required_fields():
return [
EntityFormField("age", "age")
]

@classmethod
def name(self):
return 'check_age'

@classmethod
def submit(self):
return


def train_dialogue(domain_file="domain.yml",
model_path="models/dialogue",
training_data_file="data/stories.md"):
agent = Agent(domain_file,
policies=[MemoizationPolicy(max_history=3),
CustomPolicy()])

training_data = agent.load_data(training_data_file)
agent.train(
training_data,
epochs=400,
batch_size=100,
validation_split=0.2
)

agent.persist(model_path)
return agent


def train_nlu():
from rasa_nlu.training_data import load_data
from rasa_nlu import config
from rasa_nlu.model import Trainer

training_data = load_data('data/nlu_data/')
trainer = Trainer(config.load("nlu_model_config.yml"))
trainer.train(training_data)
model_directory = trainer.persist('models/nlu', fixed_model_name="current")

return model_directory


def run(serve_forever=True):
interpreter = RasaNLUInterpreter("models/nlu/default/current")
agent = Agent.load("models/current/dialogue", interpreter=interpreter)

if serve_forever:
agent.handle_channel(ConsoleInputChannel())
return agent


if __name__ == '__main__':
utils.configure_colored_logging(loglevel="INFO")

parser = argparse.ArgumentParser(
description='starts the bot')

parser.add_argument(
'task',
choices=["train-nlu", "train-dialogue", "run"],
help="what the bot should do - e.g. run or train?")
task = parser.parse_args().task

# decide what to do based on first parameter of the script
if task == "train-nlu":
train_nlu()
elif task == "train-dialogue":
train_dialogue()
elif task == "run":
run()

8 changes: 8 additions & 0 deletions ChatBot/data/nlu_data/Female.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## intent:Female
- Female
- female
- woman
- Girl
- Gal
- Lady

6 changes: 6 additions & 0 deletions ChatBot/data/nlu_data/Male.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## intent:Male
- male
- man
- Boy
- Guy

13 changes: 13 additions & 0 deletions ChatBot/data/nlu_data/affirm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## intent:affirm
- yes
- ya
- Yes
- Yup
- Yes I am
- It's true
- Correct
- Right
- indeed
- affirmative
- agreed

5 changes: 5 additions & 0 deletions ChatBot/data/nlu_data/botPlace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## intent:botPlace
- Where do you live
- where are you
- where can I meet you?

17 changes: 17 additions & 0 deletions ChatBot/data/nlu_data/deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## intent:deny
- No
- no
- not
- no!
- What!! No!
- Nah
- i deny that
- impossible
- not possible
- that’s not correct
- that’s a mistake
- that’s incorrect
- that’s not right
- i disagree
- i don’t think so

33 changes: 33 additions & 0 deletions ChatBot/data/nlu_data/goodbye.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## intent:goodbye
- bye
- goodbye
- good bye
- stop
- end
- farewell
- have a good one
- lets close this conversation
- have a good day
- good night
- talk to you later
- ttyl
- ciao
- I’ve got to get going
- I must leave now
- I will leave now
- I’m done
- have a nice day
- nice talking to you
- until next time
- gotta go now
- see you
- see ya
- catch you later
- later
- I’m out of here
- I gotta head out
- I gotta take off now
- maybe tomorrow then
- we’ll continue some other time
- shall we continue at a later time

27 changes: 27 additions & 0 deletions ChatBot/data/nlu_data/greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## intent:greet
- hey
- howdy
- hey there
- hello
- hi
- good morning
- good evening
- dear sir
- hi doctor
- hi doc
- how’s it going?
- how are you doing?
- What’s up?
- What’s going on?
- good afternoon
- long time no see
- lets chat
- yo
- Sup?
- Wassup?
- Wazzup?
- Good day mate
- Hiya
- Hola
- Ola

23 changes: 23 additions & 0 deletions ChatBot/data/nlu_data/identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## intent:identity
- Who are you
- what's your name
- what are you called
- how are you called
- your name
- who you
- you?
- do i know you
- may i know who this is
- may i know who i am talking to
- who am i talking to?
- am i talking to a doctor?
- am i talking to a human?
- are you a girl?
- are you a female?
- are you a lady?
- are you a man?
- are you a boy?
- are you a guy?
- what is your gender?
- may i know your name?

6 changes: 6 additions & 0 deletions ChatBot/data/nlu_data/informAge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## intent:informAge
- [18](age)
- I am [17](age)
- [17](age) years old
- I’m [17](age)

15 changes: 15 additions & 0 deletions ChatBot/data/nlu_data/informThird.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## intent:informThird
- Not applicable
- third gender
- Don’t wish to specify
- Third gender
- not applicable
- not specifying
- does not apply
- not necessary
- other
- shall not specify
- why specify?
- will not tell


Loading

0 comments on commit 154b2fd

Please sign in to comment.