UiPath
- Updated On 16 Nov 2020
- 5 Minutes To Read
-
Print
-
DarkLight
Before you begin
Getting an Aito instance
If you want to follow along with this get started guide, you'll have to go and get your own Aito instance from the Aito Console.
- Sign in or create an account, if you haven't got one already.
- In the Aito Console go to the instances page and click the "Create an instance" button.
- 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, to learn more about the Aito instance types.
- Click "Create instance" and wait for a moment while your instance is created, you will receive an email once your instance is ready.
Getting UiPath
If you haven't already, install UiPath Studio on your machine, or use any other UiPath software you're familiar with.
TL;DR
Getting started with Aito in UiPath is quite straight forward. Follow these steps to use the basic functionality.
- Create the UiPath variables, but add your specific API URL and key.
Name | Variable type | Scope | Default |
---|---|---|---|
api_url | String | Sequence | "your-predict-api-url " |
api_key | String | Sequence | "your-rw/ro-api-key " |
table | String | Sequence | "invoice_data" |
target | String | Sequence | "Product_Category" |
inputs | String | Sequence | |
query | String | Sequence | |
response | String | Sequence |
- Formulate the query with Assign activity
Value for the query variable:
"{""from"": """+table+""",""where"": "+inputs+",""predict"": """+target+""",""limit"": 1}"
- Set up HTTP Request activity with the correct properties
The API URL needs to be the full path to the _predict endpoint, e.g. https://your-instance.aito.app/api/v1/_predict
Intro
Using Aito through UiPath works with the exact same principle as using Aito with a REST client: You can use the default HTTP Request activity in UiPath to send queries and get responses. This tutorial uses the _predict endpoint to make predictions, but the same principles apply to any other Aito query. This guide is done by using the UiPath project as a base.
Data
Data lives in Aito as tables. The train.csv
of a Kaggle dataset will be put into Aito as one table which will be called invoice_data. It is possible to use linked tables in Aito but in this example having just one table is enough.
Aito needs data from the past in order to make predictions for the future. Kaggle has an excellent sample dataset (train.csv) which contains +5500 rows of data from invoices and the correct category for each. . The details can be used to define the invoice we want to predict category for. The value we want to predict also has to be encoded in the data as a column (or a feature in data science terms), in this case, it is Product_Category
.
Here's a snapshot of the data:
Inv_Id | Vendor_Code | GL_Code | Inv_Amt | Item_Description | Product_Category | ||
---|---|---|---|---|---|---|---|
15001 | VENDOR-1676 | GL-6100410 | 83.24 | Artworking/Typesetting ... | CLASS-1963 | ||
15002 | VENDOR-1883 | GL-2182000 | 51.18 | Auto Leasing Corporate ... | CLASS-1250 | ||
15004 | VENDOR-1999 | 6050100 | 79.02 | Store Management Lease/Rent ... | CLASS-1274 | ||
... | ... | ... | ... | ... | ... |
Upload Data
- Upload the sample dataset into your Aito instance with the drag & drop feature in Aito Console instance overview.
- Change the table name to invoice_data.
Enable Packages
You first need to install the UiPath.Web.Activites package via the Manage Packages windows to get access to the HTTP Request activity. You also need to install the UiPath.System.Activities package to enable reading text files.
Create Variables
First, create a Sequence activity. The sequence uses several variables. The HTTP Request needs the URL and key, while the query needs a table name and target column name. You also need empty placeholders for inputs, query and response. These will be assigned during the sequence.
- Click on Activities in the left sidebar
- Add the Sequence activity
- Click on variables (note that the Sequence activity should be selected)
- Add needed variables to the Sequence activity
Needed variables
Name | Variable type | Scope | Default |
---|---|---|---|
api_url | String | Sequence | "your-predict-api-url " |
api_key | String | Sequence | "your-rw/ro-api-key " |
table | String | Sequence | "invoice_data" |
target | String | Sequence | "Product_Category" |
inputs | String | Sequence | |
query | String | Sequence | |
response | String | Sequence |
You can get your Aito instance API URL and API key through the Aito Console.
Note that the your-predict-api-url should be the full path to the _predict
endpoint e.g. https://your-instance.aito.app/api/v1/_predict.
Read Input Data
In this tutorial, the input information is read from a text file. In the real world scenario, the inputs would come from earlier parts of the sequence. Here's an example of how the input.txt file should look like, located in the project directory:
{
"Inv_Id": 15033,
"Vendor_Code": "VENDOR-1424",
"GL_Code": "GL-6100410",
"Inv_Amt": 78.78,
"Item_Description": "Digital Display"
}
The input describes an imaginary invoice for which the invoice category will be predicted. Aito will use all of the variables defined for the invoice as information about the invoice.
Use the Read Text File activity to assign the file content to the inputs variable:
Formulate Query
Next, you will define the query that will do the prediction of the invoice category.
Aito query's generic syntax
The aito query follows a syntax that is based on this rule:
From a given context (a specific table and what is known from that table), use an operation to find the known or the unknown.
{
"from" : define the initial context (table name),
"where" : more details of the context,
"operation_name" : operation to be perform,
"orderBy" : sort the result by some metric,
"select" : select specific attributes or parts of the result,
"offset" : define the number of rows in the result to be skipped,
"limit" : limit the number of rows to be shown in the result
}
Query in UiPath
Aito expects the query to be in the proper format for the endpoint. Use the Assign activity to set up the query in its correct form. In UiPath the easiest way to go about this is by using Strings.
"{""from"": """+table+""",""where"": "+inputs+",""predict"": """+target+""",""limit"": 1}"
Send Query
Add the HTTP Request activity and fill the properties with the correct options and variables. Remember to open up the Options -> Headers window to fill in the x-api-key
and content-type
headers. The response from Aito is assigned to the response variable you created.
Show Results
Lastly, you might want to inspect the response from Aito. The simplest way to do this is to use the Write Line activity and display the newly received content of the response variable in the Output window.
We have been asked for tips how to parse the relevant parts of full Aito's JSON response to separate variables in UiPath. Check out the article here.
Run the pipeline
Now you're ready to run the prediction pipeline. Select the sequence and hit the "Debug File" play button.
The following result should be now shown in the Output window.
Full Sequence
Here's how the full sequence looks like. Quite straightforward.
You can find the sequence as an attachment in this guide. After uploading the sample dataset to your Aito instance, to run the UiPath file you will have to go through these steps:
- Download the attachment
- Create the input.txt file in the folder you saved the attachment
- After opening the file, install the UiPath.Web.Activities package
- Add your API URL and API key to the Sequence variables
- Run the file