Create Test Documents in SharePoint with OpenAI APIs and Power Automate

Create Test Documents in SharePoint with OpenAI APIs and Power Automate

Introduction

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.

  1. Navigate to OpenAI. Sign up, or register to proceed.
  2. From your profile, select View API Keys.
  3. 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.

The curl option will provide you with more information on passing header information. We will use json format for our Power Automate flow.

Power Automate

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.

  1. Generate a given number of random words.
  2. Write an essay for each of the generated random words.

Follow the below steps to set up the Power Automate flow:

  1. 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.
  2. In the next step, we will use HTTP action to post the request to OpenAI API. This will help us to get the random words from OpenAI.
  3. Run the flow manually to see the result. Copy the Body from the output of the HTTP request.
  4. Now, we will use Parse JSON to extract the output.
  5. 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). replace(first(body('Parse_JSON')?['choices'])['text'],decodeUriComponent('%0A'),'')
  6. Further, let us split the comma-separated words string into an array stored in a variable.
  7. Using the Apply to each action, we will iterate through each word by calling OpenAI API to write an essay on it.
  8. Finally, the test document (.txt) can be created in the SharePoint document library using Create file activity.

Use the below formulas:

ParameterFormula
File Nameconcat(items('Apply_to_each'), '.txt')
File Contentreplace(first(body('Parse_JSON_Essay_Response')?['choices'])['text'],decodeUriComponent('%0A'),'')

End Result

After running the Power Automate, the test documents will be generated in the SharePoint document library as follows.

Summary

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.

References

Pause
Enjoy more SharePoint focused at SharePoint Week.

About the Author:

Hello! I’m Nanddeep Nachan.

I am from Pune, Maharashtra, India. Microsoft MVP (Office Apps & Services), Microsoft Certified Trainer (MCT). I am happily married and living with my loving family (Parents, caring sister, lovely wife, and a sweet newborn junior).

I born in a small town Khopoli, cocooned amidst the Sahyadri mountains. Spent my childhood at Matheran, a cozy little hill station. Eventually moved to Mumbai for higher educations and landed in Pune for the job.

I like reading historical books and a big fan of Sherlock Holmes. Photography is my recent developed hobby and I have perceived a Diploma in Photography from Shaw Academy (UK).

On a technical note, I’m a results oriented Technology Architect with experience in Microsoft Technologies especially with SharePoint, MS Azure and .NET. Experienced in design, implementation, configuration, and maintenance of several large-scale projects.

Organizer and frequent speaker at various industry seminars, conferences, and community events including SPS, Global Microsoft 365 Developer Bootcamp, and Global Power Platform Bootcamp.

Reference:

Nachan, N. (2023). Create Test Documents in SharePoint with OpenAI APIs and Power Automate. Available at: https://nanddeepnachanblogs.com/posts/2023-02-12-test-docs-spo-openai-power-Automate/ [Accessed: 2nd May 2023].

Share this on...

Rate this Post:

Share: