Let AI Builder figure out the user’s meaning!

Shows Batman programming.

Continuing on with my series about building a HR Copilot with Copilot Studio. Previously I’ve been advocating of making a multiple choice option with prefilled options to steer the answer in the right directions. But with the rise of Generative AI we can look different at how we program our apps. We can now do things significantly different. In my last post we changed our manually authored topic to an action. We lost the ability to steer the user in the right direction by presenting a multiple choice option set. And instead of trying to fix this, I want to show you a different way. Let Generative AI figure out the meaning of the provided answer by the user. No complex (Azure) Open AI connections needed, we can use AI Builder for this!

Now before I dive deep how to set this up, I want to talk a little bit about the future of programming. More and more I see examples of how Generative AI can solve tasks which in the future would require a lot of programming. Tasks such as find the nearest shop based on your location. Previously this would be a tedious programming exercise. Now we can ask ChatGPT to do this for us, if we provide it with enough information. The challenge for me is, to think about solutions like the previous and my upcoming example. As my default still is to program it out in (low) code. But being creative with specific instructions to a large language model can often be a better fit.

Create your first AI Builder prompt

On to the task at hand. The plugin action asks the user an open-ended question: “What leave type do you wish to request?”. There are tons of ways to answer this question. The user could input a short message like: “Vacation”, “Holiday”, “Day off”. Or they could answer in a full sentence: “I would like to go on a city trip”. For our HR system, all of these answers would result in the same option. In my example I call it “holiday leave”. Finding the correct option set to correspond will be hard to program. Let’s ask AI Builder to figure this out for us! We will use AI Builder within Power Automate which we use as an action in Copilot Studio.

Step 1 in the AI Builder Create text with GPT using a prompt model.
Create Prompt

First we need to create our first prompt. In the Power Automate portal, go to the AI hub, or go to the AI prompts directly. From here choose “Create text with GPT using a prompt”. This will start you off with some explanation of what is available in the editor.

Step 2 in the creation of the prompt wizard
Create Prompt step 2

Input Parameters of the AI Builder prompt

In the next step we can start building our prompt. The great thing about this interface is that we can test our prompt right here. But first we need to define some input parameters for our prompts. In our example we want the model to give us a specific leave type. So we define an input for the leave types the model can choose from. Consider it a best practice to not hard-code parameters like this in your model.

Shows the 2 inputs for our AI Builder Prompt. 1 is a list of Leave Types. The second is the user request
AI Builder Model Inputs

The second input parameter is the actual user request. This can be an entire sentence, or a single word. In the prompt we can use these input parameters as variables. We can already define sample data to the input parameters. This data is what is used to test our prompt inside the interface.

On to the actual Prompt

We are all learning on how to craft the best prompts. I am no expert in prompt engineering, so go read up on AI Builders prompt engineering guide for building a good prompt. I find that with some playing around and trial and error you can get the result you want. The prompt I use is:

Please select one of the leave type options from the following comma separated list: "Leave Types"
Return the best possible leave request from the following input: "User request". 
Reply in a JSON format.
For example: 
{ 
    'match': 'Sick Leave' 
}
Our finished AI Builder Prompt. We can now use Test Prompt to test it.
AI Builder Prompt Overview

A couple of noteworthy things. I request the model to respond in JSON. I tried to just have the model respond with the Leave Type. However this was inconsistent. The model has a tendency to chat and add more words then just the leave type. Changing the response to a JSON solves that. Also it is a good practice to do so, as in other prompts you might want to extract multiple things at once. The second noteworthy point is that it helps to give the model examples of the answer you want. In my case, the JSON structure.

Shows the result of our AI builder model. The result is a json with the correct leave type
AI Builder Prompt Overview with Response

We can now test the model and see if we get the right response. As always, it’s a good practice to create various test scenario’s with both expected and unexpected answers to the prompt.

Power Automate as the glue to put it all together

Now how would we use this AI Builder model in our Copilot Studio topic? Actually we don’t. At least, not directly. We will incorporate this in the existing action. Of course under the hood this action actually is a Power Automate Cloud Flow. Within Power Automate we can add AI Builder action. Select “Create text with GPT using a prompt” for the prompt we just created.

Highlights the correct AI Builder action to select in Power Automate: "Create text with GPT using a prompt"
Select Create text with GPT using a prompt

In the option set of available prompts we can see a couple of out of the box prompts, and our own prompt.

Shows that you have to select a prompt to use, or create a new one in Power Automate after selecting the correct AI builder action
Select Correct Prompt

As input parameters we will give it a comma separated list of the leave types we want the prompt to choose from. For this blogpost I put them in manually. But in a production scenario, you can of course retrieve the available leave type from your HR system.

The second parameter is the “Leave Type” answer of the user. This parameter is also an input parameter of the Cloud Flow which Copilot Studio calls.

Add input parameters to the Power Automate Flow Action
Input Parameters AI Builder Node

There you have it, with a couple of steps and a good AI Builder prompt, we can identify correctly what the user means with their request. The faster and better these Large Language Model will be, the more I see programming as we know it change. I’m curious about scenario’s you’ve used generative AI for. Let me know in the comments!

Leave a Reply

Your email address will not be published. Required fields are marked *