AI builder in Power Automate
Tags: aibuilder, powerautomate, powerplatform, powerapps
Published: 2023-06-09 08:27:15

Greetings to all Tech enthusiasts and Tech specialists!!!

In this post, I am going to demonstrate how to use AI Builder actions in Power Automate.

**Scenario**: In a table of an Excel sheet identify the sentiments of the text in a column and insert another column to show whether that text meant positive or negative.

### Objectives

- Prerequisites
- Create a flow
- Add an AI Builder action
- Configure AI Builder action
- Use model's inference
- Test flow

### Prerequisites
- Power Automate accessibility.
- A license or trial of the AI Builder.
- An environment with a Microsoft Dataverse database. (Applicable only for work or school accounts).
- A Microsoft Office 365 subscription with access to Excel Online (Business) and OneDrive for Business.
- A basic understanding of Power Automate and experience with creating a flow is recommended.

### Create a flow

In this section we are going to create a Microsoft Dataverse solution for creating flow and adding AI builder actions to that flow.

- Sign into Power Automate.
- Select **Solutions** options from the side bar menus and then select **+New Solution**.

![ai2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58vj0i534ftc77n85dkp.png)

- In the **New Solution** side screen enter the following details and select **Create**:-

| Options     | Values |
| ----------- | ----------- |
| Display Name      | AIApp |
| Name      | AIApp       |
| Publisher  | Select the publisher from the drop down list or create new publisher by selecting **+New Publisher**.  I have create a publisher named **AIpublisher** and then selected it.      |

![ai3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n396fhgr774qw4fa7j8w.png)

- After creating the AIApp solution please select the solution and then Select **+New > cloud flow in the action bar on the top of the screen. Then Select **Automation > Cloud flow > Instant**. 

![ai4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pk7x0tjbtd3ocdtssuzo.png)

- The Build and instant cloud flow designer screen appears and enter name as **AIflow** on the **Flowname** box, then select **Manually trigger a flow**, then select **Create**.

![ai5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/etxk6wcl7tz360qimaeh.png)

### Add an AI Builder action

- On the **Manually trigger a flow** select **+Add an input**, then select **Text** and on the input box enter **MyText**.
- Select **+New Step**.
- In the search box, enter **Analyze sentiment**, then select **AI Builder**.
- From the actions tab select **Analyze positive or negative sentiment in text**.

Depending on the needs of the underlying models, different parameters apply to each AI Builder activity.

The two required fields for the AI Builder sentiment analysis model are Language and Text.

### Configure AI Builder action
- In the Language field, select English as the language.
- In the Text field, select My Text, which is defined in the trigger action.
The MyText value will be provided during flow testing, so you don't need to focus on it right now.

- Select Save. Your flow is now saved in the name of AIflow. 

### Use Model's inference
For this task, you'll use a Microsoft Excel file in OneDrive to store the text sentiment that is detected by the AI model.
- Create a Microsoft Excel file named **AIresults.xlsx** and saved it into Onedrive.
- In this file, insert a table with two columns and then save the file (make sure that you use the Insert > Table function of Excel).
- In AIflow, select **+ New step**, then select **Excel Online (Business)** then add the **Add a row into a table action** from Excel Online (Business).
- Complete the Location, Document Library, and File fields to point to the Excel file on your machine.
- In the Table field, select the name of the table that you created in your Excel file.
- In the Column 1 field, add **MyText**, and in the Column 2 field, add **Overall text sentiment**, then select **Save**.

### Test flow
- Select Test on the upper-right corner of the flow designer screen.
- Select Manually - Perform the starting action to trigger it. and the select Save & Test.
- Provide the value of the **MyText** field from the trigger action. This text is what you want to analyze the sentiment for. For this example, we'll enter **It was the best session**.
- Select Run flow. If your flow ran successfully, you would see all steps shown with a green checkmark.

![ai7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ou3gndpjl98oyohpttj.png)

- You can expand the actions to view the running inputs and outputs of each action, which is a good way to debug your flow.

- Check that the line has been correctly added in the Excel file.

![ai8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mt360qo237121h9sg8v6.png)

- Provide the value of the **MyText** field from the trigger action by selecting **Test** from the top menus.  Here we'll enter **A very bad session**.
- Select Run flow. If your flow ran successfully, you would see all steps shown with a green checkmark.
- Check that the two lines has been correctly added in the Excel file.

![ai9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1ub81sx0j2xmy2e5eqn.png)

Thanks all !!!

Hope You Enjoyed the Post!!!

Keep Learning | Spread Knowledge | Stay blessed |