wit-api
wit-api is a node package that allows you to easily configure, train and consume your NLP through Wit.ai HTTP API.
Note: This is the version 1.x.y, it has no dependency, and it uses async
/await
, if you prefer using promises
please refer to the the 0.0.6 version (npm i wit-api @0.0.6
), that version's branch will recieve only hotfixes and won't support additional features.
Note: Version 1.0.0 is stable, and will recieve only additional utils methods
Installation
npm i wit-api --save
Initialization
const Wit = { try // Instantiation const wit = '<YOUR-SERVER-ACCESS-TOKEN>' // Syncronize with remote await wit catch e console }
Additionally, you can pass options to the instantiation, like:
new Wit('<YOUR-SERVER-ACCESS-TOKEN>', { debug: true, timeout: 30000, version: '20170307'})
- debug: will display more insights about the http requests
- timeout: in milliseconds, indicate when the http request times-out
- version: indicate what version of wit.ai to use, this lib ain't work for versions prior to 20170307
Entities, Vlaues & Expressions
{ try const wit = '<YOUR-SERVER-ACCESS-TOKEN>' await wit // Adding a new entity await witentities // The newly added entity is sync-ed in the `wit` object // and can be accessed through `wit.entities.cloth` // For script reusability, it is recomended check the entity existance before adding it if !witentitiessize await witentities // Update an entity await witentitiescloth // We can also manipulate the entities values and expression through the `.update` function // Also additional options are present, like metadata await witentitiessize // Deleting an entity await witentitiescloth catch e console }
Training
// This goes insde an `async function`await witservicessample// wit.service.sample.train can take multiples training sample // You can reverse a training by using .forgetawait witservicessample
Guessing (text & speech)
This is actually where we use the api for understanding
// this goes inside an `async function` // Text:const guess = await witservicesguessconsole/* example of a result:{ _text: 'I want to try a coton black shirt, preferably size 43', entities: { product: [ { confidence: 1, value: 'shirt', type: 'value' } ], shirtTextile: [ { confidence: 1, value: 'coton', type: 'value' } ], color: [ { metadata: '#000000', confidence: 1, value: 'black', type: 'value' } ], size: [ { confidence: 1, value: 'XL', type: 'value' } ], intent: [ { confidence: 0.72456770482335, value: 'try' } ] }, msg_id: '1AY90y2ewdQhotazg'}*/ // Audio:await witservicesguess
Both .message
and .speech
can take additional options, in like the following
const options = n: 5await witservicesguess
More about these options at https://wit.ai/docs/http/20170307#get__message_link