DEV Community

Kazuki Yonemoto
Kazuki Yonemoto

Posted on • Updated on

How to use GPT-3 in Google Apps Script

How to use GPT-3 in Google Apps Script

GPT-3 (Generative Pre-trained Transformer 3) is a state-of-the-art language generation model developed by OpenAI. It has been trained on a diverse range of internet text and can generate human-like text on a wide range of topics.

Why don't you use GPT-3 in Google Sheets? It's definitely useful if you could make it possible.

Google Sheets and GPT-3

I prepared two options to use GPT-3 with Google Sheets. You can follow the tutorial according to your purpose and skill set.

  1. Clone the sample sheet which has already deployed scripts.
  2. Create a new sheet and deploy scripts from your local development environment.

Create your account at OpenAI

You need to create an account at the first.
https://openai.com/api/

Access to OpenAI API keys, create a new secret key and copy it to your clipboard.

OpenAI API keys

1. Clone the sample sheet which has already deployed scripts

You can clone this sample sheet if you want to use GPT-3 function immediately without deployment.

πŸ“ˆ gas-gpt3-sample

Note: You need to set the OpenAI API key into script properties even though you cloned the sample sheet.

How to set the OpenAI API key into script properties

Apps Script

  1. Open your Apps Script project.
  2. At the left, click Project Settings The icon for project settings.
  3. To add the first property, under Script Properties click Add script property.
  4. To add second and subsequent properties, under Script Properties click Edit script properties > Add script property.
  5. For Property, enter the key name. The key name is must be OPENAI_API_KEY.
  6. For Value, enter the secret key you generated before.

How to add script properties

2. Create a new sheet and deploy scripts from your local development environment

Creating a repository from this template and cloning the repository.

πŸ“– gas-gpt-starter

You need to install Deno if you want to deploy and develop in your local environment.

Deno v1.29.4 or higher

πŸ¦• How to install Deno

Check out how to use and follow the documentaion.

πŸ“– gas-gpt-starter: How to use

3. GPT-3 function

  1. Authorize this project's script by execution
  2. Use GPT3() in your Google Workspace
GPT3(prompt, maxTokens, model, temperature)

// Example 1 on Google Sheets
=GPT3("Hello, world!")

// Example 2 on Google Sheets
=GPT3(A1, 200)

// Example 3 on Google Sheets
=GPT3(A1, 300, "text-babbage-001", 0.5)
Enter fullscreen mode Exit fullscreen mode

Parameters

  1. prompt: The prompt to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays.
  2. maxTokens: The maximum number of tokens to generate in the completion.
  3. model: ID of the model to use.
  4. temperature: What sampling temperature to use. Higher values means the model will take more risks.

Conclusion

The combination between GPT-3 and Google Sheets is really useful. I hope this article will help you improve your productivity.

Oldest comments (0)