-
Notifications
You must be signed in to change notification settings - Fork 34
Upgraded ChatBot #161
Upgraded ChatBot #161
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we use a similar logic to check if age/gender already exists and not ask him again. That should solve Issue @Buddhiprabha was referring to in the last meeting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. If that is to be implemented, it would be done using these Python functions and conditionals. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I think we have another Issue open to track that. |
||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## intent:Female | ||
- Female | ||
- female | ||
- woman | ||
- Girl | ||
- Gal | ||
- Lady | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## intent:Male | ||
- male | ||
- man | ||
- Boy | ||
- Guy | ||
|
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 | ||
|
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? | ||
|
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 | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a new line in all these files. Please check all the files once.. |
||
|
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 | ||
|
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? | ||
|
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) | ||
|
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 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work for both python 2 and 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should Integrate it as part of travis build. Opinions @Raxerz @paavininanda @Buddhiprabha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shreyans29 what purpose shall it serve?
I have created this make file just to map larger python commands to shorter make commands.
i.e. instead of
python bot.py run
, you can callmake run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Raxerz it supports both Python 2 and 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay.. about version, rasa has support for both, but you must have chosen one of those and moved ahead with it right? APIs for python 2 and python 3 are different. I doubt we can build this code with both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shreyans29 I had used Python 3. And accordingly recommended this in the Documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.. I am saying that this code won't work with python 2. If you used python 3 which is a nice decision, everyone contributing in future will have to use python 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay! Got it.