Introduction to API.AI

Jayven N
Chatbots Life
Published in
7 min readFeb 4, 2017

--

Make robots give a shit again

“A robot is as good as its creator” — Jayven Jobs

One Line

Getting started with API.AI without getting bored to death.

Background

Two weeks ago, I signed up to talk to smart robots.

I went up to them and they gave no shit.

So I went on journey and looked for ways to make robots respond. Perhaps a getting started video would help? Can’t find a single good one. How about a simple article? Nope.

Nothing showed how to use this immensely powerful tool. It’s like having a light saber and not knowing how to light it up. Luckily, I found Yoda. He showed me the way of life.

Purpose

Introduce API.AI.

By the end of this article, you will have yourself an AI. Hopefully you will understand how to create your own AI for whatever purpose since the fundamentals are all you need.

What a time to create AI.

-Drake

Getting Ready

Here is the link for API.AI. Sign up/sign in as you like.

Once you are in the console then you are probably wondering “where am I.” That was me. Think of this as your headquarter. A place where you store your robot(s) and its intelligence.

Have a look around at your headquarter just to see where things are located.

Here are three useful terms to know before going further:

Agent — Your robot’s name

Intent — Your robot’s capabilities

Entity — Your robot’s inventory

Getting started

Naming The Robot

Let’s name the robot “Bob.” Start by clicking the down arrow beneath the API.AI logo.

Done correctly and you should see this dropdown:

Then click on “Create new agent.” Type in Bob for agent’s name and press save. You’ve just named your robot.

Top left console should now look like this:

If it does then Bob is official.

Capabilities

Bob looks he wants to be an athlete. Let’s give it a capability called “exercise.”

Press “Intents.” Press “Create Intents.”

At the very top, there is a text field for intent name. Type “do.exercise” and press save. Now Bob kind of has the capability to do exercise. This is because although he knows exercise, he doesn’t know what exercises exist. This is where we transition to entities and throw in some exercises to this Bob’s inventory.

Inventory

Now we need to show Bob some exercises. To do that, we are going to press on the “Entities” tab on the left. Then press “Create Entity.”

Now inside our inventory, creating a new entity is like creating a new category for our robot. We use it to keep organize of all the items that we place inside of our inventory box. Like how Apple Store has different sections for different products. It’ll be a mess if we just pile everything together.

Let’s continue by giving our category a name. Type “exercises” for the entity name.

Next, we are going to talk about entry. An entry is an item we put inside of our defined category. Now that we have our category we can put items inside.

We can think about it like this. We have a big box (entities) that stores everything. Inside the big box, we have smaller boxes. Now inside the smaller box, we store our items.

Referring to entry is something that we are going do later on. It allows us to be very intuitive. In real life, we can refer to one thing with many different names. Therefore, same goes for entry.

Now it’s time for use to add our items. Start by clicking on “+ Add a row”. Type sit up. Press enter.

After that, you see a placeholder that say enter synonym. Let’s go ahead and press on that and enter “crunches.” This way Bob understands that we are referring to the same exercise whether it be sit up or crunches.

Let’s give Bob two more exercise entries. Push ups and pull ups sounds like a great addition. We have covered arms, chest, and back. We will skip legs for now. If you can’t go to sleep without working out your legs then go ahead and add it into your inventory.

Your console should now look something like this:

Robot Comprehension

Now is the time for Bob to understand us. Understand that we want him to exercise. I would like you to put yourself in the shoes of a personal trainer for this section.

Imagine this:

We are now going to show Bob how we would command an action on exercise. To do that, just think about how you would speak normally to your client as a personal trainer. Then type it into the “Add user expression” box and press enter. Type out all the commands that you would give to your client to perform the exercises.

Should look something like this:

If you notice, some words are highlighted. This is simple because Bob recognizes push up, pull up, and sit up from our inventory which is super cool. But you are probably wondering how come not all of the exercises are highlighted? Well that’s just about how smart Bob is at recognizing exercises at the moment. We can give him a hand by highlighting the entry we want to be recognized like the unhighlighted sit ups.

A list should drop down. Then press “@exercises:exercises”.

Now the word highlighted and Bob understand “sit ups.” Do the same thing for the other ones.

You may have noticed that Bob automatically understand things such as number, geography, and email from the drop down list. Well that’s because Bob is born as a robot. It’s robot’s common sense nowadays.

Robot Talk

To teach our robot how to talk, scroll down to the response section. This is where we show Bob how he to respond to exercise commands.

You can put this:

$exercises indicates the input exercise value.

Demo

Alright, demo time. It’s time to test out Bob.

Make sure you have pressed on the save before moving on.

Now go to the right column. This is where we test out Bob. Press the microphone icon and tell Bob to perform an exercise with your voice. You can also type it out but that’s boring. So try speaking to Bob first. It’s more exciting.

If Bob understands you, then you should see something like this:

It’s also worth mentioning that you don’t need to teach your robot everything. Check this out. I can say this and Bob still understands me based on previous knowledge:

Basically the more inputs your robot knows about, the more it can understand on its own.

Now maximize your volume and press PLAY. Just listen to all the shit that the robot gives. Is that satisfying or what?

Seriously though, this has been really exciting and congratulation for making it this far. We’ve just created a robot using API.AI that can understand and talk back to us.

Last Remarks

I hope you have enjoyed and learned something valuable from this article. If you have then let me know by hitting that ❤ button. Also, share this article so that your circle can make some knowledge gains too!

You can follow me on Medium for fresh articles. Here is my LinkedIn for connection.

Lastly if you have any comment, question, or recommendation, feel free to post them in the comment section below!

Feel free to check out my recommended articles:

API.AI in Swift 3

Master Functions in Swift 3

--

--