# Get Started

aito.ai brings AI capabalities to no-coders working on any data or any workflow.

## Try in three minutes

Getting started with aito.ai is absolutely easiest with Airtable, and using our Instant Predictions extension. The extension is available for free from the [Airtable Marketplace](https://airtable.com/marketplace/blkHZZ8NLJ27bL5oy/aito-instant-predictions), and it automates all the steps of creating datasets and making predictions. You'll get results without a single line of code.

## Different ways to use aito.ai

aito.ai machine learning can be used in various ways, depending on your needs and the level of coding experience. These are the most common ways:

* [Airtable extension](https://airtable.com/marketplace/blkHZZ8NLJ27bL5oy/aito-instant-predictions) - our Airtable extension is truly no-code. The best starting point for most.
* [aito.ai Console](https://console.aito.ai) - Our web console is needed in all cases to maintain your aito.ai cloud instance, teams and payment methods. But it also supports uploading datasets, testing predictions and making evaluations.
* [Python SDK](https://aito-python-sdk.readthedocs.io/en/stable/) - Our Python SDK is an easy to use wrapper for the full aito.ai API, and simplifies many steps in the process. This is the preferred way for example when using Python-native Automation platforms such as Robocorp.
* [aito.ai API](https://aito.ai/docs/api/) - Sometimes the easiest way is just to make HTTP calls straight to aito.ai's API. This is most commonly used from various workflow automation tools, such as Integromat/Make, Zapier, UiPath, Parabola, MS Power Automate and many more.
* [Command Line Interface](https://aito-python-sdk.readthedocs.io/en/stable/cli.html) - well yeah. You can do that too.


# What is aito.ai?

So what exactly is this thing we are talking about here?

## In one sentence

aito.ai is a machine learning service in the cloud that lets you predict almost anything without learning data science.

## In two paragraphs

aito.ai helps no-coders and automation developers to cover larger parts of the workflows with bots. Often the bot stops when a human decision is needed, and this is exactly where aito.ai steps in. Using historic data that your process has handled over time, it is able to make predictions and decisions that help the bot run autonomously, or the human to make the right call quicker. When we talk about the decisions, we think of things like "*which team should solve this customer ticket"*, or "*should we use an automation to reply to this tweet*".

aito.ai machine learning cloud solution can be used from a range of no-code and automation tools such as Airtable, Integromat/Make, Zapier, Robocorp, UiPath, Automation Anywhere, Blue Prism. aito.ai can work without a single line of code, but the software developers can harness the full powers through API and Python SDK.

## As described by our lead scientist Christoffer

\[He has been so busy with building the platform that this text is still missing. Sorry!]

## The difference

aito.ai covers the entire machine learning workflow in one cloud-hosted solution, aimed for no and low coders.

| Workflow step                | Traditional ML approach                                                                                                                                                                                                         | aito.ai approach                                                                                                                                                                 |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Feature engineering**      | User is expected to perform several steps of feature engineering (imputation, feature scaling, one-hot encoding, grouping, standardization, ...) to produce training data suitable for most machine learning algorithms.        | Upload data from an existing data source such as Airtable or CSV file. No other steps needed.                                                                                    |
| **Model construction**       | User needs to choose a fixed prediction target, and then the most suitable algorithm and it's parameters, typically requiring data science knowledge to get right.                                                              | aito.ai works fundamentally differently: based on queries that generate predictions in real time. Users do not need to know the details of the science behind.                   |
| **Deployment and hosting**   | After the model is trained, the user wraps it in an API for production use, and deploys it on a server, needing to take care of the scalability and performance as well as maintenance tasks.                                   | There are no "models" in aito.ai, so this step is made completely irrelevant. When you have data in, you already have API for querying predictions. We take care of the scaling. |
| **Retraining with new data** | Every new datapoint means that the model needs to be retrained, and deployed again to production. This pipeline needs to be maintained, managed and monitored in order to keep the accuracy high, and all things running fresh. | With aito.ai, every new datapoint automatically contributes to next prediction. This happens without any user action.                                                            |


# Instances

Every user needs at least one aito.ai instance. That's your own dedicated aito.ai in the cloud that hosts the training data as well as the necessary services to run the predictions. Putting your data and the aito.ai engine in the same space makes things secure - your data is never shared with anybody else in any way.

The instances, teams and payment methods are managed in the [Console](https://console.aito.ai). One owner can have multiple instances of different types (however only one free Sandbox per user), and owners can invite team members to paid instances.

Get going by hitting "Create new instance" button in the right corner!

![](/files/rD4VGRgDEN4YtJP3Ics5)

## Instance Overview

Instance overview page contains the most important details for using the instance.

![](/files/6pNTj66dQnsG3I1cV50e)

API URL and API keys are needed to connect aito.ai with other services and access your predictions. Note that both read-only and read and write keys are available. Use them wisely, please.

You can add new data by dropping a CSV file in the upload section.

Metrics display your progress towards the instance limits. Each instance tier has it's own limits, check the latest tiers from our [website](https://aito.ai/pricing/).


# Datasets

They are called "Tables" in Aito.

## The basics

Your data is hosted in "tables" in Aito. The naming is due to a fact that Aito's way of dealing with your data resembles a database rather than a "flat sheet". What it means in practice is that the datasets can consist of single table data, or even multiple tables linked together.

Each table has a **schema** that describes its structure: columns and datatypes. You can create these schemas and upload tables from [Aito Console](https://console.aito.ai), through [API](https://aito.ai/docs/api/) all by yourself or use integration like [Airtable extension](/integrations/airtable) that hides all the complexity from you.

Regardless of where and how you created the tables, they are all visible in the Tables tab on the console.

![](/files/sZTvrUMQtesmzmqv1QbK)

This view allows you to **create empty tables**, **upload CSV file** to create a table as well as **view details** of, **clear data** and **delete existing tables**.

## Details of a table

For each table, you can view the amount of **rows** and **columns,** the schema and a few rows of sample data.

![](/files/HJkamIVc7qhgXOhCP6mI)

When using Airtable extension, it automatically manages your tables, schemas and data. Essentially, you don't even need to know about them. However, having access to table structure and names is handy in the cases when you extend functionality to for example automation platforms and scripts.

{% hint style="info" %}
**Good to know!** Manipulating table data or schema is not supported in the Aito Console. This is on the roadmap, but not yet scheduled for the immediate next releases.
{% endhint %}

## Uploading a dataset on Console

Aito's dataset uploader is actually quite cool! We made a quick video on how it works. Check it out!

{% embed url="<https://youtu.be/BkODAIIcljo>" %}


# Predictions

Predictions are what generate the value. The fun part!

## Different ways of predicting with Aito

You can use Aito to predict "things" via different means, which follow the same paths as the data uploads.

* Use [Aito HTTP API](https://aito.ai/docs/api/) to make requests to query endpoints, and read predictions from responses (JSON). Note that this is the most common option when using Aito with most of the automation platforms, such as Zapier, Integromat/Make and UiPath.
* Use [Aito Python SDK](https://aito-python-sdk.readthedocs.io/en/latest/quickstart.html#sdkquickstartsendquery)'s predict functions to send queries to Aito, and read the results from the response JSON. This would be the recommended method when working with a Python native platform, such as Robocorp.
* Use the [Airtable Extension](/integrations/airtable/predictions) to make get predictions automatically without code, based on your interactions with the Airtable base. **This is the recommended method for users not having a software development background.**

Regardless of the chosen method, the big picture is simple. Once you have a dataset in Aito, you can choose any of the available predictive functions and give needed inputs, and read the results from Aito's response. As a usage paradigm, this is closer to interacting with a database than a machine learning model.

An example of an Aito `_predict` query (request) would be for example:

```
{
  "from": "Titanic",
  "where": {
    "Pclass": 3,
    "Sex": "male"
  },
  "predict": "Survived"
}
```

The response to the said query would be as below, indicating only \~11% survival prediction for Titanic's male passengers with a third-class ticket. 😥

```
{
  "offset": 0,
  "total": 2,
  "hits": [
    {
      "$p": 0.8927479295163457,
      "field": "Survived",
      "feature": 0
    },
    {
      "$p": 0.1072520704836543,
      "field": "Survived",
      "feature": 1
    }
  ]
}
```

## What can you predict?

**First of all, at this point, only categorical predictions are supported.** We are planning to add support for other types of predictions (such as forecasting) later on.

The main types of predictions/queries are reflected in the Aito API as endpoints:

| Prediction type                                                     | Description                                                                                                                                                                                            |
| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [**Search**](https://aito.ai/docs/api/#post-api-v1-search)          | Allows you to search, filter, and order rows. You can also select only specific columns. Similar to *SELECT* in SQL. (You could argue this is not really "predict", but it's handy so we included it). |
| [**Predict**](https://aito.ai/docs/api/#post-api-v1-predict)        | Predict the likelihood of a feature ("your target") given some known inputs. For example, predict a category of expense claim row based on its place of purchase and description.                      |
| [**Recommend**](https://aito.ai/docs/api/#post-api-v1-recommend)    | Recommend a row from your dataset which optimizes a given goal. For example, you could ask Aito to choose a product, which maximizes the click likelihood, when user\_id equals 4543.                  |
| [**Similiarity**](https://aito.ai/docs/api/#post-api-v1-similarity) | Similarity returns entries from your dataset that are similar to the given sample object. The sample object can be either a complete or a partial row.                                                 |
| [**Match**](https://aito.ai/docs/api/#post-api-v1-match)            | Match gets you the most likely value/feature of a column or any column of a *linked table* to given known details or inputs.                                                                           |
| [**Relate**](https://aito.ai/docs/api/#post-api-v1-relate)          | Relate provides statistical information on data relationships. It calculates correlations between a pair of features, which can be used to for example find causation and correlation.                 |

## Testing predictions in Aito Console

An easy way to check that all things are working great is to test the predictions in Aito Console first. Once the data is uploaded, navigate to the Predictions tab. Check out this quick video, or ream more below.

{% embed url="<https://youtu.be/VazRGgle40Q>" %}

There you can choose any table and prediction target column from the dropdown. Aito then populates the request with one sample row from the data to give you a quick starting point. You may edit the input data, and remove unnecessary inputs. The right side shows your JSON request body in real-time.

![](/files/ElhtzEWB6hkF4cXBCtRD)

Once the query is good, hit Predict and Aito returns the results.

The resulting view has both a visual representation of the probabilities, as well as the raw output that came with Aito's response.

![](/files/OCBPRnlBUEG4MNvs25Vn)

{% hint style="info" %}
**Note!** Predictions view on Console only supports Aito's Predict endpoint for now. You can not test other types, like Recommend, Match and so on yet.
{% endhint %}


# Evaluating accuracy

We have built in no-code way to evaluate if your data is good enough for high quality predictions.

The detailed article is in the works, but please check the quick video we put together on how the Evaluations work!

{% embed url="<https://youtu.be/IqxjjMdgoeM>" %}


# Airtable

aito.ai Instant Predictions extension brings machine learning to every no-coder right inside the Airtable base.

**Instant Predictions extension is available for Airtable through the Marketplace** [**here**](https://airtable.com/marketplace/blkHZZ8NLJ27bL5oy/aito-instant-predictions)**.**

aito.ai Instant Predictions extension has the following features:

* **AI-powered autocomplete** - Speed up manual data entry by getting suggestions for field values or tags based on your own historic data.
* **Intelligent actions** - Automate workflows by predicting things like who should handle a customer service ticket, new lead or approve purchase invoices.
* **Find more things like this** - Uncover hidden links in your data and get suggestions for similar records, whether it's freelancers for a project or customers to target with a campaign.
* **Discover insights** - *coming soon*

In order to provide machine learning predictions, it connects your Airtable data from a selected view to your instance in the cloud. No data transformations or feature engineering is needed, simply hitting the "sync" button.

{% hint style="info" %}
**Work continues!** We are constantly developing the Airtable extension, so please be sure to check back often for new features.
{% endhint %}


# Installing the extension

Setting up aito.ai for Airtable is quick. You'll need an aito.ai account, and then connect it with the Airtable extension.

First, you will need an aito.ai account and cloud instance to use the extension in Airtable. Free sandboxes as well as paid plans are available. Sign up [here](https://aito.ai/sign-up/). Once signed up, create an instance in the Console to start.

After installing the aito.ai extension from the [Airtable marketplace](https://airtable.com/marketplace/blkHZZ8NLJ27bL5oy/aito-instant-predictions) you will see this:

![](/files/FD6KQEDWJjx4kSwL4MBM)

Find the API URL and key in the Console in the Overview page of your instance.\\

![](/files/RPA1rfHE1GUV9mN73lYw)

{% hint style="info" %}
You need to use the read and write API key, as the extension uploads/syncs the training data from your Airtable base to aito.ai cloud instance.
{% endhint %}


# Syncing data

Keeping data up to date between Airtable and aito.ai ensures you always predict from the latest dataset.

The training of aito.ai machine learning can be started with the "Train model" button at the bottom of the extension.

![](/files/rcEbUPqmMczP2lSEyLD7)

The view will guide you through the upload, but the **recommendation is to create a grid view that contains the training data and name it clearly**. In aito.ai extension, you can then choose this view as your training source.

![](/files/uJIbBPdltXQJr4ZISwt7)

A few tips below.

Use view filters to choose the records you want to upload. The general advice is to create a separate view for aito.ai upload purposes, that controls the training data, and contains filters that remove the data that has empty values.

![Screenshot 2021-09-14 at 11.00.16.png](/files/T2UUwrtZvtjjoFGsuJcy)

The extension will automatically create a table name in aito.ai, based on your Airtable table id. This is non-editable at the moment. It looks something like this example: `airtable-tblre7vxZNhkv2kzw`. You can review the table contents and schema through [Console](https://console.aito.ai).

If there is existing dataset in aito.ai with the same tablename, the previous data will be deleted and new data will be uploaded.

{% hint style="info" %}
**A word about data synchronisation**

Training data is not automatically synchronized to your aito.ai instance. If your training data changes and you want your predictions to be informed by the updates then you can re-upload the new training.
{% endhint %}

While most of the Airtable field types are supported by aito.ai, there are some limitations. If you view has columns such as buttons and images, aito.ai will automatically ignore them in the upload. You will see the list of included and excluded fields in the upload view.

![](/files/BJWJXQpwQSxbRVFmmuom)

Linked fields (either externally, or within the table) are automatically added to aito.ai. In this case, multiple tables will also be created in aito.ai, capturing your original data structure. The neat feature here is that then the data behind the links is also used for your predictions.

We recommend you to be careful with any personal information. It is not recommended to include fields that might cause biased predictions. For example, if you are dealing with people, always exclude their demographics such as sex or religion from the training data.

Once you start the upload/sync process, the extension will display the progress (and hopefully not errors :sweat\_smile:) and alert you once the process is complete. Please do not close the tab or browser window while the upload is in progress, as that will terminate the process.

![](/files/xzHigt8SvRyBDRIXkwAo)


# Predictions

aito.ai extension is a great companion when adding and working with data, as it can auto-fill column values based on predictions.

Once the training data has been uploaded, you can immediately start using the predictions through the extension.

Predictions work simply by choosing a cell or cells in your table. The extension will display the top 5 predicted results for this particular cell. aito.ai works best for predicting categories, such as short strings, single and multiselects, collaborators and so forth. We may at a later stage add support for other types of inference, such as regression ("forecast a numeric value").

The elements of the extension's predictions are explained below the screenshot.

![](/files/AN2B2wSVqg3jysc7cOMM)

The switch at the top allows the extension to automatically fill empty cells with the predicted value if the confidence is higher than the set percentage (90% in the picture). The threshold value is editable from the pen icon on the right.

The predicted values are on the left, with the confidence values on the right, with the question mark that will display explanations. Use button allows applying the value to the cell manually. If the selected cell in Airtable is not empty, a confirmation dialogue is shown. For multiple select fields, the Use buttons are replaced with + and - buttons to add and remove values.

You may also choose multiple cells either vertically or horizontally to predict multiple cells at the same time. Maximum of 10 cell values are predicted at once.

### Results explainability

Hovering over the question mark next to confidence opens a tooltip that shows the top contributors for each prediction. This helps you to understand what datapoints aito.ai used to make each prediction.

![](/files/fppLMKWVecU7dZeE3vEr)

In this example, the words **dayton** and **store** in the column `lineText` were the top negative contributors, and having `productCategory` **CLASS-1274** together with words **rent**, **management** ... **real** in `lineText` were the top positive contributors.


# Similiarity

Uncover hidden links in your data and get suggestions for similiar records.

{% hint style="info" %}
This feature is coming soon!
{% endhint %}


# Insights

aito.ai's magic is to uncover statistical links across your entire base. Uncover things like "what is typical for my best paying customers" without writing any code.

{% hint style="info" %}
This feature is coming soon!
{% endhint %}


# Using automation scripts

We are working to make the use of predicted results as easy as possible. There are plenty of tutorials on how to use Aito from different integrations platforms such as [Integromat](/integrations/integromat-make), [Parabola](/integrations/parabola.io), as well as from [Airtable Automation scripts](/solution-examples/airtable-scripts-predict). More is coming soon, so be sure to follow us in [Twitter](https://twitter.com/AitoDotAI) and subscribe to our [Youtube channel](https://www.youtube.com/channel/UCLVFis53pOci-S1YdIKQuOA).


# FAQ

{% hint style="info" %}
**Not finding what you are looking for?**

This FAQ is evolving all the time. If you don't find what you are looking for, ask us in [Slack](https://aito.ai/join-slack).
{% endhint %}

**What can I predict?**

aito.ai works best for predicting categories, such as short strings, single and multiselects, collaborators and so forth. We may at later stage add support for other types of inference, such as regression ("forecast a numeric value").

**How can I delete data from my instance?**

Deletion in easiest done through the Console, where you have access to all the tables in your instance.

![Screenshot 2021-09-14 at 11.12.45.png](/files/5zftY8FzLpqfGwEOp26a)

**Where can I read more about security?**

Check our [general FAQ](https://portal.document360.io/v1/docs/general).

**Can I edit the extension source code?**

aito.ai Instant Predictions extension is open source, find the repository [here](https://github.com/AitoDotAI/aito-instant-predictions-for-airtable).

**How can I contact you?**

The fastest way to reach us is through our [Slack Community](https://aito.ai/join-slack). Find people with (aito.ai) in their names! 🙌


# Integromat / MAKE

Dreaming of adding brains to your [Integromat](https://www.integromat.com) automation workflow? Seek no more, aito.ai is the easy way of embedding some ML top your processes.

Here's an example how things can look for you! This workflow watches for new rows in a Google Sheet, then uses aito.ai to predict the accounting category based on row data, and uses Router to send ones with good predictions to elsewhere than the ones with not confident enough predictions.

![](/files/qBXLyqWePziW34cvNDdU)

#### Creating schema to aito.ai

We recommend [uploading some data first](/the-basics/datasets), as this way you can ensure everything is set up properly to receive your data and make predictions.

#### Making predictions : HTTP/Make a request

The easiest way is to amke HTTP calls to aito.ai API. In Integromat, look for Activity type HTTP, and Action **Make a request**.

![](/files/M991iQdmei7p9sJmwJm7)

Then let's do some config to get the HTTP request set right. Follow these steps, together with below screenshot.

* URL: this is the API endpoint in aito.ai you are calling. In our case we do Predictions. Also note that you should get your own instance url from [aito.ai Console](https://console.aito.ai).
* Request method is most of the time POST. Check the [documentation of each aito.ai's end point](https://aito.ai/docs/api/) to make sure you get this one right.
* Headers need to contain your API key. Name is `x-api-key` and the value you'll find from your [aito.ai Console](https://console.aito.ai) in the instance details. Note that for read only queries you can use Read-Only key, but for writing or altering data you need the separate Read/Write key.
* Body type is Raw, with Content type being JSON.
* Request content is where you put the aito.ai Predictive Query, that essentially defines what is aito.ai predicting. Integromat has a really easy way of adding the content from your previous action to the query. Check the example with green highlighted text. Tip! By adding `"limit": 1` to your query, the usage of results is easier as you only have the top prediction.
* You should check the "Parse response" box, as this will make the next steps much easier!

![](/files/xEDt6UDBVbFPPPsBGT4I)

With that, you are already good to go! However, let's look at a few more things.

#### Use of prediction confidence

Integromat's Routers are a super-easy way of deciding what to do with predicted data, according to the confidence of the prediction. In our example here, we have chosen the condition to be`$p`, which essentially is the confidence of the given prediction. Then we have chosen to send entries with higher than 90% confidence to continue with automated workflow, and all the rest have a different way of processing.

![](/files/gAtKw48voYGrnUoTCgde)

#### Debugging

We love Integromat! Check below how easy it is to debug your workflow! Use the magnifying glass to view the full input and output with aito.ai. For example ,the highlight here contains the first predicted result from aito.ai. `$p` means the probability (confidence), `field` denotes what was the prediction target and `feature` contains the predicted value.

![](/files/8yOHDcVnpNeYOdAqRJxP)

#### Adding data to aito.ai

In order to send new data in to your instance, you would be using the same HTTP Action called Make a request. Instead of using aito.ai's prediction end points, you simply use Data API instead. As Integromat mostly operates on entry by entry basis, the most practical approach is to use [single entry upload](https://aito.ai/docs/api/#post-api-v1-data-table).


# Zapier

Coming soon.


# Parabola.io

aito.ai works great with several workflow automation platforms, including an awesome [Parabola](https://parabola.io). Once you have your aito.ai instance up and running, here's how to get started in no time!

#### Creating schema to aito.ai

We recommend uploading your training data in [aito.ai Console](/the-basics/datasets) or with [Airtable extension](/integrations/airtable/syncing-data) first, as this way you can ensure everything is set up properly to receive your data.

#### Adding data: Send to an API

Adding data to aito.ai happens with "Send to an API" activity.\
What ever the input to that activity will be, is to be sent one by one to API. In this case to aito.ai. Note! If you are working with bigger datasets, you should explore batch transfer options.

Check the below screenshots for guidance on how to set up the connection. Here are the steps.

* Request type is POST.
* API endpoint URL is the one given to you in console, along with `/api/v1/data/[tablename]`where you need to add a name of the table in aito.ai to which you are uploading data.
* Body needs to be constructed to have a JSON element that contains the data that you are uploading. Check the example in the screenshot of using Parabola's merge tags to add data from your input.
* Max requests throttles the number of calls sent to API. Drop it to 30 per minute to avoid any issues.
* In authentication, you should add two custom headers. One is `Content-Type` with value `application/json` and the second is `x-api-key` with value being the read/write key that you find in aito.ai console.

![](/files/RtLi7kbfNu4S7WMUeegq)

![](/files/OThMl3r7cibwJY3aO5jn)

#### Making predictions: Pull from an API or Enrich with an API

There are two ways to make queries to aito.ai API from your Parabola workflow.

**Pull from an API** would work if you start by getting some data from aito.ai and push it to other activities later on.

**Enrich with an API** would be more typical way of using aito.ai in Parabola. It enriches your existing dataset by triggering a call for each row and adding something new there. For example predicting a missing datapoint for each row.

Below example pulls data from Google Sheet, enriches it with aito.ai, and then pushes back to another Google Sheet.

![Overview workflow](https://storage.googleapis.com/aito-blog-images/workflow.png)

Click open the activity, and configure your action with aito.ai. Follow the numbering in the screenshots.

1. Choose the right HTTP request method in Type. Most of the times it is POST.
2. Endpoint URL is a combination of yoru instance URL (check from the aito.ai Console), and API endpoint in use. In this case we are using `_similarity` as the endpoint.
3. Query body goes here. Essentially, you are writing an aito.ai predictive query. Remember that Parabola merge tags make it easy to feed in the data from the each row of your input.
4. Add custom header `Content-Type` with a value `application-json`.
5. Add another custom header, where the key is `x-api-key` and the value is the API key that you can fetch from the aito.ai Console.
6. This is really handy! Parabola will parse the response and pick up the right element if you choose "hits" as Top Level Key in the Nested Keys section. Note that in this case it is recommended to limit the query results to one with `"limit": 1` in your query body. This way you'll get only the top prediction for each row.

![Configurinng aito.ai query, part1](https://storage.googleapis.com/aito-blog-images/enrich1.png)

![Configuring aito.ai query, part2](https://storage.googleapis.com/aito-blog-images/enrich2.png)


# Robocorp

Robocorp is a Python native automation platform, and that makes it play extremely nicely with aito.ai! There are two resources to check out to get started.

{% content-ref url="/pages/z6zkRPVFS2DQjTQtn4dk" %}
[Labeling support tickets with Robocorp tools](/solution-examples/labeling-support-tickets-with-robocorp-tools)
{% endcontent-ref %}

{% content-ref url="/pages/VOr8h7xhqxcdaP7b4Rp2" %}
[Purchase invoice automation with Robocorp - video tutorial](/solution-examples/purchase-invoice-automation-with-robocorp-video-tutorial)
{% endcontent-ref %}


# UiPath

A full-on tutorial for using aito.ai on UiPath is coming, but it's actually very easy. Use UiPath's built-in HTTP requests, put aito.ai queries in, and read the results.

We made an extensive video on how to build an invoice automation robot. That covers most of the relevant UiPath integration tricks starting from [19:04](https://www.youtube.com/watch?v=VZPPNqVmYbQ\&t=1144s) onwards.

{% embed url="<https://www.youtube.com/watch?v=VZPPNqVmYbQ>" %}


# Automation Anywhere

aito.ai works great with several workflow automation platforms, including [Automation Anywhere](https://www.automationanywhere.com/). Read the tips to get things going with Automation Anywhere!

#### Creating schema

We recommend creating the data schema in aito.ai Console or with CLI first, as this way you can ensure everything is set up properly to receive your data.

#### Adding data: REST Web Services

Data can be added to aito.ai by using Automation Anywhere's **REST Web Services POST method** action. **Note!** If you are working with bigger datasets, you should explore batch transfer options.

Check the below screenshots for guidance on how to set up the connection. Here are the steps.

1. To the URI, you should input your aito.ai instance URL and the endpoint you want to use, for data upload it's `/api/v1/data/{your-table-name}`.
2. Add a custom header called `x-api-key`, this header describes the API key of your instance. For extra security you can add the API key to Automation Anywhere's **Credentials** vault.\
   ![cust-header-aa](/files/sTGOXYfIq3BZn0XtwGRe)
3. For the custom parameters, select **Content type** as JSON and in the **Enter the parameters** section, define the data you want to add to aito.ai. Variables can be accessed with $$ and don't forget to put string variables into quotations marks.
4. Create an output variable for the result, so you can acces the result later in your flow. The result should be the same as you used as input.

![Add\_dat\_AA](/files/3536ZBxioMojS44t5qT9)

#### Making predictions: REST Web Services

Similarly to data upload, aito.ai predictions can also be managed by the **REST Web Services POST method** action.

In the example flow, we download a file from an URL, read the file and iterate through it to predict a suitable category for each of the inputs and store the results in to a file.

![AA-flow](/files/ZkM0rpULpPl2LXJdQvQV)

Let's go over the details how to setup the REST Web Service in order to make predictions using aito.ai.

1. To the URI, you should input your aito.ai instance URL and the endpoint you want to use, for predictions it's `/api/v1/_predict`.
2. Add a custom header called `x-api-key`, this header describes the API key of your instance. For extra security you can add the API key to Automation Anywhere's **Credentials** vault.\
   ![cust-header-aa](/files/sTGOXYfIq3BZn0XtwGRe)
3. For the custom parameters, select **Content type** as JSON and in the **Enter the parameters** section, define the API query you want to make. Variables can be accessed with $$ and don't forget to put string variables into quotations marks. The data you're using as input should match the schema you have created to your aito.ai instance.
4. Create an output variable for the result, so you can acces the result later in your flow. aito.ai returns JSON responses.

![AA-REST](/files/n4OpGXujPO4P6u9OJ1JG)

The result JSON can be parsed by using the **String: Extract text** activity or by using a readily made [JSON parser bot](https://botstore.automationanywhere.com/bot/json-parser-bot/)


# Blue Prism

Blue Prism has created a connector for making aito.ai API calls, and it's available at their [Digital Exchange](https://digitalexchange.blueprism.com/dx/entry/9648/solution/aitoai).

Watch out for this space for full-on guide coming soon!


# Power Automate

Microsoft Power Automate is a great way of starting the automation journey, especially for companies that have already invested in MS ecosystem tools. Check our quick start video tutorial for using aito.ai in building intelligent automations on Power Automate.

{% embed url="<https://youtu.be/swsCxX7vE-o>" %}


# TagUI

Using aito.ai from the open-source RPA tool [TagUI](https://github.com/kelaberetiv/TagUI) is simple! This example uses an existing dataset in a demo instance, containing some thousands of purchase invoices that have already been categorised for `Product_Category` and `GL_Account`.

#### Uploading data to Aito

{% hint style="info" %}
**EVOLVING ARTICLE**

This article will evolve over time and contain more examples and material later. Data upload part will be added later.
{% endhint %}

#### Making predictions

Using aito.ai predictions as part of the TagUI workflows is as simple as using the built-in [api](https://tagui.readthedocs.io/en/latest/reference.html#api) keyword.

First, construct the Aito query using your input data for the predictions. For example like this:

```json
// Construct a predict query from your input data
linetext = "Rental car New York May 2021"
amount = 34.22
query = {"from": "invoice_data", "where": {"Item_Description": linetext, "Inv_Amt": amount}, "predict": "GL_Code", "limit": 1}
```

Next, consigure the HTTP call headers:

```json
// Configure HTTP headers
api_config = {method:'POST', header:['x-api-key: bvss2i2dIkaWUfBCdzEO89LpxUkwO3A24hYg8MBq','content-type: application/json'], body:query};
```

Then make a call using the `api` keyword. Note that the API key and the aito.ai instance in use here are publicly available for testing. Get your own instance for free at [Console](https://console.aito.ai/).

```json
// Make API call to Aito predict endpoint
api https://public-1.api.aito.ai/api/v1/_predict
```

The use of results is simple, as TagUI automatically returns the JSON version of the response as `api_json`. Here is where you would find the top result's predicted value and confidence:

```json
// Print out the top feature and confidence.
echo Aito predicts `api_json.hits[0].feature` with confidence `api_json.hits[0].$p`
```

#### All the code together

The entire code is here, try running it yourself! :)

```json
// This flow demonstrates the usage of Aito.ai _predict API endpoint with table already existing in Aito

// Construct a query from your input data
linetext = "Rental car New York May 2021"
amount = 34.22
query = {"from": "invoice_data", "where": {"Item_Description": linetext, "Inv_Amt": amount}, "predict": "GL_Code", "limit": 1}

// Configure HTTP headers
api_config = {method:'POST', header:['x-api-key: bvss2i2dIkaWUfBCdzEO89LpxUkwO3A24hYg8MBq','content-type: application/json'], body:query};

// Make API call to Aito predict endpoint
api https://public-1.api.aito.ai/api/v1/_predict

// Print out the top feature and confidence.
echo Aito predicts `api_json.hits[0].feature` with confidence `api_json.hits[0].$p`
```


# Airtable script to fill in missing data

This example shows you how to add a scheduled automation that fills in missing data using aito.ai predictions.

### Uploading data from Airtable to aito.ai

aito.ai extension for Airtable is in review, and hopefully live soon. Check back please.

### Using predictions in automation scripts

In this example we create an automation that fills in the best product category for the new products in your inventory, based on their brand, name and description.

Here's how our starting point looks like, the last four products don't have the category defined. Also we assume that you already have the data uploaded to aito.ai.

![FireShot Capture 131 - Aito Examples\_ Table 1 - Airtable - airtable.com.png](/files/AlUb5rNJnrr9z6J8JijG)

#### Create a custom automation

Kick off by choosing the automations tab from the right pane, unless you already have that open, and click "Create a custom automation".

![](/files/E6F0kl0dEVPsID1H0cQr)

#### Create a trigger

There might be several ways to trigger your automation, but in this example we use "When record matches conditions", and set the rules according to the following picture.

![](/files/bIyOZxcTPOFioswT2IdF)

Another typical way is to create a timed event, that triggers e.g. every 15 minutes.

#### Write some script

For the action, choose "Run script". This will open a full screen editor to write your script in to.

![](/files/CQWnFfk190nB9ggtQhCo)

As a first step, add the input variable that the trigger gives to the automation script. This is done on the left side of the editor, and below is an example that gets you going.

![](/files/zTPx9negkdVxxD6sZrVW)

Next, let's get scripting! This broken to chewable chunks.

First block gets the chosen record (id) in to a variable, and then gets the matching record from the table.

```js
// Assign input record id to a variable
let inputConfig = input.config();
let recordId = inputConfig.recordID;

// Get one record based on id
let table = base.getTable("product_inventory");
let queryResult = await table.selectRecordsAsync();
let record = queryResult.getRecord(recordId);
```

Then let's get aito.ai ready for use. First, configure your instance url, as well as give the read-only API key (you'll find these from the Console).

```js
// Configure aito.ai API (using read-only key)
let aitoUrl = "https://public-1.api.aito.ai/api/v1/_predict";
let aitoKey = "bvss2i2dIkaWUfBCdzEO89LpxUkwO3A24hYg8MBq";
```

Second, we construct a query that will go to aito.ai. Find more examples about queries here, but simply define the table where the training data is, define fields in `where`-block for inputs and then the prediction target.

```js
// Construct aito.ai _predict query body
let body = {
  "from": "airtable-product-inventory",
  "where": {
    "description": record.getCellValue("description"),
    "name": record.getCellValue('name'),
    "brand": record.getCellValue('brand')
  },
  "predict": "category",
  "limit": 1
}
```

With this, we are ready to send the query to Aaito.aiito for predictions. Here's how it happens. We naturally recommend catching errors better than here in the simplified examples.

```js
// Make a request to aito.ai HTTP API
let response = await fetch(aitoUrl, {
    method: 'POST',
    body: JSON.stringify(body),
    headers: {
        'Content-Type': 'application/json',
        'x-api-key': aitoKey,
    },
});
let data = await response.json();
```

One step left! Based on the results from aito.ai, we then update the original record's category, as well as data to "confidence" field, so that it is easier to track the accuracy of predictions later on.

```js
// Update a record in the table based on aito.ai result
await table.updateRecordAsync(recordId, {
    "category": data.hits[0].feature,
    "confidence": data.hits[0].$p,
})
console.log("Record updated!")
```

#### Test

Coding done, all is in place! You can test your script with the Test-button in the top right corner, and if all is great, close the full screen editor with "Finish editing". After closing, remember to click "Done" on the script block to finish the entire process.

\\


# Labeling support tickets with Robocorp tools

In this tutorial, you will learn how to use aito.ai with the Robocorp tools and run intelligent workflows in the cloud.

### Before you begin

#### Prequisites

This tutorial expects you to be familiar with both **Python** and **Robot Framework** at least on a novice level.

#### Getting an aito.ai instance

If you want to follow along with this tutorial, get your own free aito.ai instance from the [Console](https://console.aito.ai).

1. Sign in or create an account, if you haven't got one already.
2. In the [Console](https://console.aito.ai) go to the instances page and click the "Create an instance" button.
3. Select the instance type you want to create and fill in needed fields, Sandbox is the free instance for testing and small projects. Visit our [pricing page](https://aito.ai/pricing/), to learn more about the aito.ai instance types.
4. Click "Create instance" and wait for a moment while your instance is created, you will receive an email once your instance is ready.

#### Accessing instance details

After the instance creation is ready, you can access the URL and API keys of the instance by

1. Log in to Console
2. Click on the instance your created
3. Go to the overview page. You can copy the API keys after clicking the eye icon.

![api\_info](/files/VHVKQSkuZ3OVztkcaP5o)

#### Getting Robocorp Lab & Cloud

For this tutorial you will need to install and have access to the Robocorp Lab and Cloud. Robocorp provides you with good instructions on how to get access to their products in their docs.

[How to install and setup Robocorp Lab & Cloud](https://robocorp.com/docs/courses/beginners-course/set-up-robocorp-lab)

### Use case: Labeling support tickets

Most companies nowadays have a ticketing system in use. Whether it be internal development or external customer support, usually everything has to have a ticket. To keep track of which tickets are important and relate to which team the ticket task belongs to, the tickets need to be labeled. The person labeling the tickets needs to read through the whole ticket before they can decide which class the ticket belongs, or how urgently it needs to be addressed. With many incoming tickets, this task takes a lot of time and isn't that motivating for the employees.

This is where aito.ai comes along and gives out the helping hand. aito.ai just needs the historical data on how have the tickets been labeled in the past and it can deduce how the new incoming tickets should be labeled.

aito.ai also gives a probability for the predicted label, so the employee can manually check those cases in which aito.ai wasn't entirely sure about the label. So instead of going through 50 tickets per day, the employee only has to check the more tricky ones. By using Robocorp you can create the whole infrastructure in a flash and have the whole process running in the cloud as a scheduled task.

### Data

The data used in this tutorial is gotten from [Kaggle's ticket classification](https://www.kaggle.com/aniketg11/support-tickets-classification/data). The data comprises of anonymized labeled support tickets with original messages from users. There are two datasets. One is used as training data, so it is already labeled (category column) and includes also subcategory columns. Testing testing data does not have the labeling information (category) and the subcategories.

#### Training tickets

| title                | body                                                                                       | ticket\_type | category | sub\_category1 | sub\_category2 | business\_service | urgency | impact |
| -------------------- | ------------------------------------------------------------------------------------------ | ------------ | -------- | -------------- | -------------- | ----------------- | ------- | ------ |
|                      | hi since recruiter lead permission approve requisitions makes please make thanks recruiter | 1            | 4        | 2              | 21             | 71                | 3       | 4      |
| connection with icon | icon dear please setup icon per icon engineers please let other details needed thanks lead | 1            | 6        | 22             | 7              | 26                | 3       | 4      |

### Overview

1. Setup Robocorp lab
2. Creating the ticket labeling robot
3. Running your robot in the Robocorp cloud

### #1 Setup Robocorp Lab

If you followed the instructions in chapter "Before you begin", you should now have an aito.ai instance, access to Robocorp cloud and Robocorp Lab installed.

1. Open Robocorp Lab and click "Create new robot".\
   ![robolab](/files/6woDRKOgzpVzxHkpQ24U)
2. Name the robot e.g. "Ticket Classifier".\
   ![namerobot](/files/pm7XU6b5QhQ60DwRM78t)
3. After the robot template has been created open the **conda.yaml**. In the conda.yaml, you can add all the different RF and Python libraries you need in order to create your robot. Under **pip** add `aitoai==0.4.0`. The following configurations were used when this tutorial was created, use newer package versions at your own risk.\
   ![conda(1)](/files/WaWwxVsUOjlqspVAHSZo)

### #2 Creating the ticket labeling robot

#### Define the workflow

First you will have to plan the workflow you want the robot to do. Where does the data come from? How to get it to aito.ai? What do I want to achieve with the classification? Where do I want to store the results?

To make things a bit easier for you, we have planned a workflow for the robot.

1. Download the training and test data CSV
2. Upload the training data to aito.ai
3. Create an output for the results that have a probability over a threshold
4. Create an output for the results below a threshold
5. Label the tickets defined in the test data
6. Add the good results to aito.ai as more training data

The idea behind the workflow is that we trust aito.ai to label the tickets correctly when the probability of the label is high enough, i.e. over a defined threshold, but if the probability is lower than the set threshold we want a human to check the results and fix them accordingly.

In the example workflow we add the results back to aito.ai which aito.ai has given high enough probability, just to show that training data can be easily added to aito.ai without any extra retraining steps. In reality you shouldn't add the results which are already good by aito.ai but the results the user has manually curated as then you'll train aito.ai to label the tricky ones better next time aito.ai is used to label tickets.

#### Writing a python helper library

You can easily add python scripts in the Robocode lab template. Just add the python file to the **root** directory. Create a file called `AitoRFHelper.py` to the root directory.

![root](/files/80MbcKvDuJgT7lPhnex8)

In the `AitoRFHelper.py` you will write helper functions to transform the data, predict with aito.ai, create output files and write data to the outputs. [Our Python SDK](https://aito-python-sdk.readthedocs.io/en/latest/) exists to make the integration of aito.ai easier to Python based systems. You can leave the `AitoRFHelper.py` file empty for now, we will get back to it when starting to create the workflow for the robot.

#### Setup the robot

**Credentials**

In order to use your Robot Framework robot with aito.ai, you will have to give it the URL and API key of your aito.ai instance. The Robocorp platform offers you a way to handle sensitive information through their vault. In that way you can have the sensitive information defined outside your repository either in the cloud environment or on your local machine. We will go through both setups, but let's first get the robot to run locally. In order to use the vault you will have to create a `vault.json` somewhere on you machine and define the URL and API key as variables for your robot to use. Here are the steps to follow:

**1.** Create the `vault.json` file somewhere on your computer (not in the robot's directory if you're thinking to add it to git for example) and store your instance information in the file as variables.

```json
{
  "credentials": {
    "aito_api_url": "your-aito-instance-api-url",
    "aito_api_key": "your-aito-instance-write-key"
  }
}
```

**2.** Next create a directory under your robot's root directory (the directory where you created the AitoRFHelper.py) called `devdata` and create a json file in the directory called `env.json`. Copy the following text into the `env.json` and modify the **RPA\_SECRET\_FILE** to point to the `vault.json` you created in the first step.

```json
{
    "RPA_SECRET_MANAGER": "RPA.Robocloud.Secrets.FileSecrets",
    "RPA_SECRET_FILE": "/path/to/vault.json"
}
```

**3.** Then create another directory under your robot's root directory called `variables` and under it a python script called `variables.py`. Copy the following script to the `variables.py`.

```python
from RPA.Robocloud.Secrets import Secrets

secrets = Secrets()
AITO_API_URL = secrets.get_secret("credentials")["aito_api_url"]
AITO_API_KEY = secrets.get_secret("credentials")["aito_api_key"]
```

**4.** Open your robot file `tasks.robot` and underneath the **\*\*\* Settings \*\*\*** add:

```
*** Settings ***
Variables    variables.py
```

**5.** You're now able to use the instance URL and API key in the robot script by referring the variables `${AITO_API_URL}` and `${AITO_API_KEY}` respectively.

**Setup aito.ai Client**

After you have setup the credentials you can define the aito.ai Client in your robot file. In order to have all the necessary keywords at your disposal, you will also have to setup the aito.ai API. Just add the setup for the client and aito.ai API to your robot's settings as follows.

```
*** Settings ***
Variables    variables.py
Library    aito.api
Library    aito.client.AitoClient    ${AITO_API_URL}    ${AITO_API_KEY}    False    WITH NAME    aito_client
```

Now you're all set to start working on your robot!

#### Scripting the robot

The file in which the robot will be written exists in `tasks/robot.robot` it is created by Robocode lab. Let's start going through the workflow step by step.

#### 1. Download the training and test data CSV

You will add the Keywords foŕ the workflow to the \*\*\* Tasks \*\*\* cell of the robot file. Add a keyword `Download Ticket Data` to the tasks.

```
*** Tasks ***
Label tickets
    Download Ticket Data
```

Next you will have to define what the keyword means. Add a \*\*\* Keywords \*\*\* cell and name the keyword as `Download Ticket Data`. It's a good practice to add each new keyword as a new cell for the robot as it will allow you to run just a single keyword at a time. The library `RPA.HTTP` includes a `Download` keyword that can be used for downloading files from URLs. For this tutorial the data files have been uploaded to S3, you can use those URLs for your robot. Set the variable `overwrite` to be `True`, so that when the robot is run it will download new files and overwrite the old ones.

```
*** Keywords ***
Download Ticket Data
    Download    https://aitoai-test-resources.s3-eu-west-1.amazonaws.com/datasets/ticket_classification/training_three_quarters_of_tickets_less_cols.csv    overwrite=True
    Download    https://aitoai-test-resources.s3-eu-west-1.amazonaws.com/datasets/ticket_classification/200_test_cases_wo_answers.csv    overwrite=True
```

The library `RPA.HTTP` has to be added to the **\*\*\* Settings \*\*\*** cell in order for the `Download` keyword to work. At this point you can also add the `AitoRFHelper` that you created earlier to the **ĺibraries** directory.

```
*** Settings ***
Variables    variables.py
Library    aito.api
Library    aito.client.AitoClient    ${AITO_API_URL}    ${AITO_API_KEY}    False    WITH NAME    aito_client
Library           RPA.HTTP
Library           AitoRFHelper
```

To test how the robot now runs press the forward button on top of the script. You will be asked to restart the kernel, press restart. The whole robot file is run. You can then check the log that everything was run successfully (you can ignore the warning about the missing keywords for now). The downloaded files should appear in the robot's directory.

#### 2. Upload the training data to aito.ai

Next you will have to upload the training data into aito.ai. The training data includes the already labeled tickets which aito.ai can then use to deduce labels for new tickets. To use the aito.ai Client add the `Get Library Instance Keyword` keyword to the tasks. Then add a new task called `Upload Training Data`, it will take in the name of the training data file and table name to be created to aito.ai as arguments. The tasks section should now look like the following.

```
*** Tasks ***
Label tickets
    Download Ticket Data
    ${client}    Get Library Instance    aito_client
    Upload Training Data    ${client}    ${trainingFile}    ${tableName}
```

You will also need to add a new library to the settings called `Collections` to be able to use the `Get Library Instance` keyword.

```
*** Settings ***
Variables    variables.py
Library    aito.api
Library    aito.client.AitoClient    ${AITO_API_URL}    ${AITO_API_KEY}    False    WITH NAME    aito_client
Library           RPA.HTTP
Library           AitoRFHelper
Library    Collections
```

The training file and table name arguments are defined through variables, so you will need to add a new cell to the robot file called \*\*\* Variables \*\*\*.

```
*** Variables ***
${trainingFile}    training_three_quarters_of_tickets_less_cols.csv
${tableName}    tickets
```

You will also have to define the keyword `Upload Training Data` as a new cell in the robot file. The `Upload Training Data` keyword will only upload data into aito.ai if the table does not yet exist. The `Quick Add Table` keyword, provided by the aito.api, will infer a schema from the CSV, transform the data, upload the schema and the data.

```
*** Keywords ***
Upload Training Data
    [Arguments]    ${client}    ${filePath}    ${tableName}
    ${tableExists}    Check Table Exists    client=${client}    table_name=${table_name}
    Run Keyword Unless    ${tableExists}    Quick Add Table    client=${client}    input_file=${filePath}    table_name=${tableName}
```

Now run your robot to check that everything works as expected.

#### 3. Create an output for the results that have a probability over a threshold

Next create an output where you will write the results you deem have a good probability. Add a `Create Output` task and define output and table name as arguments.

```
*** Tasks ***
Classify tickets
    Download Ticket Data
    ${client}    Get Library Instance    aito_client
    Upload Training Data    ${client}    ${trainingFile}    ${tableName}
    ${header}=    Create Output    ${client}    ${output}    ${tableName}
```

As output and table name are used as variables, add them to the variables as well.

```
*** Variables ***
${trainingFile}    training_three_quarters_of_tickets_less_cols.csv
${testingFile}    200_test_cases_wo_answers.csv
${tableName}    tickets
${output}    output_aito_classified.csv
```

Now you're missing the definition of the `Create Output` so add the code that creates an output file to the `AitoRFHelper.py`.

```python
def create_output(aito_client, file_name, table_name):
    """ Create output file"""
    schema = aito_api.get_table_schema(
        client=aito_client,
        table_name=table_name
    )
    features = schema.columns + ["$p"]
    with open(file_name, "w+") as open_file:
        line = ",".join(features) + "\n"
        open_file.write(line)
    return features
```

Now you can again run your robot to test that it works as intended. You should see the file `output_aito_classified.csv` being created the **tasks** directory.

Checking the Python script

You can also test that your Python script runs by clicking on the script the same forward button as you would when running the robot.

#### 4. Create an output for the results below a threshold

Let's also create an output file for the results that need manual curation. Similarly as before add the `Create Output` task to tasks. This tine use a different output variable for the file name.

```
*** Tasks ***
Classify tickets
    Download Ticket Data
    ${client}    Get Library Instance    aito_client
    Upload Training Data    ${client}    ${trainingFile}    ${tableName}
    ${header}=    Create Output    ${client}    ${output}    ${tableName}
    ${headerCuration}=    Create Output    ${outputNotLabeled}    ${tableName}
```

Also remember to add the file name variable definition to variables.

```
*** Variables ***
${trainingFile}    training_three_quarters_of_tickets_less_cols.csv
${testingFile}    200_test_cases_wo_answers.csv
${tableName}    tickets
${output}    output_aito_classified.csv
${outputNotLabeled}    output_needs_curation.csv
```

You're now ready to test out this step. You should see the file `output_needs_curation.csv` being created the **tasks** directory.

#### 5. Label the tickets defined in the test data

Now let's get to the real beef of this tutorial, labeling tickets using Aiaito.aito. First you can add a task that creates a simple predict and evaluate query from the uploaded data, we won't go through using the evaluate in this tutorial, but now you know how to get it. Then add a `Label Tickets With Aito` task into tasks. It will take the headers of both the labeled output, the manual curation output and the predict query.

```
*** Tasks ***
Classify tickets
    Download Ticket Data
    ${client}    Get Library Instance    aito_client
    Upload Training Data    ${client}    ${trainingFile}    ${tableName}
    ${header}=    Create Output    ${client}    ${output}    ${tableName}
    ${headerCuration}=    Create Output    ${outputNotLabeled}    ${tableName}
    ${predictQuery}    ${evaluateQuery}=    Quick Predict And Evaluate    ${client}    ${table_name}     ${predictField}
    Label Tickets With Aito    ${client}    ${header}    ${headerCuration}    ${predictQuery}
```

Then you can create the `Label Tickets With Aito` keyword into a new cell. The keyword takes two arguments, headers for the output files. The test data is then read and formated from CSV into JSON as aito.ai queries work in JSON. The keyword `Format CSV To Json` we created to the `AitoRFHelper.py` previously when making the functions to add test data into aito.ai. The result is fetched separately for each row by a for loop and then the result is stored either into the labeled output or the manual curation output, depending on the probability of the result.

```
*** Keywords ***
Label Tickets With Aito
    [Arguments]    ${client}    ${header}    ${headerCuration}    ${predictQuery}
    ${testData}=    Format CSV To Json    ${client}    ${testingFile}    ${tableName}
    FOR    ${testRow}    IN    @{testData}
        &{result}=    Predict Row    ${client}    ${testRow}    ${predictQuery}
        Run Keyword If    ${result}[$p] < ${threshold}    Append Output    ${outputNotLabeled}    ${testRow}    ${result}    ${headerCuration}    ${predictField}
        ...    ELSE    Append Output    ${output}    ${testRow}    ${result}    ${header}    ${predictField}
    END
```

Add to the variables the field to be predicted as `predictField` in this case it is `category` and threshold you want to use for the predictions as `threshold`.

```
`*** Variables ***
${trainingFile}    training_three_quarters_of_tickets_less_cols.csv
${testingFile}    200_test_cases_wo_answers.csv
${tableName}    tickets
${output}    output_aito_classified.csv
${outputNotLabeled}    output_needs_curation.csv
${predictField}    category
${threshold}    0.8
```

If you look at the `Label Tickets With Aito` a bit closer you'll notice that you still have three keywords which haven't been defined, `Format CSV To Json`, `Predict Row` and `Append Output`. Those you will add into the `AitoRFHelper.py`. The formatting of the file is needed for making the queries for aito.ai.

```python
def format_csv_to_json(
        aito_client,
        file_path,
        table_name,
        schema=None
        ):
    """ Format CSV file to JSON """
    # If schema is not given expect to get it from aito.ai
    if not schema:
        schema = aito_api.get_table_schema(
            client=aito_client,
            table_name=table_name
        )

    # Convert the data to be in correct data types by using the schema
    file_df = pandas.read_csv(file_path)
    data_frame_handler = DataFrameHandler()
    converted_file_df = data_frame_handler.convert_df_using_aito_table_schema(
          df=file_df,
          table_schema=schema
        )

    # Modify NA values to be None
    converted_file_df = converted_file_df.where(
        pandas.notnull(converted_file_df), None)

    return converted_file_df.to_dict(orient="records")

def predict_row(aito_client, datadict, predict_query):
    """ Use aito.ai predict endpoint to predict a result for
    the given field for a data row.
    """
    # Use the template query and formulate a query from the data values
    for key in datadict.keys():
        predict_query["where"][key] = datadict[key]

    # Send query to aito.ai predict endpoint
    result = aito_api.predict(
        client=aito_client,
        query=predict_query
        )

    return {
        "feature": result["hits"][0]["feature"],
        "$p": result["hits"][0]["$p"]
        }
```

The query created in the `predict_row` function, looks like the following (data from the first row of the test data is used as an example).

```json
{
	"from": "tickets",
	"where": {
		"title": "for call issues",
		"body": "for call issues hi we have daily meeting with client last period we have issues dialing scenario we calling client phone enter conference number can dial others cannot ones cannot receive message saying busy we already asked client if somehow conference number but confirmed today during call got suddenly disconnected join call anymore could you please look into reflecting bad our work cheers application engineer",
		"ticket_type": 0,
		"business_service": 87,
		"urgency": 1,
		"impact": 3
	},
	"predict": "category",
	"limit": 1
}
```

The `from` clause defines the table we're using for the prediction. Resembles FROM in SQL.

The `where` clause defines the prior information we have on the ticket by using propositions, e.g. `"ticket_type": 0`. This information is used by aito.ai to deduce a label for the ticket.

In the `predict` clause you define the column which you are trying to predict, in this case it's the `category` column.

With `"limit": 1` aito.ai will return only one result by default the results are ordered by highest probability to the lowest, so the first result is the one with highest probability.

Remember to also add the `append_output` function to `AitoRFHelper.py` before trying to run the labeling task.

```python
def append_output(file_name, row, result, header, predict_field):
    """ Append data rows to the created output file"""
    with open(file_name, "a") as open_file:
        row[predict_field] = result["feature"]
        row["$p"] = result["$p"]
        line = ",".join(
            [str(row.get(key, "")) for key in header]) + "\n"
        open_file.write(line)
```

Now you're ready to test how aito.ai makes predictions! Press the forward button in the robot script and see aito.ai in action. After running the robot you should now have content in the labeled output or the manual curation output files. It works, yay!

#### 6. Add the good results to aito.ai as more training data

Now you have only one step left, adding more training data to aito.ai. **Note that normally you should add the manually curated data into aito.ai as those tickets are the ones that are harder for aito.ai so it needs more data in order to do better labeling. Adding the results aito.ai gives can skew the accuracy of the predictions.**

In this tutorial we use the data aito.ai has been sure about to add as training data, just to show how easy it is to add more training data into aito.ai (without any additional retraining steps!). Add a keyword `Upload Data` to tasks.

```
*** Tasks ***
Label tickets
    Download Ticket Data
    ${client}    Get Library Instance    aito_client
    Upload Training Data    ${client}    ${trainingFile}    ${tableName}
    ${predictQuery}    ${evaluateQuery}=    Quick Predict And Evaluate    ${client}    ${table_name}     ${predictField}
    ${header}=    Create Output    ${client}    ${output}    ${tableName}
    ${headerCuration}=    Create Output    ${client}    ${outputNotLabeled}    ${tableName}
    Label Tickets With Aito    ${client}    ${header}    ${headerCuration}    ${predictQuery}
    Upload Data    ${client}    ${output}    ${tableName}
```

Then add the `Upload Data` keyword as follows. The data has to first be transformed into the JSON format (function was defined in the `AitoRFHelper.py`) and then the `Upload Entries` can be used to upload the data into aito.ai.

```
*** Keywords ***
Upload Data
    [Arguments]    ${client}    ${fileName}    ${tableName}
    ${entryData}=    Format CSV To Json    ${client}    ${fileName}    ${tableName}
    Upload Entries    ${client}    ${tableName}    ${entryData}
```

When you now run the robot, after labeling the data the robot will add the newly labeled data into aito.ai. And you're done building your robot! Next let's go through how to run the robot in the Robocorp Cloud.

The full robot can be foud as an attachment in this article, in case you just want to test running the robot in the Robocorp cloud.

### #3. Running your robot in the Robocorp cloud

Set up your robot in Robocorp cloud:

1. [Log in to the Robocorp cloud](https://cloud.robocorp.com)
2. Click on your example organization (or use some existing organization, no need to create a new one if you don't want to)
3. Click on the "New Process" button
4. Give a name to the process e.g. "Ticket labeler"
5. Go to the "Robots" tab and click "New Robot"
6. Give the robot a name, e.g. "Ticket Labeling Robot" (otherwise use the default options)
7. Now open up your robot code in the Robocode Lab (robot.robot file)
8. Click the "Publish to Robocorp Cloud" button in the upper right corner
9. Select the correct Organization (your example organization), Process (Ticket labeler) and Robot (Ticket Labeling Robot) and click "".
10. Wait for the process to finish, you'll see a note in the bottom of the IDE that says *"The robot was successfully pushed to Robocorp Cloud."* when finished.
11. [Go back to Robocorp cloud](https://cloud.robocorp.com)
12. Click yourself to the "Ticket labeler" process and click "Add Step"
13. Select the "Ticket Labeling Robot" and press "Add to process"
14. Go to the tab "Vault" and press "Add"
15. Give the name "credentials" to the secret and click twice the "Add item" button
16. Define `aito_api_url` and `aito_api_key` to the keys section (use the read/write API key value) and click "Confirm". You can get your instance information through the [Console](https://console.aito.ai).\
    ![secret](/files/aG3TbBVJwpOGKaz6C75W)
17. Now you're ready to run your robot in the cloud! Go back to the "Processes" tab and click "Ticket labeler", you should see a "Run Process" button, click it and the robot will start running.

### What's next

Now that you have the robot up and about you could integrate it with your ticketing system. For example, you could choose tickets from a certain time period and upload them to aito.ai as training data. Then schedule the robot to be run on a certain day to get new unlabeled tickets from the ticketing system and use aito.ai to label them and write the labels back to the ticketing system. The tickets that need manual curation could be sent to the employee via email and he could then send the curated file to an email owned by another robot, which would be triggered by the email to store the data into the ticketing system and aito.ai as additional training data.


# Purchase invoice automation with Robocorp - video tutorial

Check out our quick overview on using Robocorp and aito.ai for intelligent invoice automation.

{% embed url="<https://www.youtube.com/watch?v=tjWVnskjBlg>" %}


# Purchase invoice automation with UiPath - video tutorial

Purchase invoices processing is a prime use case for intelligent automation. It is well proven within many organisations, and is shown to deliver automation rates of up to 80%! By automating the steps in the journey of an invoice, companies do not only save on repetitive tasks, but they also improve the correctness of information and speed up the payment times.

**This step-by-step video tutorial takes you through building a robot that predicts and assigns general ledger (GL) codes to the incoming invoices using aito.ai and UiPath.**

Jump right in, and also check out the resources below the video in this article!

{% embed url="<https://www.youtube.com/watch?v=VZPPNqVmYbQ>" %}

#### What do you build with this tutorial?

The tutorial takes a simplistic view, and only focuses on one part of the purchase processing automation: predicting and assigning the GL code for each invoice based on it's details and aito.ai's prediction (that uses historic invoices as training data).

**The steps your robot will complete:**

1. Open an excel file that contains 100 new invoices as rows
2. Loops through each invoice row one by one
   1. Predicts the most likely GL code using aito.ai
   2. Checks if the prediction confidence is above or below selected threshold
   3. Writes results back to each row in the same excel
   4. Colours the "low confidence" predictions in red for easy review
3. Closes the excel workbook and writes a log line of automation rate

Here is an extract of how the completed predictions will look, once added to your source excel:\\

![](/files/VEdqDStMmnJu2DICy47x)

In a real life setting the predictions like this would happen as part of the larger workflow that takes in invoices one by one from OCR or electronic invoices source, and in the end adds the invoice in to an ERP or accounting system.

This tutorial also does not cover the data input part, but uses already populated aito.ai dataset of [historic invoices](https://www.kaggle.com/nikhil1011/predict-product-category-from-given-invoice). In real life there is usually another robot workflow that adds invoices in to aito.ai to keep the training data up to date.

#### What is needed?

* [UiPath Studio](https://www.uipath.com/developers/studio-download). Community edition is enough, the tutorial was built with version 2020.10.2.
* Microsoft Excel (you'll need a version that can edit files, not just view)
* Incoming invoices file, available here:

[100\_invoices.xlsx](https://github.com/AitoDotAI/gitbook-kb/blob/main/.gitbook/assets/100_invoices.xlsx)

{% hint style="info" %}
**New UiPath version available!**

Please note that UiPath published a new 21.04 version of the Studio soon after this tutorial was made. There should be no reason why the tutorial would not work with the new version, but the video is made with the 2020.10.2, and no further testing with new version has been yet completed.
{% endhint %}

#### Copy-pasteable resources

We have included the critical parts that are hard or long to type in to your robot here as copy-pasteable text. Be extra diligent with all the quotes, things will not work if you get just one thing wrong!

**aito.ai EndPoint for the HTTP call:**

```
"https://public-1.api.aito.ai/api/v1/_predict"
```

**aito.ai `x-api-key`value for HTTP call headers:**

```
"bvss2i2dIkaWUfBCdzEO89LpxUkwO3A24hYg8MBq"
```

**aito.ai query for HTTP call body:**

```
"{ ""from"": ""invoices-uipath"", ""where"": {""Product_Category"": """+inputProductCategory+""",""Item_Description"":  """+inputItemDescription+""",""Vendor_Code"":  """+inputVendorCode+""",""Inv_Amt"": { ""$numeric"" : "+inputInvAmt.ToString+ "} },""predict"": ""GL_Code"",""limit"": 1}"
```

#### aito.ai query

Below is a clean version of aito.ai `_predict` query, that is explained in the video.

```json
{
  "from": "invoices-uipath",
  "where": {
    "Product_Category": "CLASS-1758",
    "Item_Description": "Travel and Entertainment Miscellaneous Company Car (Field Only) Akorn Inc Ground Transportation Miscellaneous Company Car (Field Only) May-2018",
    "Vendor_Code": "VENDOR-1065",
    "Inv_Amt": { "$numeric" : 27.55 }
  },
  "predict": "GL_Code",
  "limit": 1
}
```

Above query results in the following prediction response from aito.ai.

```json
{
  "offset": 0,
  "total": 9,
  "hits": [
    {
      "$p": 0.9999999512520671,
      "field": "GL_Code",
      "feature": "GL-6050310"
    }
  ]
}
```


# Freshdesk ticket triage with Integromat - video tutorial

Check how easy it is to triage tickets on Freshdesk with aito.ai and Integromat! And remember to like and comment on the video! 🙏

{% embed url="<https://youtu.be/VQkHasgKOZs>" %}


# Contacting us

Easiest way to get in touch with us is to [join our Slack community](https://aito.ai/join-slack/). You can also [leave your details here](https://aito.ai/contact-us/) and we'll be in touch asap.


