plan4dial.for_generating.custom_actions.slot_fill

Contains all the functions for the slot_fill custom action that is provided to bot designers by default.

Authors: - Rebecca De Venezia

Functions

slot_fill(loaded_yaml, action_name, ...[, ...])

Custom action provided by default that allows bot designers to specify entity slot fills with ease.

_clarify_act(entity: str, message_variants: List[str], single_slot: bool, additional_updates: Dict | None = None) Dict[source]

Generates a clarify action for an entity.

Parameters:
  • entity (str) – The entity to generate the action for.

  • message_variants (List[str]) – The message variants for the clarification action.

  • single_slot (bool) – Determines if this entity also has a single_slot action. This is necessary because of the situation where we “maybe” found the entity in the original action, try to clarify it and fail, and we were trying to extract > 1 entities originally. In that case, we need to activate the appropriate single_slot.

  • additional_updates (Dict, optional) – Any additional updates. In reality, it will only consider those where just this entity is extracted. Defaults to None.

Returns:

The clarify action configuration.

Return type:

Dict

_create_clarifications_single_slots(original_act_name: str, original_act_config: Dict, entities: List[str], config_entities: Dict, context_variables: Dict, additional_updates: Dict | None = None) Tuple[Dict, Dict][source]

Used by the slot_fill action to generate clarify and single_slot actions where necessary.

Parameters:
  • original_act_name (str) – The action name given to the original slot_fill action.

  • original_act_config (Dict) – The configuration of the original slot_fill action.

  • entities (List[str]) – The total list of entities to extract.

  • config_entities (Dict) – Configurations for these entities that hold more information.

  • context_variables (Dict) – The context variable configuration from loaded_yaml.

  • additional_updates (Dict, optional) – Any additional updates. Defaults to None.

Returns:

The new actions and context variables to be added.

Return type:

Tuple[Dict, Dict]

_single_slot(entity: str, config_entity: Dict, known_is_fflag: bool, additional_updates: Dict | None = None) None[source]

Generates a ‘single slot’ action for the entity provided. These are only necessary when multiple entities were specified, to handle the case where the bot is able to only extract some on its first go and clarify actions as well as actions that extract an entity on its own (single_slot) need to take care of the rest.

Parameters:
  • entity (str) – The entity to generate the action for.

  • config_entity (Dict) – The config_entities configuration for this entity. Necessary so that we can access the single_slot_message_variants and fallback_message_variants if they exist.

  • known_is_fflag (bool) – Indicates if the known setting for the entity in question is of type fflag.

  • additional_updates (Dict, optional) – Any additional updates. In reality, it will only consider those where just this entity is extracted, or maybe extracted. Defaults to None.

Returns:

The single_slot action configuration.

Return type:

Dict

slot_fill(loaded_yaml: Dict, action_name: str, message_variants: List[str], entities: List[str], overall_intent: str, config_entities: Dict | None = None, fallback_message_variants: List[str] | None = None, additional_conditions: Dict | None = None, additional_updates: Dict | None = None) None[source]

Custom action provided by default that allows bot designers to specify entity slot fills with ease.

Handles actions that can be clarified, as well as those that can’t, or a mix of both. This depends on what the known’s type setting is for each entity in the YAML.

Also handles “partial” extraction, where the bot asks for multiple entities but is only able to extract some. In that case, the bot will follow up with clarify actions in which it tries to extract uncertain entities, or single_slot actions in which it tries to extract unknown entities individually in order to make up for the missing information (only used when there are > 1 entities specified).

Additional outcomes can also be specified for certain outcomes, i.e. when entity pizza is extracted, respond with the given response_variants.

Parameters:
  • loaded_yaml (Dict) – The loaded YAML configuration.

  • action_name (str) – The name of this instance of the custom action.

  • message_variants (List[str]) – Possible messages the bot will utter upon execution of this action.

  • entities (List[str]) – The entities to be extracted or have their “slots filled.”

  • overall_intent (str) – The name of the intent that will extract all the entities.

  • config_entities (Dict) –

    Holds configurations that specify what the bot should do in certain situations regarding each entity. The keys are each entity and the values are the configuration for each entity. Defaults to None as this is not always necessary (again note that single_slot only occurs if there are > 1 entities here). The 4 configuration options for each entity are:

    clarify_message_variants (List[str]): The message variants that will be used for the clarify action for this entity. Only necessary if the known type of this entity is of type fflag.
    single_slot_message_variants (List[str]): Custom message variants to utter for single_slot extractions of the given entity.
    single_slot_intent (str): If single_slot extraction is being used, this indicates the intent to detect for that extraction (the intent that extracts this singular entity). Can also be detected in initial extraction if only one of multiple entities are found.
    fallback_message_variants (List[str]): Custom fallback messages to utter if the bot tries to extract this entity by itself with a single_slot action and fails. Differs from the outer fallback_message_variants parameter, which applies to the initial slot_fill action only. The default fallback messages will replace this parameter if not specified.

  • fallback_message_variants (List[str]) – Custom fallback messages to utter if the bot fails to extract any entities. Defaults to None.

  • additional_updates (Dict, optional) –

    Additional updates to specify when a given extraction happens AT ANY POINT. Indicate the extraction that happens in the outcome by specifying the known status of the entities you desire. You can not only use this to add arbitrary context variable updates under updates but also specify response_variants and follow_up.

    NOTE: Will only match to outcomes that match the given specification exactly. For example, if you specify an additional update for when test1 is known, updates would only be added to actions where ONLY test1 is extracted, and not when test1, test2 and test3 are extracted, for example. This is done to reduce ambiguity. Defaults to None.

  • additional_conditions (Dict, optional) – Additional conditions necessary before executing the slot_fill action. Defaults to None.

See the tutorial for an example of a slot_fill action.