sheets-llm
Use Large Language Models (LLM) in Google Sheets
AI Summary
sheets-llm
A Google Apps Script that exposes OpenAI GPT models to Google Sheets through the custom function `=LLM()`.
Target Users
Entry- to mid-level GAS users building internal tools who need to summarise, translate, or classify spreadsheet data.
Problems Solved
Directly invoking the OpenAI API requires fetch code and credential handling, making reuse in Sheets cumbersome.
Tags
Main Features
Use GPT via a sheet function
Adds the `=LLM()` custom function so GPT responses can be fetched by passing text and a prompt directly from a cell.
API key settings UI
Provides an "LLM → Settings" dialog that saves the OpenAI API key to PropertiesService, avoiding hard-coding credentials.
Configurable model and temperature
Model name (e.g., gpt-4o-mini, gpt-4) and temperature can be supplied as arguments, allowing users to tune accuracy and creativity.
Usage Examples
Minimal call to GPT from a spreadsheet
/**
* Example that calls the custom function LLM from a script.
* In a sheet you can simply type =LLM("Hello","Translate to Japanese").
*/
function testLLM() {
// 1st arg: input text
// 2nd arg: prompt or instruction
// 3rd arg: model (optional)
// 4th arg: temperature (optional)
const result = LLM("Summarise yesterday's sales.", "Summarise the text", "gpt-4o-mini", 0);
Logger.log(result); // Prints the assistant's reply
}
Paste the snippet into the Apps Script editor and run testLLM
. The answer returned by GPT is logged to View → Logs
. Make sure you have saved your OpenAI API key via the LLM → Settings
dialog beforehand.