This tutorial explains how to autocomplete text, answers in Google Sheets using GPT-3 AI. To do this, here I will talk about a simple and effective Google Apps Script that you can add to any Google Sheets to interact with OpenAI over API. It takes input from a specific cell of a Google Sheet and produces the output in some other cell of the sheet.
The Google Apps Script I have mentioned here adds a new formula in the Sheets that you can use to get answer to a question or generate content by completing a sentence. It interacts with the OpenAI API under the hood and fetches the text for you. The formula that it adds has options to specify the advanced parameters to generate text content using a specific model under GPT.
How to do Text Completion and Answer Generation in Google Sheets?
Using the gpt-sheets script is very simple. You just need GPT-3 API. For that, you need to create an account on OpenAI website. After that, you will have to opt for a paid account in order to get API access. Using GPT is actually very cheap. After signing up, go to the API keys section and generate a key there.
Now, you need to open Google Sheets. Use Extensions > Apps Script menu and then in the script editor paste the gpt-sheets script. You can copy the entire JS code from this GitHub repository.
Now, you just need to add the OpenAI API key. At the line number 25 that has “const API_KEY”, paste your API key there.
Click on the Save button from the toolbar. After that, you click on the Run. It will now ask to authorize the script by your Google account. So, allow the access and then you are all set.
Come back to the Google Sheet and use the
=GPT(Cell_Index) function to get the response from OpenAI GPT. For example, if you have an incomplete text or question in cell A1 and A2 then in B1 and B2, you paste the formula as shown in the screenshot below.
Hit enter and then it will show you the GPT response. This as simple as that. You can now create question in any cell and use the
GPT() function to fetch the result from GPT-3 AI. You can use it unlimited number of times.
=GPT(input, max_tokens, model, temperature, stop)
For advanced usage, you can turn to the GitHub repository of this Google Apps Script. Here you will find the details about the sophisticated usage of this script. From here, you can also specify a different model to fetch response as well.
If you are looking for a GPT companion for Google Sheet that is purely based on plain simple OpenAI API, then the Google Apps Script that I have mentioned here will help you. You just need to create it and deploy it. Once you are set up, you can start using unlimited number of times. With the help of this script, you can now supercharge Google Sheets and generate content via AI for free.