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.
-
-
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: Returns: The dictionary response.
Return type: (dict)
-
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: 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.
-
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:
-
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)
-
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'¶
-
-
list
(items)[source]¶ Adds a 'list' view directive.
Parameters: items (list) -- The list of dictionary objects.
-
prompt
(text)[source]¶ Alias for reply(). Deprecated.
Parameters: text (str) -- The text of the reply.
-
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.
-
suggest
(suggestions)[source]¶ Adds a 'suggestions' directive.
Parameters: suggestions (list) -- A list of suggestions.
-
history
¶
-
params
¶
-
request
¶
-
class
-
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.
-