The Easiest Way to Integrate ChatGPT with Google Spreadsheets (No Extension) : Chris

The Easiest Way to Integrate ChatGPT with Google Spreadsheets (No Extension)
by: Chris
blow post content copied from  Be on the Right Side of Change
click here to view original post


https://youtu.be/rA9iddTwsNE

Here’s the code you can use:

const SECRET_KEY = "YOUR_API_KEY";
const MAX_TOKENS = 800;

function AI_ChatGPT(prompt, neighborCell, temperature = 0.9, model = "gpt-3.5-turbo") {
  const url = "https://api.openai.com/v1/chat/completions";
  const fullPrompt = `${prompt} ${neighborCell}`;
  const payload = {
    model: model,
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: fullPrompt },
    ],
    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].message.content.trim();
}

March 07, 2025 at 09:21PM
Click here for more details...

=============================
The original post is available in Be on the Right Side of Change by Chris
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce