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


shaik ashikPosted Jul 10, 2023, 4:09 PM
It was a great article. I am getting an error while using "HTTP" action. Please find the error "UnresolvableHostName. Http request failed with status code 'NameResolutionFailure' and status message: 'The remote name could not be resolved: 'api.openapi.com''." Kindly help me.
SukruthPosted Mar 1, 2023, 10:08 AM
Flow looks good, but my flow is failing in HTTP action, what may be the reason? below is the error message:<html><head><title>400 Bad Request</title></head> <body> <center><h1>400 Bad Request</h1></center> <hr><center>nginx</center> </body> </html>
Shriram PophaliPosted Feb 24, 2023, 7:46 AM
Thank you Sagar for sharing this nice article! One thing I observed with text completions api is, it is returning response only for statements like "total world population is", "rainbow is", "capital of India is", which seems reasonable as it is text completions api.
robin wongPosted Feb 24, 2023, 3:55 AM
Hi Chand, had the same blank output after running the flow. any thought?
Wei HePosted Jan 23, 2023, 12:50 PM
I've got the blank output or commar output after run the flow
IT SolutionPosted Jan 17, 2023, 10:19 AM
Hi Chand, Could you share the full Schema in Parse Json field. Thank you in advance. Thank for the sharing alot.
Chris LovePosted Jan 16, 2023, 7:54 PM
Good example of how to leverge the OpenAI tool in a real-world application. I believe there will be a lot of demand for developers to do exactly this sort of thing inside of businesses over the next year. This will be a good reference article to get started on these projects!
Sagar VishwakarmaPosted Jan 16, 2023, 6:19 PM
Thank you, Mahesh Chand. It means a lot.
Mahesh ChandPosted Jan 16, 2023, 1:32 PM
Impressive! Very nice and innovative. I see many businesses can take advantage of ChatGPT in this way.