Script#

The Script module provides a set of pydantic models for representing the dialog graph. These models are used to define the conversation flow, and to determine the appropriate response based on the user’s input and the current state of the conversation.

class Node(**data)[source]#

Bases: BaseModel

The class for the Node object.

transitions: Dict[NodeLabelType, ConditionType]#
response: Optional[Union[Message, Callable[[Context, Pipeline], Message]]]#
pre_transitions_processing: Dict[Any, Callable]#
pre_response_processing: Dict[Any, Callable]#
misc: dict#
classmethod normalize_transitions(cls, transitions)[source]#

The function which is used to normalize transitions and returns normalized dict.

Parameters:

transitions (Dict[Union[Callable, Tuple[str, float], Tuple[str, str], Tuple[str, str, float], str], Callable]) – Transitions to normalize.

Return type:

Dict[Union[Callable, Tuple[str, str, float]], Callable]

Returns:

Transitions with normalized label and condition.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class Script(**data)[source]#

Bases: BaseModel

The class for the Script object.

script: Dict[LabelType, Dict[LabelType, Node]]#
classmethod normalize_script(cls, script)[source]#

This function normalizes Script: it returns dict where the GLOBAL node is moved into the flow with the GLOBAL name. The function returns the structure

{GLOBAL: {…NODE…}, …} -> {GLOBAL: {GLOBAL: {…NODE…}}, …}.

Parameters:

script (Dict[Union[str, Keywords], Any]) – Script that describes the dialog scenario.

Return type:

Dict[Union[str, Keywords], Dict[Union[str, Keywords], Dict[str, Any]]]

Returns:

Normalized Script.

get(key, value=None)[source]#
keys()[source]#
items()[source]#
values()[source]#
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].