cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Call AI Builder Models Dynamically via Variable

Hello everybody,

 

my issue is the following:

I created Form Processing models that give the same output given the inputs of "Document Type" (1) and specified "Document" (2). Due to differing layouts they need to be in separate models. What currently works is to call each model individually with their own Predict connector in a child flow and then use the output in the parent flow. When I try to put a variable as the model name, my model specific inputs (1) and (2) throw an error and instead a new generic input "Body" appears.

My current implementation requires one child flow per model. Is there a way to call the AI Builder models dynamically, i.e. save the model name to be called in a string variable defined at the beginning of the flow and use this as the "Model" input?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Power Apps
Power Apps

Re: Call AI Builder Models Dynamically via Variable

Thanks @aQguy,

 

Instead of base64(triggerBody()?['file']?['contentBytes']), can you try with the string function? Like this string(triggerBody()?['file']?['contentBytes'])

View solution in original post

5 REPLIES 5
Highlighted
Power Apps
Power Apps

Re: Call AI Builder Models Dynamically via Variable

Hi @aQguy,

 

Thanks for posting the question.

 

Today it's not possible to set the AI Builder model dynamically on the predict action, although it something we are looking to enable.

 

One approach I can think of is that you could call various predict actions within a single flow, and after each predict action you set as many variables as outputs you want to get from the model and then use those variable in successive steps in your flow. Here is an example: 

 

2020-05-20_23-16-36.png

 

If this doesn't fit your needs, there is a workaround you might look into (but I need to warn you that we don't officially support it  🙂).  This consists on using the Perform a bound action action on the Common Data Service (current environment) connector. In here you:

- Select as Entity name: AI Models

- Set as Action name: predict

- In Item id (1) you can dynamically specify the id of the AI Builder model you want to call.  

- Set version as: 1.0

- On the request: Set the content type of the file you want to analyze (2) and provide a base 64 string of the file to analyze (3) within the structure you see on the screenshot.

 

When this action gets executed, you will get a JSON response that you can parse.

2020-05-20_23-27-56.png


Let us know if this helps and what approach you end up taking!

Highlighted
Regular Visitor

Re: Call AI Builder Models Dynamically via Variable

Thanks a lot @JoeF-MSFT ,

 

a solution like the second one with the "Perform a bound action" action is what I was looking for.

Unfortunately, I can't quite make it work yet. Power Automate reads the "request" input as a string and embeds it in quotation marks:

 

"item/request""{\"mimeType\":\"application/pdf\",\"base64Encoded\":\"@{base64(triggerBody()?['file']?['contentBytes'])}\"}"

 

As I understand the correct syntax ought to be:

 

"item/request": {
    "mimeType":"application/pdf",
    "base64Encoded":"@{base64(triggerBody()?['file']?['contentBytes'])}"
}
 
Is this correct? If so, it would require to remove the leading and trailing double quotes as well as the escapes in front of the double quotes. I did not find a way to accomplish this. Does anybody have ideas?
Highlighted
Power Apps
Power Apps

Re: Call AI Builder Models Dynamically via Variable

Hi @aQguy,

 

Could you share a screenshot of how you have configured your Perform a bound action?

 

Thanks!

Highlighted
Regular Visitor

Re: Call AI Builder Models Dynamically via Variable

Here you go @JoeF-MSFT :

 

My input:

grafik.png

 

The underlying code:

grafik.png

 

The (default) settings:

grafik.png

 

Thanks a lot for helping me.

Highlighted
Power Apps
Power Apps

Re: Call AI Builder Models Dynamically via Variable

Thanks @aQguy,

 

Instead of base64(triggerBody()?['file']?['contentBytes']), can you try with the string function? Like this string(triggerBody()?['file']?['contentBytes'])

View solution in original post

Helpful resources

Announcements
firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Users online (8,121)