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.
Now click on Create new Secret Key to create a new API key.
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.
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
Now add Append to string variable action to append the question in the varPrompt variable by following a new line.
Add HTTP action to call the API to get the answer to the question.
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.
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,
Preview