Skip to content

Commit

Permalink
re-reverting verbose (sorry) + in run_actions
Browse files Browse the repository at this point in the history
  • Loading branch information
patapizza committed Jun 4, 2016
1 parent c945693 commit 68ad3af
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- adding verbose option for `message`, `converse` and `run_actions`

## v3.5

- allows for overriding API version, by setting `WIT_API_VERSION`
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The Wit [message API](https://wit.ai/docs/http/20160330#get-intent-via-text-link

Takes the following parameters:
* `msg` - the text you want Wit.ai to extract the information from
* `verbose` - (optional) if set, calls the API with `verbose=true`

Example:
```python
Expand All @@ -114,6 +115,7 @@ Takes the following parameters:
* `message` - the text received from the user
* `context` - the dict representing the session state
* `max_steps` - (optional) the maximum number of actions to execute (defaults to 5)
* `verbose` - (optional) if set, calls the API with `verbose=true`

Example:
```python
Expand All @@ -133,6 +135,7 @@ Takes the following parameters:
* `session_id` - a unique identifier describing the user session
* `message` - the text received from the user
* `context` - the dict representing the session state
* `verbose` - (optional) if set, sets the API parameter `verbose` to `true`

Example:
```python
Expand Down
33 changes: 18 additions & 15 deletions wit/wit.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,36 @@ def __init__(self, access_token, actions, logger=None):
self.logger = logger or logging.getLogger(__name__)
self.actions = validate_actions(self.logger, actions)

def message(self, msg):
self.logger.debug('Message request: msg=%r', msg)
def message(self, msg, verbose=None):
self.logger.debug('Message request: msg=%r verbose=%s', msg, verbose)
params = {}
if msg:
params['q'] = msg
if verbose:
params['verbose'] = True
resp = req(self.access_token, 'GET', '/message', params)
self.logger.debug('Message response: %s', resp)
return resp


def converse(self, session_id, message, context=None):
self.logger.debug('Converse request: session_id=%s msg=%r context=%s',
session_id, message, context)
def converse(self, session_id, msg, context=None, verbose=None):
self.logger.debug('Converse request: session_id=%s msg=%r context=%s verbose=%s',
session_id, msg, context, verbose)
if context is None:
context = {}
params = {'session_id': session_id}
if message:
params['q'] = message
if msg:
params['q'] = msg
if verbose:
params['verbose'] = True
resp = req(self.access_token, 'POST', '/converse', params, json=context)
self.logger.debug('Message response: %s', resp)
return resp

def __run_actions(self, session_id, message, context, max_steps,
def __run_actions(self, session_id, msg, context, max_steps, verbose,
user_message):
if max_steps <= 0:
raise WitError('max iterations reached')
rst = self.converse(session_id, message, context)
rst = self.converse(session_id, msg, context, verbose)
if 'type' not in rst:
raise WitError('couldn\'t find type in Wit response')
if rst['type'] == 'stop':
Expand Down Expand Up @@ -116,14 +119,14 @@ def __run_actions(self, session_id, message, context, max_steps,
else:
raise WitError('unknown type: ' + rst['type'])
return self.__run_actions(session_id, None, context, max_steps - 1,
user_message)
verbose, user_message)

def run_actions(self, session_id, message, context=None,
max_steps=DEFAULT_MAX_STEPS):
def run_actions(self, session_id, msg, context=None,
max_steps=DEFAULT_MAX_STEPS, verbose=None):
if context is None:
context = {}
return self.__run_actions(session_id, message, context, max_steps,
message)
return self.__run_actions(session_id, msg, context, max_steps, verbose,
msg)

def interactive(self, context=None, max_steps=DEFAULT_MAX_STEPS):
"""Runs interactive command line chat between user and bot. Runs
Expand Down

0 comments on commit 68ad3af

Please sign in to comment.