Implementation Of ChatGPT In Power Automate

Introduction

In this blog, I will demonstrate how we can use ChatGPT to implement Q&A where we can ask any questions and the flow will return the answer to that question using the text completions feature of ChatGPT. So, let’s get started.

Step 1

First, go to OpenAI API and then click on Sign Up to register if you don’t have account in it or you can login if you have.

After login, navigate to your profile and then select View API Keys.

Implementation of ChatGPT in Power Automate

Now click on Create new Secret Key to create a new API key.

Implementation of ChatGPT in Power Automate

After getting the key save it in a notepad or any editor for future reference.

Step 2

Go to Microsoft Power Automate and create an Instant Cloud Flow.

Add an input in Manual trigger a flow.

Implementation of ChatGPT in Power Automate

Add Initialize variable action which will store some existing conversations with Humans and AI in a string variable following a new line. For more information, you can visit this link: Introduction - OpenAI API

 Implementation of ChatGPT in Power Automate

Now add Append to string variable action to append the question in the varPrompt variable by following a new line.

Implementation of ChatGPT in Power Automate

Add HTTP action to call the API to get the answer to the question.

Implementation of ChatGPT in Power Automate

Add Parse Json action to parse the body of HTTP action response to extract the answer and configure the action as shown in the below picture.

Implementation of ChatGPT in Power Automate

At last, we will use the Compose action to print the response from the Parse JSON response action which will be stored in the choices object, and then add the following expression.

Expression: first(body('Parse_JSON')?['choices'])['text']

The final flow will look like this,

Implementation of ChatGPT in Power Automate

Preview

Implementation of ChatGPT in Power Automate

Next Recommended Reading How To Use ChatGPT For Cyber Security