dialogy.workflow package

Submodules

dialogy.workflow.workflow module

The Workflow represents a black box for an SLU microservice, and its terminals, input and output represent request response structure of the SLU API.

Note

The Input has some extra properties that aren’t part of the SLU API. We have kept reserves for intermediates, and flattened as most other nested inputs aren’t required and add to bloat.

Attention

Input and Output instances are immutable.

What does it do?

Produce the response for a single turn of a conversation. It recieves (not an exhaustive list):

  • Utterance.

  • Timezone

  • Language code

  • Locale

  • Current State of the conversation

  • Slot tracker

as inputs, parses these, produces a few intermediates and finally returns the intent and optionally entities. Details will be documented within the specific plugins.

classDiagram direction TB Workflow --> "1" Input: has Workflow --> "1" Output: has Workflow --> "many" Plugin: has class Workflow { Workflow: +Input input Workflow: +Output output Workflow: +set(path: str, value: Any) Workflow: +run(input: Input) } class Input { +List~Utterance~ utterance +int reference_time +str current_state +str lang +str locale +dict slot_tracker +str timezone +dict json() } class Output { +List~Intent~ intents +List~BaseEntity~ entities +dict json() } <<abstract>> Plugin class Plugin { +str dest *any utility(input: Input, output: Output) }

How does it do it?

  • A workflow contains a sequence of plugins. The sequence is important.

  • The sequence describes the order in which plugins are run.

  • The plugins can save their output within the workflow’s input or output.

  • After execution of all plugins, the workflow returns a pair of serialized input and output.

flowchart TB subgraph Workflow subgraph input utterance reference_time end subgraph output intents entities end input --> plugin output --> plugin plugin -->|update| input plugin -->|update| output plugin -->|foreach| plugin end output --> output_json input --> input_json output_json --> workflow_output input_json --> workflow_output subgraph Response output_json end
class Workflow(plugins=NOTHING, debug=False, *, input=None, output=None)[source]

Bases: object

SLU API blackbox.

NON_SERIALIZABLE_FIELDS = ['plugins', 'debug', 'lock']
debug

Switch on/off the debug logs for the workflow.

execute()[source]

Update input, output attributes.

We iterate through pre/post processing functions and update the input and output attributes of the class. It is expected that pre-processing functions would modify the input, and post-processing functions would modify the output.

Return type

Workflow

flush()[source]

Reset workflow.input and workflow.output.

Return type

Tuple[Dict[str, Any], Dict[str, Any]]

input: Optional[dialogy.base.input.Input]

Represents the SLU API request object. A few nested properties and intermediates are flattened out for readability.

json()[source]

Represent the workflow as a python dict.

Return type

Dict[str, Any]

lock: _thread.allocate_lock

A workflow isn’t thread-safe by itself. We need locks to prevent race conditions.

output: Optional[dialogy.base.output.Output]

Represents the SLU API response object.

plugins

List of plugins.

run(input_)[source]

Get final results from the workflow.

The current workflow exhibits the following simple procedure: pre-processing -> inference -> post-processing.

Return type

Tuple[Dict[str, Any], Dict[str, Any]]

set(path, value, replace=False, sort_output_attributes=True)[source]

Set attribute path with value.

This method (re)-sets the input or output object without losing information from previous instances.

Parameters
  • path (str) – A ‘.’ separated attribute path.

  • value (bool) – A value to set.

  • sort_output_attributes (bool) – A boolean to sort output attributes.

Returns

This instance

Return type

Workflow

train(training_data)[source]

Train all the plugins in the workflow.

Plugin’s have a no-op train method by default. The one’s that do require training should override this method. All trainable plugins manage their data validation (in case the data isn’t suitable for them) and saving/loading artifacts.

Parameters

training_data (pd.DataFrame) – [description]

Return type

Workflow

Module contents