OpenAI is the most buzzing thing at this moment. It is powered by a family of models with different capabilities.
In this article, we will use the OpenAI API to answer the questions from Power Automate.
Get the API Key
Follow the below steps to get the API key to work with OpenAI APIs.
- Navigate to OpenAI. Sign up, or register to proceed.
- From your profile, select View API Keys.
Click + Create new secret key to create one. Note down the secret key for future use.
Before we start using the OpenAI functionality in our application, the best place to play and test it, is the OpenAI Playground.
From the playground, you can load a pre-defined preset (e.g., Q&A, Chat, etc.) and select other configurations.
Once you are happy with evaluating the functionality, click View code. The available code options are python, node.js, curl, and json.
The curl option will provide you with more information on passing header information. We will use json format for our Power Automate flow.
We will now develop a Power Automate flow to make a request to OpenAI API to answer the user question.
Follow the below steps to set up the Power Automate flow:
We will start by creating an instant cloud flow and add input as a Question. In the next step, we will have a variable to store the prompt.
In the next step, we will use HTTP action to post the request to OpenAI API.
Run the flow manually to see the result. Copy the Body from the output of the HTTP request.
In the next step, we will use Parse JSON to extract the output. Use the expression
first(body('Parse\_JSON')?['choices'])['text']in the compose action to see the response from OpenAI.
Test the result
Manually trigger the flow and ask your question. You should get the answer back from the OpenAI API.
OpenAI offers various models to use in various scenarios. OpenAI API can be consumed in Power Automate to answer user queries.