Skip to content

Commit

Permalink
Merge pull request #11433 from RasaHQ/bugfix-session-config-follow-up
Browse files Browse the repository at this point in the history
Follow-up bugfix to merging separate domain files with custom session config
  • Loading branch information
ancalita authored Aug 11, 2022
2 parents f0bb41d + 7b419be commit 9268b74
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/11433.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This fix makes sure that when a Domain object is loaded from multiple files where one file specifies a custom session config and the rest do not, the default session configuration does not override the custom session config.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
recipe: default.v1
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

data:
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: RulePolicy
# - name: UnexpecTEDIntentPolicy
# max_history: 5
# epochs: 100
# - name: TEDPolicy
# max_history: 5
# epochs: 100
# constrain_similarities: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
version: "3.1"

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
- 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?
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3.1"


responses:
utter_test:
- text: "Hey! How are you?"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.1"

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.1"

intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge

responses:
utter_greet:
- text: "Hey! How are you?"

utter_cheer_up:
- 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: "Great, carry on!"

utter_goodbye:
- text: "Bye"

utter_iamabot:
- text: "I am a bot, powered by Rasa."

session_config:
session_expiration_time: 0
carry_over_slots_to_new_session: false
5 changes: 4 additions & 1 deletion rasa/shared/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ def merge_domain_dicts(
override
or combined.get(SESSION_CONFIG_KEY) == SessionConfig.default().as_dict()
or combined.get(SESSION_CONFIG_KEY) is None
) and domain_dict.get(SESSION_CONFIG_KEY):
) and domain_dict.get(SESSION_CONFIG_KEY) not in [
None,
SessionConfig.default().as_dict(),
]:
combined[SESSION_CONFIG_KEY] = domain_dict[SESSION_CONFIG_KEY]

# remove existing forms from new actions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from rasa.shared.core.domain import SessionConfig
from rasa.shared.importers.importer import TrainingDataImporter


def test_merge_domain_with_custom_session_config_and_no_session_config():
expected_session_expiration_time = 0
expected_carry_over_slots = False

config_path = (
"data/test_domains/"
"test_domain_files_with_no_session_config_and_custom_session_config/config.yml"
)
domain_path = (
"data/test_domains/"
"test_domain_files_with_no_session_config_and_custom_session_config/domain.yml"
)
training_data_paths = [
"data/test_domains/"
"test_domain_files_with_no_session_config_and_custom_session_config/data"
]
file_importer = TrainingDataImporter.load_from_config(
config_path, domain_path, training_data_paths
)

domain = file_importer.get_domain()

assert (
domain.session_config.session_expiration_time
!= SessionConfig.default().session_expiration_time
)
assert (
domain.session_config.carry_over_slots
!= SessionConfig.default().carry_over_slots
)

assert (
domain.session_config.session_expiration_time
== expected_session_expiration_time
)
assert domain.session_config.carry_over_slots == expected_carry_over_slots

0 comments on commit 9268b74

Please sign in to comment.