Git Product home page Git Product logo

pywit's Introduction

pywit

pywit is the Python SDK for Wit.ai.

Install

Using pip:

pip install wit

From source:

git clone https://github.com/wit-ai/pywit
pip install .

Usage

See the examples folder for examples.

API

Versioning

The default API version is 20160516. You can target a specific version by setting the env variable WIT_API_VERSION.

Overview

pywit provides a Wit class with the following methods:

  • message - the Wit message API
  • speech - the Wit speech API
  • interactive - starts an interactive conversation with your bot

Wit class

The Wit constructor takes the following parameters:

  • access_token - the access token of your Wit instance

A minimal example looks like this:

from wit import Wit

client = Wit(access_token)
client.message('set an alarm tomorrow at 7am')

.message()

The Wit message API.

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:

resp = client.message('what is the weather in London?')
print('Yay, got Wit.ai response: ' + str(resp))

.speech()

The Wit speech API.

Takes the following parameters:

  • audio_file - a file handler opened in binary mode
  • verbose - (optional) if set, calls the API with verbose=true
  • headers - (optional) the dict of headers (e.g. "Content-Type")

Example:

resp = None
with open('test.wav', 'rb') as f:
  resp = client.speech(f, None, {'Content-Type': 'audio/wav'})
print('Yay, got Wit.ai response: ' + str(resp))

.interactive()

Starts an interactive conversation with your bot.

Example:

client.interactive()

See the docs for more information.

Logging

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.

pywit's People

Contributors

andreimarcu avatar blandinw avatar danqing avatar davidawad avatar erlichmen avatar garethpaul avatar jhoelzl avatar louisnow avatar madspindel avatar martinraison avatar oliviervaussy avatar oniken avatar patapizza avatar raviteja-ms avatar tvivoli avatar vikc07 avatar willywongi avatar wwj718 avatar xsschauhan avatar zachorr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.