Intent Parameters¶
Intent Parameters are Intent
class members. There
are two kinds of parameter in Intents:
NLU Parameters are Entity types (or list of entities). They can be tagged in User utterance and extracted at prediction time. They are modelled by
NluIntentParameter
.SessionParameters are values that are injected in the Conversation context via software, either when triggering an intent, or at
fulfillment
time. Session parameters can contain complex structured data, but cannot be tagged in user utterances; therefore an intent with Session parameters will never be predicted. Session Parameters are modelled inSessionIntentParameter
.
-
class
IntentParameter
(name, required, default)[source]¶ Model metadata of a single Intent parameter. NluIntentParameter objects are built internally by
Intent.parameter_schema
based on the Intent dataclass fields.>>> OrderPizzaIntent.parameter_schema { 'pizza_type': NluIntentParameter(name='pizza_type', entity_cls=<...PizzaType'>, is_list=False, required=True, default=None), 'amount': NluIntentParameter(name='amount', entity_cls=<...Sys.Integer'>, is_list=False, required=False, default=1) }
This is a base class for two different kinds of intent parameters:
NluParameter
- Those that are tagged in User utterancesSessionParameter
- Those that are injected in session by triggers and fulfillments
- Parameters
name (
str
) – Parameter nameentity_cls – Parameter type
is_list – Parameter will match multiple values in the User utterance
required (
bool
) – If True, user will be prompted for parameter value when that can’t be tagged in his utterancedefault (
Any
) – If set, this value will be used when parameter value can’t be tagged in the User’s utterance
-
class
NluIntentParameter
(name, required, default, is_list, entity_cls)[source]¶ These are
IntentParameter
s that are tagged in User utterances (e.g. a pizza_type parameter can be tagged in the message of a user that is ordering pizza).Every member of an
Intent
dataclass that is annotated with an Entity type will be recognized as a NLU Parameter.- Parameters
name (
str
) – Parameter nameentity_cls (
EntityType
) – Parameter typeis_list (
bool
) – Parameter will match multiple values in the User utterancerequired (
bool
) – If True, user will be prompted for parameter value when that can’t be tagged in his utterancedefault (
Any
) – If set, this value will be used when parameter value can’t be tagged in the User’s utterance
-
class
ParameterSchema
[source]¶ -
property
nlu_parameters
¶ Return the ParameterSchema subset that only contains NLU Parameters
- Return type
Dict
[str
,NluIntentParameter
]- Returns
A map of NLU Parameters
-
property
session_parameters
¶ Return the ParameterSchema subset that only contains Session Parameters
- Return type
Dict
[str
,SessionIntentParameter
]- Returns
A map of Session Parameters
-
property
-
class
SessionIntentParameter
(name, required, default, data_type)[source]¶ These are
IntentParameter
s that are injected in the conversation by triggers and fulfillment procedre (e.g. a delivery_info dict can be sent when triggering an intent for pushing an order delivery update to User).Every member of an
Intent
class that is annotated with a primitive type,list
,dict
or adataclass
type will be recognized as a Session Parameter.- Parameters
name (
str
) – Parameter nameentity_cls – Parameter type
is_list – Parameter will match multiple values in the User utterance
required (
bool
) – If True, user will be prompted for parameter value when that can’t be tagged in his utterancedefault (
Any
) – If set, this value will be used when parameter value can’t be tagged in the User’s utterancedata_type (
Type
[~T]) –
-
is_serializable
()[source]¶ Return True if the Parameter specification is serializable as a string by
serialize_value()
- Returns
True if parameter is serializable as a string, False otherwise
-
serialize_value
(value)[source]¶ Serialize the given value based on data_type. These are the supported scenarios:
data_type is a JSON-serializable (
list
or adict
,str
,int
,float
) -> value is serialized as JSONdata_type is a dataclass -> value is converted to dict with custom
to_dict()
. In addition to standardasdict()
behavior, it will process Enums correctly.
- Parameters
value (
Any
) – The value to serialize based on the Parameter spec- Raises
ValueError – If data_type is not serializable
- Return type
str
- Returns
A string representation of value