Skip to content

Giska/tutorials

Repository files navigation

Tutorial

Here is a quick tutorial to get familiar with craft ai.

The material for this tutorial is a web application that will browse reddit topics and match the titles to the names of state capitals from all over the world. When there is a match, the application will connect to the OpenWeatherMap API, retrieve the current weather for the corresponding capital and display it on a map.

Getting ready

Requirements

  • A modern browser such as Chrome 45, Firefox 39 or Safari 9,
  • A GitHub account.

Forking the GitHub repository

First, you will need to fork the GitHub repository of the craft ai tutorials, so that you can manipulate the behaviors and actions.

To do so, go to github.com/craft-ai/Tutorials, log in with your GitHub account and click on the Fork button, in the top right corner of the page.

User configuration

The following information will be required to run the web application:

  • your GitHub username (more precisely, the owner of your fork of the Tutorials project),
  • the name of your fork,
  • the branch of your fork you want to use.

App configuration

You will also need to have an Application ID and an Application secret for your modified version of the tutorials. Those are generated by craft ai:

  • go to the craft ai editor,
  • log in with your GitHub account - you'll need to have a beta access for this step to work,
  • click on the add projects button and check the box on the right of the project corresponding to your fork of the Tutorials project (something along the lines of <github_username>/Tutorials),
  • click on the "Add 1 project" button at the bottom of the list. The project will be added to your workspace and you can select it to start editing it,
  • in the project explorer that appears on the left of the page, click on the cog button on the right of the project name.

You will end up on the settings page which will display the Application ID and the Application secret needed to run the tutorials.

Running

First launch

Open your browser and go to www.craft.ai/tutorials and click the Run button. You will be prompted to fill in a form with the data from the previous steps.

Once submitted, the data will appear in the URL like this:

http://www.craft.ai/tutorials
  ?owner=<github_username>
  &project=Tutorials
  &branch=<github_project_branch>
  &appid=<craft_ai_app_id>
  &appsecret=<craft_ai_app_secret>

This way you can save the url and when hitting the "Run" button from there, the form will be completed with your data and all you will need to do is hit "Submit".

Playing around

You can play around with the app and see what happens. The controls are the following:

  • Run will start an instance and display the posts retrieved from reddit in the web page;
  • Stop will stop the currently running instance and prevent retrieving and displaying any more content;
  • Next will explicitly retrieve more results from reddit;
  • Clean will remove the content from the web page.

Under the hood

Here's how the application works:

  1. A craft ai agent that we will call the reddit manager retrieves the front page of a given subreddit via the GetFrontPage action;
  2. If the reddit API returns results, the reddit manager will
  • display a summary of the topics returned as thumbnails in the web page,
  • and send the results to the city manager agent using craft ai messaging system;
  1. The city manager agent will then
  • compare the results' titles with a list of capitals (GetCapitals action),
  • and for each capital matched
    • display the thumbnail in a dedicated column (DisplayCityThumbnail action),
    • and retrieve the weather and display it on a map (DisplayCityWeather action);
  1. When all of the results have been run through, the city manager agent will notify the reddit manager agent;
  2. The reddit manager agent will send a request for other topics in the subreddit, and the scenario plays again, until no more topics are found.

Next step

Stay tuned for incoming tutorials. Next time we'll teach you how to make your own behavior trees!

Releases

No releases published

Packages

No packages published