pywit
is the Python SDK for Wit.ai.
Using pip
:
pip install wit
From source:
git clone https://github.com/wit-ai/pywit
pip install .
See the examples
folder for examples.
The default API version is 20200513
.
You can target a specific version by setting the env variable WIT_API_VERSION
.
pywit
provides a Wit class with the following methods:
message
- the Wit message APIspeech
- the Wit speech APIinteractive
- starts an interactive conversation with your botThe Wit constructor takes the following parameters:
access_token
- the access token of your Wit instanceA minimal example looks like this:
from wit import Wit
client = Wit(access_token)
client.message('set an alarm tomorrow at 7am')
The Wit message API.
Takes the following parameters:
msg
- the text you want Wit.ai to extract the information fromExample:
resp = client.message('what is the weather in London?')
print('Yay, got Wit.ai response: ' + str(resp))
The Wit speech API.
Takes the following parameters:
audio_file
- a file handler opened in binary modeheaders
- (optional) the dict of headers (e.g. "Content-Type")Example:
resp = None
with open('test.wav', 'rb') as f:
resp = client.speech(f, {'Content-Type': 'audio/wav'})
print('Yay, got Wit.ai response: ' + str(resp))
Starts an interactive conversation with your bot.
Example:
client.interactive()
See the docs for more information.
Default logging is to STDOUT
with INFO
level.
You can set your logging level as follows:
from wit import Wit
import logging
client = Wit(token)
client.logger.setLevel(logging.WARNING)
You can also specify a custom logger object in the Wit constructor:
from wit import Wit
client = Wit(access_token=access_token, logger=custom_logger)
See the logging module and logging.config docs for more information.
The license for pywit can be found in LICENSE file in the root directory of this source tree.
Our terms of use can be found at https://opensource.facebook.com/legal/terms.
Our privacy policy can be found at https://opensource.facebook.com/legal/privacy.