Skip to content

Commit

Permalink
amend update of default slot
Browse files Browse the repository at this point in the history
  • Loading branch information
ancalita committed Aug 11, 2023
1 parent 8ce9432 commit 81e11b8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rasa/cdu/command_generator/command_prompt_template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Based on this information generate a list of actions you want to take. Your job
* Responding to a non-task-oriented user message, described by "ChitChat()".
* Responding to a user message that requires additional knowledge from a knowledge database, described by "KnowledgeAnswer()"
* Handing off to a human, in case the user seems frustrated or explicitly asks to speak to one, described by "HumanHandoff()".
* Updating a user profile with information from the user message, described by "UpdateUserProfile()".
* Updating a user profile with metadata about the user message, described by "UpdateUserProfile(metadata=metadata)". Metadata should be a dictionary of key-value pairs, e.g. {"sentiment": "frustrated", "time_of_day": "2021-07-03 16:21:12.357246"}.

===
Write out the actions you want to take, one per line, in the order they should take place.
Expand Down
1 change: 1 addition & 0 deletions rasa/cdu/command_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def execute_commands(
)
elif isinstance(command, UpdateUserProfileCommand):
structlogger.debug("command_executor.update_user_profile", command=command)
events.append(SlotSet("metadata", command.metadata))
flow_stack.push(
FlowStackFrame(
flow_id=FLOW_PATTERN_UPDATE_USER_PROFILE_ID,
Expand Down
1 change: 1 addition & 0 deletions rasa/cdu/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ class UpdateUserProfileCommand(Command):
"""A command to indicate that the bot should update the user profile."""

command: str = "update user profile"
metadata: Dict[str, Any] = None
8 changes: 6 additions & 2 deletions rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,10 @@ def run(
if user_profile_slot is None:
user_profile_slot = {}

# set user profile properties
metadata = tracker.get_slot("metadata")

return [SetSlot("user_profile", user_profile_slot)]
if metadata is not None:
for key, value in metadata.items():
user_profile_slot[key] = value

return [SlotSet("user_profile", user_profile_slot)]
13 changes: 8 additions & 5 deletions rasa/shared/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ def _add_default_slots(self) -> None:
"""Sets up the default slots and slot values for the domain."""
self._add_requested_slot()
self._add_flow_slots()
self._add_user_profile_slot()
self._add_knowledge_base_slots()
self._add_categorical_slot_default_value()
self._add_session_metadata_slot()
Expand Down Expand Up @@ -993,12 +994,14 @@ def _add_flow_slots(self) -> None:

def _add_user_profile_slot(self) -> None:
"""Add a slot called `user_profile_slot` to the list of slots."""
if "user_profile" not in [slot.name for slot in self.slots]:
self.slots.append(
AnySlot(
"user_profile", mappings=[], influence_conversation=False
user_profile_slots = ["user_profile", "metadata"]
existing_domain_slots = [slot.name for slot in self.slots]

for slot in user_profile_slots:
if slot not in existing_domain_slots:
self.slots.append(
AnySlot(slot, mappings=[], influence_conversation=False)
)
)

def _add_requested_slot(self) -> None:
"""Add a slot called `requested_slot` to the list of slots.
Expand Down

0 comments on commit 81e11b8

Please sign in to comment.