Build a Chatbot w/ an API

directions to the nearest water source watched your geology

he knows the way

hello world welcome to sur geology in today’s episode we’re going to build a chat bot with an API in a previous episode we talked about how to build a generative model chatbot by training it on your own data set with no hard coded responses whatsoever this time we’re going to go the API route because let’s face it is the year

of the chat box in the past few months

cowlitz companies have released chap . AP is so that you can integrate it with their service chat bots are like the new apps if you think of a startup idea there’s probably an app for it but no chat box we’re going to build a flower delivery chatbot so I did a little API shopping and therefore services that really stood out to me with nuance sirikit an API

today I let’s talk about the pros and cons of each of them it is a checkup API

that was acquired by Facebook’s they’ve got the benefit of the facebook marketing machine behind that it’s free so you can spend your money on things that matter speech recognition is included the thing I really like about this service was the use of open instances if someone else designs about you can just fork it and

use that fork as your new chat back in but the problem is when I attempted to

build a bot with this it was super annoying and bugging the documentation isn’t dense enough so there’s a lot of ambiguity I got frustrated because there was no option to create synonyms for entities and i also just didn’t have time to learn how the story model work more time

for Minecraft another service i looked at was nuanced mix you guys remember

dragon naturally speaking from back in the day yeah these guys made that so they definitely have speech recognition as a capability right out of the box and it seems like they really pay attention to that feature because they have a bunch of spec papers on their site detailing their speech recognition technology 40 different languages are supported in

eight different text-to-speech voices are available during their docs they use

terms like literals and concepts that had another layer of abstraction or doesn’t seem necessary I tried to sign up and they said they’d get back to me into business days ain’t nobody got time for that nuance has been known to stick to big enterprise deals if you’re an independent dad probably not the best fit then this serie kit

apple announced the WGC this year that they open up Siri to third-party

developers the extensions finally it’s got great documentation but that’s really the only pro I found by the way wdc this year Apple what syriac it is limited to just six different app type so you can’t tell her to make you spoil and just yet

and those limitations are already baked into the API with functions like in book

restaurant intent and only works with Apple devices so yeah the garden is quite wall finally there’s a peon at AII this was the easiest service for me to use I built a pretty useful chat with this in just two hours the documentation and interface or just way easier to understand than any other service I

found it’s got this integration feature where you literally just flip a switch

and it will integrate with your service provider of choice be that slack or twilio you just build your bot once and then deployed to whichever platform you want also they have the most client libraries and SDKs I found for chapel API that makes me a very happy day speech recognition functionality is built into

the SDKs the only con is that while it is free as you scale their pricing tiers

but hey if I were going to build a production great service quality is a number one metric I be optimizing for and it seems ap on AI is leading the charge so let’s build this baby we’re going to build a flower delivery chatbot using api’s console in a Python client will start by writing up an ideal conversation with our box the user lets the bach know

they’re interested in buying flowers then specify the type of flowers

followed by the color and then the address it like it to be delivered to they can exit the conversation or ask for more flowers in the process loops we need to codify this conversation and the API console makes it relatively simple to do this will create a new agent click on domain and turn on small talk now arbok is already capable of very basic conversation then we’ll see the intense

and entities tab an entity is a model object that you refer to in your

conversation at some point so we want three entities flower color and address will create the flower entity will define three synonyms these will be the types of flowers we want will do the same for color then for a dress cool now that we have our energies let’s build our intense an intent is an

abstraction of a specific request a user makes which then naps it to an action

and a speech response will create our first intent and call it proposal we want to think of a couple of possible statements a user can say the system will be able to recognize not just these hand-coded possible statements but statements that are worded differently and have the same meaning once the system has recognized what the user has said it can perform an action an action

is an event that fires once an intent has been recognized well then type out

our speech response and this will fire when it recognizes the intent of the user statements finally we’ll add an output context context or how the system keeps track of what is being said it’s what makes the bot conversational we know that after this proposal intense we want to chat bot – then ask what type of flower so we’ll set the output context to our next intent called type

specification for type specifications are out of context is color

specification we are looking for a one word answer from the user that specifies type our system will detect the word if it’s of type flower and performing yet undefined action will call save flower type will add in our speech response asking for the color and do the same for color specification the output context is address specification the user will save a one word answer which will

determine to be an entity of type color will perform the same color action and

ask for the address lastly in a dress specification write out an example address and I’ll recognize it of type address by using the address system and it will perform the create order action and we use the address variable name to repeat the address back to the user we can set the output contacts back to the proposal in

case the user wants to continue buying flowers

now that we have our back-end set up let’s write our client in Python will import our dependencies a json parser in the API on a ipython rapper then initialize raj then create functions for each of our actions leave these blank but you can add any kind of functionality you’d like then in our main method will create a while loop and retrieve the user input

from the command line then post it to the agent and retrieve the JSON response

to parse the JSON to display the Box reply if we detect an action will fire one of our action helper methods hey what’s up I want flowers to of the color blue one infinite loop order created I totally get why everybody is raving about this service on hacker news check

out the links down below and subscribe for more ml videos I’ve got to go fix a

race condition so thanks for watching