OpenAI has recently become very popular due to its intelligence that is able to answer a lot of diverse questions that can ultimately help various types of work in daily activities. OpenAI cannot be used for everything but it is very helpful in many other ways.
With OpenAI intelligence, one can utilize it for various purposes including finding fast and accurate references. Amazingly, OpenAI can be run on various other application platforms including using Google Sheets.
By utilizing OpenAI in Google Sheets you will finally no longer need to be confused about finding answers to some cases of questions related to data and usually processed in applications such as Google Sheets, because OpenAI will be able to provide answers that are good enough, and your job is just to review them or if they are not right you can just change them.
In addition, you can utilize Google Sheets and OpenAI simultaneously to save time in accessing OpenAI features because you don’t need to log in again on the OpenAI website if you have logged in using a Google account, or even if the OpenAI website is under maintenance you will be able to utilize its features with the API intermediary that you have connected with Google Sheets.
To connect OpenAI with Google Sheets and use it, you can follow this guide.
How to Use OpenAI in Google Sheets
- Go to Google Sheets and create a spreadsheet.
- Give your spreadsheet a name such as “MyOpenAI“.
- Click the “Extensions” > “Apps Script” menu.
- Name your Apps Script for example “OpenAIConnect“, and delete all scripts in it.
- Paste the following code into the “Code.gs” of your Apps Script. This code is the code that works when this article is created, if the code does not work you can probably find the latest code update here.
const SECRET_KEY = "ENTER YOUR SECRET KEY HERE";
const MAX_TOKENS = 200;
// For more cool AI snippets and demos, follow me on Twitter: https://twitter.com/_abi_
/**
* Completes your prompt with GPT-3
*
* @param {string} prompt Prompt
* @param {number} temperature (Optional) Temperature. 1 is super creative while 0 is very exact and precise. Defaults to 0.4.
* @param {string} model (Optional) GPT-3 Model to use. Defaults to "text-davinci-003".
* @return Completion returned by GPT-3
* @customfunction
*/
function AI(prompt, temperature = 0.4, model = "text-davinci-003") {
const url = "https://api.openai.com/v1/completions";
const payload = {
model: model,
prompt: prompt,
temperature: temperature,
max_tokens: MAX_TOKENS,
};
const options = {
contentType: "application/json",
headers: { Authorization: "Bearer " + SECRET_KEY },
payload: JSON.stringify(payload),
};
const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
return res.choices[0].text.trim();
}
/**
* Classifies an item into a fixed set of categories
* @param {range} categories Set of categories
* @param {string} item Item to classify
* @param {range} rules (Optional) Set of rules written in plain text
* @return Completion returned by GPT-3
* @customfunction
*/
function CATEGORIZE(categories, input, rules=[]) {
const prompt = "The available categories are " + categories.map((c) => `"${c}"`).join(", ") + ". " + rules.join(". ") + "The category for '" + input + "' is ";
console.log(prompt);
const completion = AI(prompt, 0, "text-davinci-003");
// Replace "s and .s at the start and end of the string
return completion.replace(/^"/g, '').replace(/["|.]{0,2}$/, '');
}
// For more cool AI snippets and demos, follow me on Twitter: https://twitter.com/_abi_
- Replace “ENTER YOUR SECRET KEY HERE” in the script above with the API from OpenAI which you can get here. To generate the API Key you can simply click “Create new secret key“.
- After finish you can click “Save Project” and you can return to your spreadsheet to try the OpenAI command directly in your Google Sheets.
- The following are the commands that you can use in your Google Sheet to get the features of OpenAI directly in your spreadsheet application.
=AI("explain in short about wikipedia")
=AI("explain in short about wikipedia",1)
=AI("explain in short about wikipedia",1,"text-davinci-003")
- Here is an example of the command execution result.
FAQ
Q: What is OpenAI?
A: OpenAI is a leading artificial intelligence research laboratory consisting of the for-profit technological company, OpenAI LP, and its parent company, the non-profit OpenAI Inc.
Q: What is the main goal of OpenAI?
A: The main goal of OpenAI is to promote and develop friendly AI in a way that benefits humanity as a whole.
Q: What kind of research does OpenAI focus on?
A: OpenAI focuses on advancing AI technologies, such as machine learning and robotics, to tackle real-world problems and improve human life.
Q: How is OpenAI funded?
A: OpenAI is funded through a combination of corporate sponsorships and research grants, as well as revenue generated by its commercial AI products and services.
Q: Is OpenAI open source?
A: OpenAI releases some of its research and tools as open source, but much of its intellectual property and technology is proprietary. The company operates on a selective open-source policy, releasing only those products and technologies that it believes will not compromise its competitive advantage.
That’s the guide on how you can use OpenAI directly from Google Sheets. In some cases this will be very helpful for your work, including finding data and references about your work.
If you are still confused with the guide on how to connect OpenAI and Google Sheets, you can view the guide in the form of a video below.
How to Use OpenAI in Google Sheets – Video
The following video will guide you through using OpenAI with Google Sheets.
Maybe you’re interested too?