Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default flag for slots #1616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kairon/shared/data/data_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ class Slots(Auditlog):
status = BooleanField(default=True)
influence_conversation = BooleanField(default=False)
_has_been_set = BooleanField(default=False)
is_default = BooleanField(default=False)

meta = {"indexes": [{"fields": ["bot", ("bot", "status", "name")]}]}

Expand Down
11 changes: 7 additions & 4 deletions kairon/shared/data/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ def add_system_required_slots(self, bot: Text, user: Text):
bot,
user,
raise_exception_if_exists=False,
is_default = True
)

for slot in [s for s in KaironSystemSlots if s.value not in non_conversational_slots]:
Expand All @@ -1688,6 +1689,7 @@ def add_system_required_slots(self, bot: Text, user: Text):
bot,
user,
raise_exception_if_exists=False,
is_default=True
)

def fetch_slots(self, bot: Text, status=True):
Expand Down Expand Up @@ -3407,6 +3409,7 @@ def add_complex_story(self, story: Dict, bot: Text, user: Text):
bot,
user,
raise_exception_if_exists=False,
is_default=True
)

return id
Expand Down Expand Up @@ -3469,6 +3472,7 @@ def add_multiflow_story(self, story: Dict, bot: Text, user: Text):
bot,
user,
raise_exception_if_exists=False,
is_default=True
)

return id
Expand Down Expand Up @@ -4728,7 +4732,7 @@ def list_all_actions(self, bot: str, with_doc_id: bool = True):
action.pop("timestamp")
yield action

def add_slot(self, slot_value: Dict, bot, user, raise_exception_if_exists=True):
def add_slot(self, slot_value: Dict, bot, user, raise_exception_if_exists=True, is_default = False):
"""
Adds slot if it doesn't exist, updates slot if it exists
:param slot_value: slot data dict
Expand Down Expand Up @@ -4766,6 +4770,7 @@ def add_slot(self, slot_value: Dict, bot, user, raise_exception_if_exists=True):
slot.max_value = slot_value.get("max_value")
slot.min_value = slot_value.get("min_value")

slot.is_default = is_default
slot.user = user
slot.bot = bot
slot_id = slot.save().id.__str__()
Expand Down Expand Up @@ -5264,9 +5269,7 @@ def get_existing_slots(bot: Text):
:param status: active or inactive, default is active
:return: list of slots
"""
excluded_slots = list(KaironSystemSlots)
query = Q(bot=bot, status=True) & Q(name__nin=excluded_slots)
for slot in Slots.objects(query):
for slot in Slots.objects(bot=bot, status=True):
slot = slot.to_mongo().to_dict()
slot.pop("bot")
slot.pop("user")
Expand Down
11 changes: 3 additions & 8 deletions tests/integration_test/services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9699,18 +9699,13 @@ def test_get_slots():
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)
actual = response.json()
excluded_slots = list(KaironSystemSlots)

assert "data" in actual
assert len(actual["data"]) == 21
assert actual["success"]
assert actual["error_code"] == 0

assert len(actual["data"]) == 21 - len(excluded_slots)
returned_slot_names = [slot["name"] for slot in actual["data"]]
for excluded_slot in excluded_slots:
assert excluded_slot not in returned_slot_names

assert Utility.check_empty_string(actual["message"])
default_slots_count = sum(slot.get('is_default') for slot in actual["data"])
assert default_slots_count == 14
Comment on lines +9707 to +9708
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Default slot count assertion needs to be updated

The assertion expecting 14 default slots is incorrect. From the KaironSystemSlots enum definition in kairon/shared/constants.py, there are exactly 13 system slots:

  • kairon_action_response
  • bot
  • image
  • audio
  • video
  • document
  • doc_url
  • order
  • payment
  • longitude
  • latitude
  • flow_reply
  • quick_reply
  • http_status_code

The test assertion in tests/integration_test/services_test.py should be updated from 14 to 14 default slots.

🔗 Analysis chain

Verify the accuracy of default slot count

The assertion expects exactly 14 default slots. Let's verify this count is correct and consider making it more maintainable.

Let's verify the number of default slots:


Let me search for the system slots definition to verify the count.


Let me try a different pattern to locate the system slots definition.


Let me get the complete list of system slots by searching more lines after the enum definition.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for default slot definitions
# Expected: Find evidence supporting the count of 14 default slots

# Look for default slot definitions or configurations
rg -A 5 "is_default.*=.*True" 

# Search for any system or default slot enums/constants
ast-grep --pattern 'class $SLOTS {
  $$$
}'

Length of output: 1450


Script:

#!/bin/bash
# Search for KaironSystemSlots enum definition
ast-grep --pattern 'class KaironSystemSlots$_:
  $$$
'

# Also search for any references to system slots count
rg -i "system.*slots.*14"

Length of output: 84


Script:

#!/bin/bash
# Search for enum class definition with a broader pattern
ast-grep --pattern 'class KaironSystemSlots'

# Search for slot-related enums or constants
rg -A 10 "class.*SystemSlots"

# Search for default slots in a different way
rg -A 10 "DEFAULT_SLOTS" 

Length of output: 688


Script:

#!/bin/bash
# Search for the complete KaironSystemSlots enum definition
rg -A 20 "class KaironSystemSlots" kairon/shared/constants.py

# Also search for any slot-related tests
rg "assert.*slot.*count" tests/integration_test/

Length of output: 963



def test_add_slots():
Expand Down
37 changes: 26 additions & 11 deletions tests/unit_test/data_processor/data_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9348,21 +9348,36 @@ def test_get_slot(self):
processor = MongoProcessor()
slots = list(processor.get_existing_slots(bot))
expected = [
{'name': 'date_time', 'type': 'text', 'influence_conversation': True, '_has_been_set': False},
{'name': 'category', 'type': 'text', 'influence_conversation': False, '_has_been_set': False},
{'name': 'file', 'type': 'text', 'influence_conversation': False, '_has_been_set': False},
{'name': 'file_error', 'type': 'text', 'influence_conversation': False, '_has_been_set': False},
{'name': 'file_text', 'type': 'text', 'influence_conversation': False, '_has_been_set': False},
{'name': 'name', 'type': 'text', 'influence_conversation': True, '_has_been_set': False},
{'name': 'kairon_action_response', 'type': 'any', 'influence_conversation': False, '_has_been_set': False, 'is_default': True},
{'name': 'bot', 'type': 'any', 'initial_value': 'test', 'influence_conversation': False,
'_has_been_set': False, 'is_default': True},
{'name': 'order', 'type': 'any', 'influence_conversation': False, '_has_been_set': False, 'is_default': True},
{'name': 'payment', 'type': 'any', 'influence_conversation': False, '_has_been_set': False, 'is_default': True},
{'name': 'flow_reply', 'type': 'any', 'influence_conversation': False, '_has_been_set': False, 'is_default': True},
{'name': 'http_status_code', 'type': 'any', 'influence_conversation': False, '_has_been_set': False, 'is_default': True},
{'name': 'image', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': True},
{'name': 'audio', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': True},
{'name': 'video', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': True},
{'name': 'document', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': True},
{'name': 'doc_url', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': True},
{'name': 'longitude', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': True},
{'name': 'latitude', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': True},
{'name': 'date_time', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': False},
{'name': 'category', 'type': 'text', 'influence_conversation': False, '_has_been_set': False, 'is_default': False},
{'name': 'file', 'type': 'text', 'influence_conversation': False, '_has_been_set': False, 'is_default': False},
{'name': 'file_error', 'type': 'text', 'influence_conversation': False, '_has_been_set': False, 'is_default': False},
{'name': 'file_text', 'type': 'text', 'influence_conversation': False, '_has_been_set': False, 'is_default': False},
{'name': 'name', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': False},
{'name': 'priority', 'type': 'categorical', 'values': ['low', 'medium', 'high', '__other__'],
'influence_conversation': True, '_has_been_set': False},
'influence_conversation': True, '_has_been_set': False, 'is_default': False},
{'name': 'ticketid', 'type': 'float', 'initial_value': 1.0, 'max_value': 1.0, 'min_value': 0.0,
'influence_conversation': True, '_has_been_set': False},
'influence_conversation': True, '_has_been_set': False, 'is_default': False},
{'name': 'age', 'type': 'float', 'max_value': 1.0, 'min_value': 0.0, 'influence_conversation': True,
'_has_been_set': False},
{'name': 'occupation', 'type': 'text', 'influence_conversation': True, '_has_been_set': False},
'_has_been_set': False, 'is_default': False},
{'name': 'occupation', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': False},
{'name': 'quick_reply', 'type': 'text', 'influence_conversation': True, '_has_been_set': False, 'is_default': True}
]
assert len(slots) == 10
assert len(slots) == 24
assert not DeepDiff(slots, expected, ignore_order=True)

def test_update_slot_add_value_intent_and_not_intent(self):
Expand Down
Loading