top of page
Search

How to Use OpenAI APIs to Generate Action Items in Google Docs: A Guide

  • Writer: Mark Stankevicius
    Mark Stankevicius
  • May 28, 2024
  • 11 min read
splash image conveying the concept of a Gen-AI powered action item generator in Google Docs

Introduction to automated action item generation

In this blog post, we will explore the process of integrating OpenAI's powerful AI into Google Docs using Apps Script. We will walk through a step-by-step guide on how to harness the potential of artificial intelligence to automate the creation of action items from meeting minutes. By leveraging the capabilities of the OpenAI ChatGPT API, you can effortlessly streamline the process of extracting key points from meetings and generating actionable tasks. Whether you're new to AI integration or an experienced developer, this comprehensive tutorial will provide you with the tools and knowledge to seamlessly incorporate AI into your workflow within Google Docs.


ChatGPT, an AI language model developed by OpenAI, is a quick and efficient method for generating automated action items from meeting minutes or discussions. You can create complete action items in Google docs with just a few clicks. This blog post will take you through a step-by-step guide, for the following:

  1. Creating an empty Google Doc

  2. Setting up the Apps Script editor for Google Docs

  3. Copying the Apps Script code to the doc & implement the OpenAI API integration

  4. Authenticating the API using the API Key 

  5. Running and testing the script call to the OpenAI API "chat/completions"

  6. Checking the output to ensure it creates the action items properly


By following this tutorial, you can harness the power of AI to improve productivity and efficiency in your document workflow. Let's start and unlock the potential of automated action item generation in Google Docs.


Introduction to the OpenAI (ChatGPT) API

By now, you've probably heard of ChatGPT, and its many powerful capabilities. However, not everyone has used this technology through the API. The API allows developers to programmatically invoke the AI capability of ChatGPT and integrate it into various applications. This API approach enables businesses and individuals to leverage the power of the AI language model to enhance user experiences and automate various processes. By understanding how the OpenAI API works, we can seamlessly integrate the AI capabilities into our Google Doc to create an AI-generated list of action items.


Introduction to Google Apps Script

Google Apps Script is a cloud-based JavaScript platform that lets you integrate with and automate tasks across Google products. It allows users to automate tasks within various Google applications, including Google Docs. This Javascript language enables users to customize and extend the functionality of Google Docs by writing small snippets of code. With Google Apps Script, users can automate repetitive tasks or build complete applications right within Google Docs. Whether it's sending personalized emails, integrating with other Google services, or creating an AI-powered action items generator, Google Apps Script provides an efficient way to streamline workflows and boost productivity within Google Docs.


Prerequisites for these Step-by-Step instructions

There are a few requirements for you to implement ChatGPT for Google Docs. They are the following:

  1. An OpenAI API account: You will need access to the OpenAI APIs to call them directly from the Apps Script, which doesn’t require a ChatGPT Plus account but does necessitate an OpenAI API plan. You can find more details here: https://openai.com/product.The OpenAI API pricing model is quite affordable, based on the number of tokens utilized. Create an account before you begin the steps in this document.

  2. Access to Google Docs: Since the call to the API is from a document that holds the meeting minutes and will also hold the newly generated action items, you need access to Google Docs to follow these instructions. As long as you have a Google Gmail account, you have access to Google Docs.

  3. Familiarity with programming is helpful: The OpenAI API will be called from the Google Apps Script, which is programmed in Javascript.  Even without knowing how to program, you should be able to follow all the steps in this guide, but if you run into problems, some familiarity with programming would help determine what the issue is and how to fix it.


A step-by-step guide to creating a Gen-AI powered Action Item generator in Google Docs

Now that we have a basic understanding of automated action item generation and the tools involved, let's dive into the step-by-step tutorial on generating action items programmatically in Google Docs.

In this automated action item generator, the input is what you would see as typical meeting minutes when discussing a project's status. The example I use is fictitious but represents what might be discussed when reviewing the status of an IT project.  I have chosen to use an approach in the document to indicate the location of the meeting minutes by using delimiters.  This was for convenience but could also be removed, and the apps script code could use the entire document text as input.  The format that the script will be looking for is a set of delimiters in the document that indicate where the minutes start and end.  The basic format is the following:

example of the Word document layout with the start and end delimiters

The script will search and find the meeting minutes start and end markers of “meeting minutes start:” and “meeting minutes end”.  It will extract the text between these delimiters to use as input to the analysis for the action items. You can see these delimiters being defined in the script where it calls the "extractText" function. If you wish to use other delimiters, you can easily change the values used in the function parameters.

When you are ready to insert your meeting minutes, replace the text in red (shown above) with the text for the meeting minutes. This approach allows you to create a Google doc with these delimiters and type the meeting minutes between the start and end delimiters in the document. Then, once the meeting is done, run the generateActionItems script to create the complete list of action items.

The script instructs the OpenAI ChatGPT API on what action to take. The details must be specified in the OpenAI prompt to ensure the chat API performs the correct prompt action.



Step 1: Create the new Google doc


1) On your Google account on the top right should be a menu that when you click opens the item to create "Google Docs".

Image showing in Google where to access Google Docs

2) Choose Start a new "Blank document" which creates a new Untitled document

Image showing start a new document in Google docs

3) Rename the document to something more meaningful using the "rename" as shown below:

Image showing renaming a new google doc

Step 2: Create the Google Apps Script


1) On the top menu in the Doc choose "Extensions" -> "Apps Script"

Image showing choosing "extensions" and then "apps script" in google doc

2) This opens the Apps Script editor in a new browser tab, allowing you to create the Javascript code that calls the ChatGPT API. You will notice it creates an empty "Untitled" project with an initial Apps Script function called "myFunction". We will replace this default function with code that has the OpenAI API integration.

Image showing an empty Apps Script project

3)  Next, you want to copy the Apps Script code I provide at the below GitHub URL. The entire code can be copied from the below URL to the editor window replacing the empty function.

You should end up with a project similar to the one below:

Image showing action item script code copied

4) Rename the project to a more useful name. Click on the "Untitled project" name to open a window for you to enter the name. I renamed it to "Action Item Generator".

Image showing rename of an Apps Script project

5) Be sure to save the new project so you don't loose your work by clicking on the icon that resembles a floppy disk.

Image showing "Save" of a project

One item to note is that when you click the save button, Apps Script will syntax-check the code to make sure there are no syntactic errors. You may get an error reported to the UI if you have entered the code incorrectly, as shown in the example below. If you encounter an error check that all the code is copied correctly.

Image indicating a syntax error in the script

   

There are a few things to note in the Apps Script code:

  • The default model (LLM - Large Language Model) used in the text generation is "gpt-4-turbo-preview" since it gave me the best results for the action items. You can change this to use other models of your choice. I suggest starting with gpt-4-turbo-preview, and once you have everything set up and working, you can change it to other models that may give you better results in the action items generated.

  • The OpenAI API endpoint called for the action items generation is the “chat/completions” API. This API is compatible with a specific list of language models, which changes over time. I recommend checking the OpenAI website to ensure you use a compatible model.

  • The crucial line of code that instructs OpenAI on the desired behavior is the line of code assigning a value to the “systemPrompt” const. This directive is a key part of the ChatGPT action item prompt, and I’ve found it to be effective in guiding OpenAI in producing the most accurate set of action items.  You can modify these instructions to try different text and see the resulting set of action items.  You will notice that in the system prompt I also give guidance to OpenAI on the formatting of the action items to a format I desire for use in the document. 

  • The code has error handling to ensure the meeting minutes are found. If something is missing in the document and the text delimiters cannot be found, messages will logged to the Apps Script execution log. Refer to the details of viewing the log in the error resolution section later in this blog post.

  • The script has a function called "onOpen" that creates a Google doc menu item to allow you to execute the script. You will see this explained later in Step 4.


Step 3: Setting up the API key to call the OpenAI API

Keep going; your determination is about to be rewarded as you approach the final stages before you can execute the script. Just a few more steps remain, and you'll be all set to give it a try.

1)   Copy your API key from the OpenAI API account site into the script.  The script will make an API call to the OpenAI endpoint, retrieve the generated content, and insert it into your Google doc.  This API key provides you with the API authentication, ensuring it's use that is using the OpenAI account. Login to your OpenAI API account that you created in the Prerequisites step and access the API key tab in the menu or use this API Keys link.

Image of OpenAI UI showing API yeys tab

2)  In the API keys UI, click the “Create new secret key” button to create a new API key for the API call. 

Image of OpenAI API keys tab with "Create new secret key" button

3) Once the API key is created, copy it into the indicated line of the script shown below. Carefully replace the placeholder with your unique key to ensure secure access to the OpenAI API from your personal account. At this point you have implemented the API authentication code that will be used when the script is run.

Remember, this key is confidential and should not be shared, as it is your exclusive access to your account.

Image indicating location in script to place your API key

     

Step 4: Running and testing the script call to ChatGPT API

1) Now that you have the Apps Script project created and using your API key, you can test the script to see if it is set up properly. The Apps Script you created is a container-bound project. This means that the Apps Script project is attached or bound to the Google Doc that you initially created. The project is embedded within the docs file. Return to the Google Doc (I named it Generate Action Items) and refresh the tab on the browser or reopen the doc. Once refreshed, you will see the menu option "AI Tools" with the subitem "Generate Action Items". This menu item was created by the "onOpen" function in the script.

Google Doc showing "AI Tools" menu item

2) Copy some example meeting minutes between the delimiters in the document as shown below. Do not worry about the color of the text. I show it in green to allow you to easily see the text delimiters vs the status meeting minutes.

Image showing meeting minutes copied into the doc

3)  Once the document is ready, choose "AI Tools" -> "Generate Action Items" on the doc menu. This will execute the script in the "Action Item Generator" project. You may need to provide authorization for the script to run on this Google account. When the authorization message is displayed, choose which Google account to allow the access and then click "Allow".

When the script is running, a message will be displayed in the document's UI, as shown below.

Image showing the script running message in Google Doc UI


4)  If the ChatGPT API request is successful, a list of action items will be generated and inserted into the document after any existing text.  I have included a screenshot of a partial example below:

Image showing example of generated action items

  • If no text is inserted, check for error messages indicating possible problems. If there are errors, check the steps above to ensure that all actions have been implemented properly. Errors will be logged to the Apps Script execution log. Refer to the section Error Resolution for a description of how to find the execution log and a list of possible errors and how to resolve them.

5)  The OpenAI chat/completions request body has a couple of API parameters you can modify to try different outputs and determine which provides the best results. These are the "temperature", "top_p", “frequency_penalty”, and “presence_penalty” parameters. A detailed description of these parameters can be found in the OpenAI ChatGPT API documentation for chat completions API.  To view the values I used, check the script code to see the values defined for the corresponding consts.

 

 

Step 5: Checking the action items generated for accuracy

While the AI Action item generator in this Google Docs integration provides a starting point, you will want to review the action items and ensure they are accurate.  While testing this approach, I found that, at times, it missed some of the action items or got the details incorrect for the action item.  This could be due to the meeting minutes not providing enough information for ChatGPT to represent the action items correctly. Therefore, you may have to add missing information or correct due dates if you are aware of additional information that the minutes did not properly represent.

Although you'll probably need to revise the action items, this serves as a solid starting point and will require less time to update than creating them from the beginning.


 

Automated Action Item Generators: Simplifying Tasks and Boosting Productivity

Automated action item generators are just one of many tools available to simplify day-to-day tasks and enhance productivity. As described above, integrating OpenAI Generative AI into a Google document is just one example of how OpenAI can be utilized.

As AI technology advances, the accuracy of generated action items will improve. This automation process can become even more efficient by providing additional training on your business processes or templates.

Utilizing the OpenAI API with Google Docs integration to automate action item creation allows you to focus on more complex tasks that require further investigation and analysis, which cannot currently be automated with Generative AI. By following the step-by-step tutorial, you can harness the power of AI to enhance overall productivity and contribute to the success of your business.

I hope this serves as a starting point and encourages you to consider other tasks that can be similarly automated, reducing your workload and increasing efficiency.


Error resolution

There are a few possible problems you may encounter when running the generator.

To view error messages sent to the Apps Script execution log, you will want to open the log window.

Accessing the Apps Script execution logs

In the Apps Script editor on the left, click "Executions"

Image showing how to access Execution log in Apps Script

This will open the Execution log window and allow you to view any of the logs from the running of the script on this document. Click on any of the rows to see the details of the logs. Any errors handled by the script code or any unexpected errors will have the details logged here.

Image showing Execution logs in Apps Script

I have provided two commented-out lines of code that log information to the execution log. These can be used if your script is not working properly, and you need to perform some API error handling to resolve the issue. These two lines are 84 and 129 in the script. Simply remove the "//" at the beginning of the line and execute the script. It will log this information in the execution log.


Possible error conditions and resolutions:

  • Truncation of the text: If the action items generated look truncated, it’s likely due to the number of tokens specified in the request. The script provided limits it to 1000 tokens; if your list of action items is extensive, you must increase this limit. To make this change, increase the number of the parameter “max_tokens” in the line of code for the payload, as shown below.

Image showing line of code to change the number of tokens

  • If you see the following error, it indicates that you have inserted the incorrect API key or that the API key is missing. Check that the API key is inserted into the proper location as indicated in Step 3.3 above and that it is the exact key from your OpenAI account. The const “API_KEY” must contain your API key.

Image showing the error in the log when the API key is incorrect
  • If the start and end delimiters are not found in the document to indicate where the meeting minutes are located, then you will see the following message in the log:

Image showing error in log when the start and end delimiters are not found
  • If the start and end delimiters are found but the meeting minutes are empty you will see the following message in the log:

Image showing error in log when the meeting minutes are empty
  • If you see the Error 400 it indicates there is an issue with the API call and likely a problem with the payload sent to the API. Common causes of the error 400 are issues with the JSON in the payload or invalid parameters sent to the API. 

Image showing Error 400 in the execution log

Comments


bottom of page