Create Test Documents in SharePoint with OpenAI APIs and Power Automate
While working with SharePoint, we most times need to create test content related to a specific topic. OpenAI API is the best fit in this case to generate content related to any topic.
In this article, we will explore how OpenAI API can be combined with Power Automate to generate content in SharePoint.
Get the API Key
Follow the below steps to get the API key to work with Open AI 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.
Open AI Playground
Before we start using the Open AI functionality in our application, the best place to play and test it, is the Open AI Playground.
Once you are happy with evaluating the functionality, click View code. The available code options are python, node.js, curl, and json.
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. We will make 2 calls to OpenAI APIs to generate a document (.txt) in SharePoint.
- Generate a given number of random words.
- Write an essay for each of the generated random words.
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 define a variable to store the “Number of documents” to generate.
In the next step, we will use
HTTPaction to post the request to OpenAI API. This will help us to get the random words from OpenAI.
- Run the flow manually to see the result. Copy the Body from the output of the HTTP request.
- Now, we will use Parse JSON to extract the output.
In the next step, let us initialize a variable with the below expression to store the response from Open AI (i.e., randomly generated comma-separated words).
Further, let us split the comma-separated words string into an array stored in a variable.
Using the Apply to each action, we will iterate through each word by calling OpenAI API to write an essay on it.
Finally, the test document (.txt) can be created in the SharePoint document library using Create file activity.
Use the below formulas:
After running the Power Automate, the test documents will be generated in the SharePoint document library as follows.
OpenAI API is the best fit to generate content related to any topic. This feature can be combined with Power Automate to generate content in SharePoint.
Leave a comment