Skip to content

Commit

Permalink
add rasa
Browse files Browse the repository at this point in the history
  • Loading branch information
khuyentran1401 committed May 28, 2021
1 parent 1aea061 commit 1326fc5
Show file tree
Hide file tree
Showing 11 changed files with 455 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nlp/conversational_rasa/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.config
models/*
events*
Empty file.
34 changes: 34 additions & 0 deletions nlp/conversational_rasa/actions/actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher


class ActionShowMenu(Action):

def name(self) -> Text:
return "action_show_menu"

def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:


menu = {'Chicken and rice': 10,
'Pho': 11,
'Spicy chicken': 9}

dispatcher.utter_message(f"The menu today is:\n")
for food in menu:
dispatcher.utter_message(food)

return []
39 changes: 39 additions & 0 deletions nlp/conversational_rasa/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en

pipeline:
# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# # If you'd like to customize it, uncomment and adjust the pipeline.
# # See https://rasa.com/docs/rasa/tuning-your-model for more information.
# - name: WhitespaceTokenizer
# - name: RegexFeaturizer
# - name: LexicalSyntacticFeaturizer
# - name: CountVectorsFeaturizer
# - name: CountVectorsFeaturizer
# analyzer: char_wb
# min_ngram: 1
# max_ngram: 4
# - name: DIETClassifier
# epochs: 100
# constrain_similarities: true
# - name: EntitySynonymMapper
# - name: ResponseSelector
# epochs: 100
# constrain_similarities: true
# - name: FallbackClassifier
# threshold: 0.3
# ambiguity_threshold: 0.1

# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See https://rasa.com/docs/rasa/policies for more information.
- name: MemoizationPolicy
- name: TEDPolicy
max_history: 5
epochs: 100
constrain_similarities: true
- name: RulePolicy
33 changes: 33 additions & 0 deletions nlp/conversational_rasa/credentials.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file contains the credentials for the voice & chat platforms
# which your bot is using.
# https://rasa.com/docs/rasa/messaging-and-voice-channels

rest:
# # you don't need to provide anything here - this channel doesn't
# # require any credentials


#facebook:
# verify: "<verify>"
# secret: "<your secret>"
# page-access-token: "<your page access token>"

#slack:
# slack_token: "<your slack token>"
# slack_channel: "<the slack channel>"
# slack_signing_secret: "<your slack signing secret>"

#socketio:
# user_message_evt: <event name for user message>
# bot_message_evt: <event name for bot messages>
# session_persistence: <true/false>

#mattermost:
# url: "https://<mattermost instance>/api/v4"
# token: "<bot token>"
# webhook_url: "<callback URL>"

# This entry is needed if you are using Rasa X. The entry represents credentials
# for the Rasa X "channel", i.e. Talk to your bot and Share with guest testers.
rasa:
url: "http://localhost:5002/api"
96 changes: 96 additions & 0 deletions nlp/conversational_rasa/data/nlu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
version: "2.0"
nlu:
- intent: greet
examples: |
- hey
- hello
- hi
- hello there
- good morning
- good evening
- moin
- hey there
- let's go
- hey dude
- goodmorning
- goodevening
- good afternoon
- Hello
- Hi
- intent: goodbye
examples: |
- cu
- good by
- cee you later
- good night
- bye
- goodbye
- have a nice day
- see you around
- bye bye
- see you later
- intent: affirm
examples: |
- yes
- y
- indeed
- of course
- that sounds good
- correct
- intent: deny
examples: |
- no
- n
- never
- I don't think so
- don't like that
- no way
- not really
- intent: mood_great
examples: |
- perfect
- 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 stoked
- extremely good
- so so perfect
- so good
- so perfect
- intent: mood_unhappy
examples: |
- 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 good
- not very good
- extremly sad
- so saad
- so sad
- intent: bot_challenge
examples: |
- are you a bot?
- are you a human?
- am I talking to a bot?
- am I talking to a human?
- intent: answer_question_about_health
examples: |
- I'm doing well! How about you?
- intent: ask_menu_today
examples: |
- What do you have in your menu today?
- What food is available today?
- intent: ask_bot_ability
examples: |
- Wow cool! What can you do?
13 changes: 13 additions & 0 deletions nlp/conversational_rasa/data/rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "2.0"

rules:

- rule: Say goodbye anytime the user says goodbye
steps:
- intent: goodbye
- action: utter_goodbye

- rule: Say 'I am a bot' anytime the user challenges
steps:
- intent: bot_challenge
- action: utter_iamabot
49 changes: 49 additions & 0 deletions nlp/conversational_rasa/data/stories.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "2.0"
stories:
- story: happy path
steps:
- intent: greet
- action: utter_greet
- intent: mood_great
- action: utter_happy
- story: sad path 1
steps:
- intent: greet
- action: utter_greet
- intent: mood_unhappy
- action: utter_cheer_up
- action: utter_did_that_help
- intent: affirm
- action: utter_happy
- story: sad path 2
steps:
- intent: greet
- action: utter_greet
- intent: mood_unhappy
- action: utter_cheer_up
- action: utter_did_that_help
- intent: deny
- action: utter_goodbye
- story: interactive_story_1
steps:
- intent: greet
- action: utter_greet
- intent: answer_question_about_health
- action: utter_doing_well
- story: get_restaurant_menu
steps:
- intent: greet
- action: utter_greet
- action: utter_how_can_i_help
- intent: ask_menu_today
- action: action_show_menu
- story: Story from Conversation ID 847ddfd5069d44499173e1a0b6ab671c
steps:
- intent: greet
- action: utter_greet
- intent: answer_question_about_health
- action: utter_doing_well
- intent: bot_challenge
- action: utter_iamabot
- intent: ask_bot_ability
- action: utter_ability
55 changes: 55 additions & 0 deletions nlp/conversational_rasa/domain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: '2.0'
config:
store_entities_as_slots: true
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
intents:
- greet:
use_entities: true
- goodbye:
use_entities: true
- affirm:
use_entities: true
- deny:
use_entities: true
- mood_great:
use_entities: true
- mood_unhappy:
use_entities: true
- bot_challenge:
use_entities: true
- answer_question_about_health:
use_entities: true
- ask_menu_today:
use_entities: true
- ask_bot_ability:
use_entities: true
entities: []
slots: {}
responses:
utter_greet:
- text: Hey! How are you?
utter_cheer_up:
- image: https://i.imgur.com/nGF1K8f.jpg
text: 'Here is something to cheer you up:'
utter_did_that_help:
- text: Did that help you?
utter_happy:
- text: Great, carry on!
utter_goodbye:
- text: Bye
utter_iamabot:
- text: I am a bot, powered by Rasa.
utter_doing_well:
- text: I am doing well! Thank you.
utter_how_can_i_help:
- text: How can I help you today?
utter_ability:
- text: I can listen and talk to you. Please be patient with me if I don't understand you yet.
- text: I can listen to your need and find the way to help you
actions:
- action_show_menu
- utter_ability
forms: {}
e2e_actions: []
42 changes: 42 additions & 0 deletions nlp/conversational_rasa/endpoints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file contains the different endpoints your bot can use.

# Server where the models are pulled from.
# https://rasa.com/docs/rasa/model-storage#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/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/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>
# use_ssl: <whether or not the communication is encrypted, default false>

#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/event-brokers

#event_broker:
# url: localhost
# username: username
# password: password
# queue: queue
Loading

0 comments on commit 1326fc5

Please sign in to comment.