Exercise - Generate text with GPT in AI Builder and Power Automate
In this exercise, you'll build a Microsoft Power Automate flow that uses the Create text with GPT using a prompt model in AI Builder to extract information from an email that a customer has sent requesting a real estate showing. The Create text with GPT model extracts the customer's name, address of the property that they want to view, and the date and time of the showing from the email. Then, the model sends a message to a Microsoft Teams channel with the extracted information.
You can use this extracted information to create a record in a Dataverse table. However, that action is beyond the scope of this lab.
Create an automated cloud flow
Sign in to Power Automate.
On the left pane, select Create > Automated cloud flow.
Name the flow Extract details for Real Estate Showing.
In the Search all triggers box, enter
when an email arrives
and then select the When a new email arrives trigger.Select Create.
Select the When a new email arrives trigger to open the trigger details pane.
Select Show all for the advanced parameters and then in Subject Filter, enter
[Query]
.Note
This step ensures that the flow only runs when the subject of the email contains the word "Query" (for the purpose of this lab).
In a real scenario, you might have a separate email address that handles customer queries, so you won't need to filter by subject.
Add a GPT prompt to the cloud flow
Under the flow trigger, select Add an action and then select AI Builder.
Select Create text with GPT using a prompt in the list of actions.
Select Prompt and then select New Custom Prompt.
Name the prompt
Extract Real Estate Showing Details
Paste the following text into the Prompt box:
Extract "Name", "Address", "Date", and "Time" from the text below. When the text below has less than a couple of words, answer that you can't extract information. [Start of text] Good day, I hope this email finds you well. My name is <Your name>, and I am currently in the market for a new property. I came across your listing for the property located at 210 Pine Road, Portland, OR 97204, and am very interested in learning more about it. I would like to kindly request a viewing of this property on September 15th at 3:30 PM. I believe this time is within the normal hours for showings, but if there are any conflicts or alternate time suggestions, please let me know at your earliest convenience. [End of text]
The preceding prompt uses the basic formula for creating a GPT prompt (instruction and context), where the first part of the prompt is the instruction component:
Extract "Name", "Address", "Date", and "Time" from the text below. When the text below has less than a couple of words, answer that you can't extract information.
The following text is the context component of the formula:
[Start of text] context [End of text]
The instruction tells the model what it should do. The context is the information that the model needs to follow the instruction. In an automation task, the instruction is constant and dynamic content provides the context, which you'll update in the next step.
Select Test prompt to see if GPT extracts the correct information from the text.
After a few seconds of preparing a response, the GPT model should be able to extract the relevant information from the example prompt:
Select the Input drop-down from the right side Prompt settings.
Select + Add Input and name it BodyInput.
Delete the example email between the
[Start of text]
and[End of text]
from the Prompt.With your cursor still between
[Start of text]
and[End of text]
, select the + Insert button, and then select BodyInput.Select Save custom prompt.
Now a new field called BodyInput will appear on the AI Builder action. Select this field and then select the Body dynamic content of the email from the trigger.
Whenever an email arrives, GPT attempts to extract the relevant information from the email body.
AI-generated content can be factually incorrect, inappropriate, or biased. We strongly recommend that you institute a practice of inserting human oversight in workflows that use AI-generated text before it's posted or used anywhere.
Now, you'll add an approval step so that a human can review the extracted information.
Add an approval step into the cloud flow
Select Add an action and then search for and select Approvals.
In the list of actions, select Start and wait for an approval of text.
In the Title box, enter
Review extracted information
.In the Suggested text box, add the Text dynamic content from the Create text with GPT using a prompt action.
Select Switch to Advanced Mode and then in the Assigned To box, enter the email address that you're using for this lab.
In the Details box, enter the following text:
Please review the extracted information and edit as necessary.
Select Add an action, search for Control, and then select Condition.
Select the Choose a value box and then select Outcome from the Dynamic content.
Select is equal to for the condition and then enter
Approve
for Choose a value.In the True box, select Add an action. Search for Microsoft Teams and then select Post message in a chat or channel.
Note
If you need to sign in to create a connection to Microsoft Teams, follow the prompts on screen to sign in.
Select Flow bot from the Post as dropdown menu, and then select Chat with Flow bot from the Post in dropdown menu.
Select Switch to Advanced Mode and then in the Recipient box, enter the email address that you're using for this lab.
For the Message box, enter the following text:
Please add the following Real Estate Showing Request. Client Email:
With the cursor next to Client Email, select Add dynamic content and then select the From option from the When a new email arrives action.
Beneath the Client Email line, select the Accepted text dynamic content from the Start and wait for an approval of text action.
This step sends a direct Teams message to you with the Client Email and the Accepted text from the approval action to remind you to create a record in the Real Estate Showings app from Microsoft Power Apps.
You can automate the record creation by converting the extracted entities into a JSON object and then using that object to create a record in the Real Estate Showings app and Dataverse table. However, that action is beyond the scope of this lab.
In the If no box, you can add a Send an email action to notify the sender that insufficient information was provided for booking the showing. However, you can add that action in your own time.
For now, save the flow by selecting Save.
Test the flow
Select Test > Manually and then select Test.
From any email address, send an email to the email address that you're using for this lab with the subject of
[Query] - New Booking Request
and the following body content:Hello, I trust you're doing well. I'm John Doe and I'm actively searching for a new home. Your listing for the property at 789 Maple Avenue, Lexington, KY 40502 has caught my attention, and I'm eager to find out more. Could I arrange to see the property on September 29th at 1:45 PM? I think this falls within your usual showing times, but if that doesn't work for you or if you have other time options, I'd appreciate it if you could inform me as soon as possible.
Open Outlook, which should show the email that you've sent to yourself followed by the Approval request with the extracted information, as shown in the following screenshot.
Select Approve and Submit and then open Teams. After the request is approved, you should receive a message from the flow bot with the extracted information, as shown in the following image.
Return to your Power Automate flow, where the flow should show a successful run.
In the top-left corner of the screen, select Back. This will take you to the Extract details for Real Estate Showing flow details page.
Add the flow to the Real Estate Solution
On the left navigation pane, select Solutions.
Select the Real Estate Solution.
On the top command bar, select Add existing > Automation > Cloud flow.
Select the Outside Dataverse tab and then select the Extract details for Real Estate Showing flow.
Select Add.