Skip to content

Instantly share code, notes, and snippets.

@janteuni
Last active July 14, 2017 09:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janteuni/501c8b9fff64be78e85547d45a5b3e2c to your computer and use it in GitHub Desktop.
Save janteuni/501c8b9fff64be78e85547d45a5b3e2c to your computer and use it in GitHub Desktop.
Recast.AI - starter

Configuring Recast.AI with Recime

Recast.AI is a collaborative bot platform for developers that makes it easy to use natural language understanding in conversational bots.

Create a bot in Recast.AI

To create a new bot, login on Recast.AI and click on the link + NEW BOT in the header section.

  • Choose a name and a description
  • Set the default language, you will be able to add more languages later ;)
  • Choose a template to start easily, the Meeting Bot is a complete bot example!

Recast.AI create bot

You bot intents

An intent is a box of expressions that mean the same thing but are constructed in different ways. Intents are the heart of your bot's understanding. Each one of your intents represents an idea your bot is able to understand. For example, an intent greetings makes your bot understand when a user says `Hello`. In the meeting bot you will find all intents you need to create a bot that can book you a meeting room. Explore each intent a little bit by clicking on the name and you will see expressions inside that train your bot to understand the user intent ;)

Add expressions

The optimal setting for a great intent is to contain around twenty different expressions. Add some expressions your users will say by typing the sentence in the field Add an expression.

Recast.AI expressions

Use entities

If you click on one of the expressions you will see highlighted words, with tags. These are entities. They’re keywords detected in expressions that are important to you in order to automate a task.

Recast.AI intents

We automatically detect 31 different entities like: Location, Datetime, Colors, Emojis, Number… We call them gold entities. If you need another entity, a custom one like a meal for a cooking bot, just select what you want to tag as your new entity and type a name. The more examples you provide, the better the detection will be ;)

Recast.AI tag entities

Use the console

Once you’ve set up your bot, you can test it with the console. Click on the TEST bubble icon on the top right to make it appear. Select the tab Analyse, and type a sentence to test if your bot is well trained: `I want meeting room 2 for tomorrow`

Recast.AI NLP analyse

You will see which intent is detected and which entities are extracted. Click on the Smart view toggle to switch the view to the JSON mode. The JSON contains a lot of useful information about the message you’ve sent, like all the enrichments we can provide for the gold entities.

Recast.AI NLP JSON

Make a first API request

This JSON returned in the console is what you receive when you've sent a text (like a user input) and want to analyze it. To get that response, you need to make a request: How? First, get your Request access token: click on the little gear icon to go to the settings of your bot.

Recast.AI bot settings

Go to your bot code folder and install the Recast.AI module:

npm install --save recastai

Set the Request access token (copied earlier) as a config var:

recime-cli config set RECASTAI_KEY=PASTE_YOUR_TOKEN_HERE

Once everything is set, you can analyse user input, get intents and entities from it, in the following way:

/*jshint esversion: 6 */

import recastai from 'recastai'

export default class Bot {

  constructor(args) {
    this.args = args
    this.recastai = new recastai.request(process.env.RECASTAI_KEY)
  }

  execute() {
    const text = this.args.text

    return new Promise((resolve, reject) => {
            
      this.recastai.analyseText(text)
        .then(res => {
          // get the intent detected
          const intent = res.intent()

          // get all the location entities extracted from your text
          const locations = res.all('location')

          // Do your code
          resolve({
            'text': `Intent is ${intent.slug}.`
          })
        }).catch(err => {
          reject(err)
      })  
           
    })
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment