Sunday, December 6, 2015

How to embed a Hutoma AI into your website

AIs can be pretty useful when placed inside a webpage. An AI can explain your product to your customers and be your brand ambassador; an AI can act as first customer support or entertain your visitors. In this short tutorial, we will create a simple webpage that will let you text with your AI.

The complete source file can be found here. Before you run it, make sure you replace the ai_ID with your neural network ID you got during the creation process. To get the actual code, view the page source using your browser.  

The code behind the page is pretty simple, but in case your are curios the main bits are:

Step 1: Add a link to our hutoma.js file in your page
Open your webpage and add a link to our hutoma.js file. The JS file just simplify a little the syntax needed to interface with our infrastructure.

<script src=""></script>

Step 2: Crate an AI
After you linked the huroma.js file you can initiate a connection to your AI. 

var ai = new AI({ai_ID: 'YOUR AI ID',user_ID: '1'});

Step 3: Talk to your AI
To talk to your AI, you can call the talk command as follow. The call, invokes the chat session API and pop up a message with the answer
      input: <YOUR QUESTION GOES HERE>},
      function(data) {
           The response from the AI will be in data.output. 
           Here we just pop up a message

Here's the complete webpage to talk to your deep learning AI:

<!doctype html>
    <title>Hutoma Chat Example</title>
<script src=""></script>
<script src=""></script>

    var ai = new AI({
        user_ID: '1'


        var q = $("#yousay").val();
          input: q
        function(data) {

  <h1>Talk to a Hutoma AI</h1>
    <form id="talk" class="boxedin" onsubmit="return false;">
      <b>You say:</b> <input id="yousay" name="input" size="90" />
      <input id="talkbutton" type="button" value="talk"/>
    <p id="response"></p>