mindmeld.components.dialogue module

This module contains the dialogue manager component of MindMeld

exception mindmeld.components.dialogue.DialogueStateException(message=None, target_dialogue_state=None)[source]

Bases: Exception

class mindmeld.components.dialogue.AutoEntityFilling(handler, form, app)[source]

Bases: object

A class to implement Automatic Entity (Slot) Filling (AEF) that allows developers to prompt users for completing the missing requirements for entity slots.

call_async(request, responder)[source]

The slot-filling call for asynchronous apps

Parameters:
  • request (Request) -- The request object.
  • responder (DialogueResponder) -- The responder object.
invoke(request, responder)[source]

Invoke slot-filling as a direct call without requiring a decorator.

invoke_async(request, responder)[source]

Async invoke slot-filling as a direct call without requiring a decorator.

class mindmeld.components.dialogue.Conversation(app=None, app_path=None, nlp=None, context=None, default_params=None, force_sync=False, verbose=False)[source]

Bases: object

The conversation object is a very basic MindMeld client.

It can be useful for testing out dialogue flows in python.

Example

>>> convo = Conversation(app_path='path/to/my/app')
>>> convo.say('Hello')
['Hello. I can help you find store hours. How can I help?']
>>> convo.say('Is the store on elm open?')
['The 23 Elm Street Kwik-E-Mart is open from 7:00 to 19:00.']
history

list -- The history of the conversation. Starts with the most recent message.

context

dict -- The context of the conversation, containing user context.

default_params

Params -- The default params to use with each turn. These defaults will be overridden by params passed for each turn.

params

FrozenParams -- The params returned by the most recent turn.

force_sync

bool -- Force synchronous return for say() and process() even when app is in async mode.

verbose

bool, optional -- If True, returns class probabilities along with class prediction.

process(text, params=None, force_sync=False)[source]

Send a message in the conversation. The message will be processed by the app based on the current state of the conversation and returns the response.

Parameters:
  • text (str) -- The text of a message.
  • params (dict) -- The params to use with this message, overriding any defaults which may have been set.
  • force_sync (bool, optional) -- Force synchronous response even when app is in async mode.
Returns:

The dictionary response.

Return type:

(dict)

reset()[source]

Reset the history, frame and params of the Conversation object.

say(text, params=None, force_sync=False)[source]

Send a message in the conversation. The message will be processed by the app based on the current state of the conversation and returns the extracted messages from the directives.

Parameters:
  • text (str) -- The text of a message.
  • params (dict) -- The params to use with this message, overriding any defaults which may have been set.
  • force_sync (bool, optional) -- Force synchronous response even when app is in async mode.
Returns:

A text representation of the dialogue responses.

Return type:

(list)

class mindmeld.components.dialogue.DialogueFlow(name, entrance_handler, app, **kwargs)[source]

Bases: mindmeld.components.dialogue.DialogueManager

A special dialogue manager subclass used to implement dialogue flows. Dialogue flows allow developers to implement multiple turn interactions where only a subset of dialogue states should be accessible or where different dialogue rules should apply.

app

Application -- The application that initializes this flow.

exit_flow_states

list -- The list of exit states.

handle(**kwargs)[source]

The dialogue flow handler.

use_middleware(*args)[source]

Allows a middleware to be added to this flow.

all_flows = {}

The dictionary that references all dialogue flows.

dialogue_manager

The dialogue manager which contains this flow.

flow_state

The state of the flow (<name>_flow).

logger = <Logger mindmeld.components.dialogue.DialogueFlow (WARNING)>

Class logger.

name

The name of this flow.

class mindmeld.components.dialogue.DialogueManager(responder_class=None, async_mode=False)[source]

Bases: object

add_dialogue_rule(name, handler, **kwargs)[source]

Adds a dialogue state rule for the dialogue manager.

Parameters:
  • name (str) -- The name of the dialogue state.
  • handler (function) -- The dialogue state handler function.
  • kwargs (dict) -- A list of options to be passed to the DialogueStateRule initializer.
add_middleware(middleware)[source]

Adds middleware for the dialogue manager. Middleware will be called for each message before the dialogue state handler. Middleware registered first will be called first.

Parameters:middleware (callable) -- A dialogue manager middleware function.
apply_handler(request, responder, target_dialogue_state=None)[source]

Applies the dialogue state handler for the most complex matching rule.

Parameters:
  • request (Request) -- The request object.
  • responder (DialogueResponder) -- The responder object.
  • target_dialogue_state (str, optional) -- The target dialogue state.
Returns:

A DialogueResponder containing the dialogue state and directives.

Return type:

(DialogueResponder)

handle(**kwargs)[source]

A decorator that is used to register dialogue state rules.

middleware(*args)[source]

A decorator that is used to register dialogue handler middleware.

static reprocess(target_dialogue_state=None)[source]

Forces the dialogue manager to back out of the flow based on the initial target dialogue state setting and reselect a handler, following a new target dialogue state

Parameters:target_dialogue_state (str, optional) -- a dialogue_state name to push system into
logger = <Logger mindmeld.components.dialogue.DialogueManager (WARNING)>
class mindmeld.components.dialogue.DialogueResponder(frame=None, params=None, history=None, slots=None, request=None, dialogue_state=None, directives=None, form=None)[source]

Bases: object

The dialogue responder helps generate directives and fill slots in the system-generated natural language responses.

class DirectiveNames

Bases: object

The list of directive names.

LIST = 'list'
LISTEN = 'listen'
REPLY = 'reply'
RESET = 'reset'
SLEEP = 'sleep'
SPEAK = 'speak'
SUGGESTIONS = 'suggestions'
class DirectiveTypes

Bases: object

The list of directive types.

ACTION = 'action'
VIEW = 'view'
act(name, payload=None)[source]

Adds an arbitrary directive of type 'action'.

Parameters:
  • name (str) -- The name of the directive.
  • payload (dict, optional) -- The payload for the action.
direct(name, dtype, payload=None)[source]

Adds an arbitrary directive.

Parameters:
  • name (str) -- The name of the directive.
  • dtype (str) -- The type of the directive.
  • payload (dict, optional) -- The payload for the view.
display(name, payload=None)[source]

Adds an arbitrary directive of type 'view'.

Parameters:
  • name (str) -- The name of the directive.
  • payload (dict, optional) -- The payload for the view.
exit_flow()[source]

Exit the current flow by clearing the target dialogue state.

list(items)[source]

Adds a 'list' view directive.

Parameters:items (list) -- The list of dictionary objects.
listen()[source]

Adds a 'listen' directive.

prompt(text)[source]

Alias for reply(). Deprecated.

Parameters:text (str) -- The text of the reply.
reply(text)[source]

Adds a 'reply' directive.

Parameters:text (str) -- The text of the reply.
reset()[source]

Adds a 'reset' directive.

respond(directive)[source]

Adds an arbitrary directive.

Parameters:directive (dict) -- A directive.
sleep(delay=0)[source]

Adds a 'sleep' directive.

Parameters:delay (int) -- The amount of milliseconds to wait before putting the client to sleep.
speak(text)[source]

Adds a 'speak' directive.

Parameters:text (str) -- The text to speak aloud.
suggest(suggestions)[source]

Adds a 'suggestions' directive.

Parameters:suggestions (list) -- A list of suggestions.
history
params
request
class mindmeld.components.dialogue.DialogueStateRule(dialogue_state, **kwargs)[source]

Bases: object

A rule that determines a dialogue state. Each rule represents a pattern that must match in order to invoke a particular dialogue state.

dialogue_state

str -- The name of the dialogue state.

domain

str -- The name of the domain to match against.

entity_types

set -- The set of entity types to match against.

intent

str -- The name of the intent to match against.

targeted_only

bool -- Whether the state is targeted only.

default

bool -- Whether this is the default state.

apply(request)[source]

Applies the dialogue state rule to the given context.

Parameters:request (Request) -- A request object.
Returns:Whether or not the context matches.
Return type:(bool)
static compare(this, that)[source]

Compares the complexity of two dialogue state rules. :param this: A dialogue state rule. :type this: DialogueStateRule :param that: A dialogue state rule. :type that: DialogueStateRule

Returns:
The comparison result
-1: that is more complex than this 0: this and that are equally complex 1: this is more complex than that
Return type:(int)
complexity

Returns an integer representing the complexity of this dialogue state rule. Components of a rule in order of increasing complexity are as follows: default rule, domains, intents, entity types, entity mappings.

Returns:A number representing the rule complexity.
Return type:(int)
logger = <Logger mindmeld.components.dialogue.DialogueStateRule (WARNING)>

Class logger.

class mindmeld.components.dialogue.DirectiveNames[source]

Bases: object

A constants object for directive names.

LIST = 'list'

A directive to display a list.

LISTEN = 'listen'

A directive to listen (start speech recognition).

REPLY = 'reply'

A directive to display a text view.

RESET = 'reset'

A directive to reset.

SLEEP = 'sleep'

A directive to put the client to sleep after a specified number of milliseconds.

SPEAK = 'speak'

A directive to speak text out loud.

SUGGESTIONS = 'suggestions'

A view for a list of suggestions.

class mindmeld.components.dialogue.DirectiveTypes[source]

Bases: object

A constants object for directive types.

ACTION = 'action'

A view directive.

VIEW = 'view'

An action directive.

class mindmeld.components.dialogue.Form(entities: Optional[List[mindmeld.core.FormEntity]] = None, exit_keys: Optional[List[str]] = None, exit_msg: Optional[str] = None, max_retries: Optional[str] = None)[source]

Bases: object

This class incapsulates Form data

entities