Script#

The Script module provides a set of pydantic models for representing the dialog graph.

These models are used by Actor 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

Node is a basic element of the dialog graph.

Usually used to represent a specific state of a conversation.

transitions: List[Transition]#

List of transitions possible from this node.

response: Optional[AnyResponse]#

Response produced when this node is entered.

pre_transition: Dict[str, BaseProcessing]#

A dictionary of BaseProcessing functions that are executed before transitions are processed. Keys of the dictionary act as names for the processing functions.

pre_response: Dict[str, BaseProcessing]#

A dictionary of BaseProcessing functions that are executed before response is processed. Keys of the dictionary act as names for the processing functions.

misc: dict#

A dictionary that is used to store metadata about the node.

Can be accessed at runtime via current_node.

inherit_from_other(other)[source]#

Inherit properties from another node into this one:

  • Extend self.transitions with transitions of the other node;

  • Replace response with other.response if self.response is None;

  • Dictionaries (pre_transition, pre_response and misc) are appended to this node’s dictionaries except for the repeating keys. For example, inherit_from_other({1: 1, 3: 3}, {1: 0, 2: 2}) == {1: 1, 3: 3, 2: 2}.

Basically, only non-conflicting properties of other are inherited.

class Flow(**data)[source]#

Bases: BaseModel

Flow is a collection of nodes. This is used to group them by a specific purpose.

local_node: Node#

Node from which all other nodes in this Flow inherit properties according to Node.inherit_from_other().

property nodes: Dict[str, Node]#

A dictionary of all non-local nodes in this flow.

Keys in the dictionary acts as names for the nodes.

get_node(name)[source]#

Get node with the name.

Return type:

Optional[Node]

Returns:

Node or None if it doesn’t exist.

class Script(**data)[source]#

Bases: BaseModel

A script is a collection of nodes. It represents an entire dialog graph.

global_node: Node#

Node from which all other nodes in this Script inherit properties according to Node.inherit_from_other().

property flows: Dict[str, Flow]#

A dictionary of all flows in this script.

Keys in the dictionary acts as names for the flows.

get_flow(name)[source]#

Get flow with the name.

Return type:

Optional[Flow]

Returns:

Flow or None if it doesn’t exist.

get_node(label)[source]#

Get node with the label.

Return type:

Optional[Node]

Returns:

Node or None if it doesn’t exist.

get_inherited_node(label)[source]#

Return a new node that inherits (using Node.inherit_from_other()) properties from Node, Flow.local_node and Script.global_node (in that order).

Flow and node are determined by label.

This is essentially a copy of the node specified by label, that inherits properties from local_node and global_node.

Return type:

Optional[Node]

Returns:

A new node or None if it doesn’t exist.

GLOBAL = 'GLOBAL'#

Key for global_node.

LOCAL = 'LOCAL'#

Key for local_node.

TRANSITIONS = 'TRANSITIONS'#

Key for transitions.

RESPONSE = 'RESPONSE'#

Key for response.

MISC = 'MISC'#

Key for misc.

PRE_RESPONSE = 'PRE_RESPONSE'#

Key for pre_response.

PRE_TRANSITION = 'PRE_TRANSITION'#

Key for pre_transition.