npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wit-api

v1.0.1

Published

Implementation of wit api, provides methods to easily manage your wit app

Downloads

13

Readme

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 = require('./src/Wit')

async function run () {
  try {
    // Instantiation
    const wit = new Wit('<YOUR-SERVER-ACCESS-TOKEN>')
    // Syncronize with remote
    await wit.sync()
  } catch (e) {
    console.error(e)
  }
}

run()

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

async function run () {
  try {
    const wit = new Wit('<YOUR-SERVER-ACCESS-TOKEN>')
    await wit.sync()
    // Adding a new entity
    await wit.entities.add('cloth')
    // 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 (!wit.entities.size) {
      await wit.entities.add('size')
    }

    // Update an entity
    await wit.entities.cloth.update({ doc: 'An item from the store', lookups: ['keywords'] })

    // We can also manipulate the entities values and expression through the `.update` function
    // Also additional options are present, like metadata
    await wit.entities.size.update({
      doc: 'Size',
      lookups: ['free-text', 'keywords'],
      values: [
        {value: 'extra small', expressions: ['36'], metadata: 'XS'},
        {value: 'small', expressions: ['37', '38'], metadata: 'S'},
        {value: 'medium', expressions: ['39', '40'], metadata: 'M'},
        {value: 'large', expressions: ['41', '42'], metadata: 'L'},
        {value: 'extra large', expressions: ['43', '44'], metadata: 'XL'}
      ]
    })

    // Deleting an entity
    await wit.entities.cloth.destroy()
  } catch (e) {
    console.error(e)
  }
}

run()

Training

// This goes insde an `async function`
await wit.services.sample.train([
  {
    text: 'I would like to have a jean please.',
    entities: [
      {
        entity: 'intent',
        value: 'order'
      },
      {
        entity: 'product',
        value 'pant',
        start: '22',
        end: '26'
      }
    ]
  }
])
// wit.service.sample.train can take multiples training sample

// You can reverse a training by using .forget
await wit.services.sample.forget([
  {text: 'I would like to have a jean please.'}
])

Guessing (text & speech)

This is actually where we use the api for understanding

// this goes inside an `async function`

// Text:
const guess = await wit.services.guess.message('I want to try a coton black shirt, preferably size 43')
console.log(guess)
/* 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 wit.services.guess.speech('path/to/an/audio/file.wav')

Both .message and .speech can take additional options, in like the following

const options = {n: 5}
await wit.services.guess.message(text, options)

More about these options at https://wit.ai/docs/http/20170307#get__message_link

with love from Hexastack