Skip to content

Commit

Permalink
File upload download fix (#1073)
Browse files Browse the repository at this point in the history
* 1. Fixed Multiflow stories upload download issue where it was skipping intents, utterances and actions already present in the bot.
2. Added test cases
3. Fixed test cases.

---------

Co-authored-by: Nupur Khare <[email protected]>
  • Loading branch information
nupur-khare and Nupur Khare authored Nov 10, 2023
1 parent 6a60039 commit 37a3c75
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 14 deletions.
3 changes: 3 additions & 0 deletions kairon/importer/validator/file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ def verify_utterance_and_actions_in_multiflow_stories(self, raise_exception: boo
utterances = events
elif step_type != StoryStepType.intent.value and step_type != StoryStepType.slot.value:
actions.extend(events)
if step_type == StoryStepType.form_action.value:
user_actions.update(event for event in events
if event in self.domain.form_names and f"validate_{event}" in user_actions)

for utterance in utterances:
if utterance not in user_actions:
Expand Down
3 changes: 2 additions & 1 deletion kairon/shared/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,8 @@ def get_names_for_events(graph: DiGraph, step_type: str):
def get_step_name_for_multiflow_stories(story_graph: list, step_type: str):
name = set()
for graph in story_graph:
name = StoryValidator.get_names_for_events(graph, step_type)
events = StoryValidator.get_names_for_events(graph, step_type)
name.update(events)
return name


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
form_validation_action:
- invalid_response: Please ensure that you attach a valid image file. This upload
only supports image file.
is_required: true
name: validate_form_image
slot: var_image1
slot_set:
type: slot
value: image
valid_response: ''
validation_semantic: if (slot['image'] == null) { return false; } else { return
true; }
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ nlu:
- yes
- Yeah!
- It's a yes
- intent: query
examples: |
- I have a doubt
- Doubt!
- I have a question
- intent: priority
examples: |
- low
- priority is low
- intent: food
examples: |
- food suggestions
- Hungry!
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,45 @@ intents:
use_entities: true
- affirm:
use_entities: true
- query:
use_entities: true
- priority:
use_entities: true
- food:
use_entities: true
entities:
- var_image1
slots:
var_image1:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: false
influence_conversation: false
responses:
utter_goodbye:
- text: Bye
utter_greet:
- text: Hey! How are you?
utter_affirm:
- text: Your answer is yes!
utter_query:
- text: Your answer is yes!
utter_priority:
- text: Your answer is yes!
utter_food:
- text: Your answer is yes!
utter_default:
- text: Can you rephrase!

actions:
- validate_form_image
- action_say_hello
- action_say_goodbye
- utter_greet
- utter_goodbye
- utter_affirm
forms:
form_image:
required_slots:
var_image1:
- type: from_text
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,77 @@ multiflow_story:
start_checkpoints: [STORY_START]
end_checkpoints: []
template_type: CUSTOM
- block_name: mf_two_w
events:
- step:
name: query
type: INTENT
node_id: "7"
component_id: "61m96mPvb2VexybDeVg1dLyH"
connections:
- name: utter_query
type: BOT
node_id: "8"
component_id: "61uaImwNrsJI1pVphc0mZh20"
- step:
name: utter_query
type: BOT
node_id: "8"
component_id: "61uaImwNrsJI1pVphc0mZh20"
connections:
- name: priority
type: INTENT
node_id: "9"
component_id: "62By0VXVazUNDNPqkr5vRRzm"
- name: food
type: INTENT
node_id: "10"
component_id: "62N9BCfSKVYOKoSixGhWDRHC"
- step:
name: priority
type: INTENT
node_id: "9"
component_id: "62By0VXVazUNDNPqkr5vRRzm"
connections:
- name: utter_priority
type: BOT
node_id: "11"
component_id: "62uzXd9Pj1q9tEbVBkMuVn3o"
- step:
name: utter_priority
type: BOT
node_id: "11"
component_id: "62uzXd9Pj1q9tEbVBkMuVn3o"
connections: null
- step:
name: food
type: INTENT
node_id: "10"
component_id: "62N9BCfSKVYOKoSixGhWDRHC"
connections:
- name: form_image
type: FORM_ACTION
node_id: "12"
component_id: "62ib6tlbgICth8vBSwSYFvbS"
- step:
name: form_image
type: FORM_ACTION
node_id: "12"
component_id: "62ib6tlbgICth8vBSwSYFvbS"
connections:
- name: utter_food
type: BOT
node_id: "13"
component_id: "62ib6tlbgIGth8vBSwSYFoPS"
- step:
name: utter_food
type: BOT
node_id: "13"
component_id: "62ib6tlbgIGth8vBSwSYFoPS"
connections: null
metadata:
- node_id: "13"
flow_type: STORY
start_checkpoints: [STORY_START]
end_checkpoints: []
template_type: CUSTOM
10 changes: 5 additions & 5 deletions tests/unit_test/events/events_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,11 @@ def _path(*args, **kwargs):
assert logs[0]['event_status'] == EVENT_STATUS.COMPLETED.value

assert len(mongo_processor.fetch_stories(bot)) == 2
assert len(list(mongo_processor.fetch_training_examples(bot))) == 10
assert len(list(mongo_processor.fetch_responses(bot))) == 4
assert len(mongo_processor.fetch_actions(bot)) == 2
assert len(list(mongo_processor.fetch_training_examples(bot))) == 17
assert len(list(mongo_processor.fetch_responses(bot))) == 7
assert len(mongo_processor.fetch_actions(bot)) == 3
assert len(mongo_processor.fetch_rule_block_names(bot)) == 3
assert len(mongo_processor.fetch_multiflow_stories(bot)) == 1
assert len(mongo_processor.fetch_multiflow_stories(bot)) == 2

def test_trigger_data_importer_stories_only(self, monkeypatch, get_training_data):
bot = 'test_trigger_data_importer_stories_only'
Expand Down Expand Up @@ -1138,7 +1138,7 @@ def test_trigger_model_testing_event_2(self):
assert not os.path.exists(os.path.join('./testing_data', bot))

def test_trigger_history_deletion_for_bot(self):
from datetime import datetime, timedelta
from datetime import datetime
bot = 'test_events_bot'
user = 'test_user'
till_date = datetime.utcnow().date()
Expand Down
15 changes: 8 additions & 7 deletions tests/unit_test/validator/data_importer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import shutil
import tempfile
import uuid

import pytest
from mongoengine import connect

from kairon.shared.utils import Utility
from kairon.shared.data.constant import REQUIREMENTS
from kairon.shared.data.processor import MongoProcessor
from kairon.exceptions import AppException
from kairon.importer.data_importer import DataImporter
from kairon.shared.data.constant import REQUIREMENTS
from kairon.shared.data.processor import MongoProcessor
from kairon.shared.utils import Utility


def pytest_namespace():
Expand Down Expand Up @@ -135,11 +136,11 @@ async def test_import_data_with_multiflow(self):
assert 'greet' in processor.fetch_intents(bot)
assert 'deny' in processor.fetch_intents(bot)
assert len(processor.fetch_stories(bot)) == 2
assert len(list(processor.fetch_training_examples(bot))) == 10
assert len(list(processor.fetch_responses(bot))) == 5
assert len(processor.fetch_actions(bot)) == 2
assert len(list(processor.fetch_training_examples(bot))) == 17
assert len(list(processor.fetch_responses(bot))) == 8
assert len(processor.fetch_actions(bot)) == 3
assert len(processor.fetch_rule_block_names(bot)) == 4
assert len(processor.fetch_multiflow_stories(bot)) == 1
assert len(processor.fetch_multiflow_stories(bot)) == 2

@pytest.mark.asyncio
async def test_import_data_append(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_test/validator/training_data_validator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,11 @@ async def test_validate_valid_training_data_with_multiflow_stories(self):
nlu_path = 'tests/testing_data/multiflow_stories/valid_with_multiflow/data'
config_path = 'tests/testing_data/multiflow_stories/valid_with_multiflow/config.yml'
validator = await TrainingDataValidator.from_training_files(nlu_path, domain_path, config_path, root)
validator.validate_training_data()
validator.validate_training_data(False)
assert not validator.summary.get('intents')
assert not validator.summary.get('utterances')
assert not validator.summary.get('stories')
assert not validator.summary.get('form_validation_actions')
assert not validator.summary.get('multiflow_stories')
assert not validator.summary.get('training_examples')
assert not validator.summary.get('domain')
Expand Down

0 comments on commit 37a3c75

Please sign in to comment.