Better Sheets - Free AI Integration
Hi Spreadsheeters! Andrew from Better Sheets here with a very simple, and quick thing for you. I say thing because it's just a piece of code but it can help you in an infinite number of ways. Want to integrate AI?You can use the OpenAI API. and I made a 2 minute video to show you how.
and... you can copy the code from here, or from Better Sheets.
function ai(prompt) {
var apikey = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("apikey").getRange("A1").getValue();
var role = ""
var data = {
"model": "gpt-3.5-turbo",
"messages": [{"role": "system", "content": role},
{"role": "user", "content": prompt }],
"temperature": 1,
"max_tokens": 500,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
}
var options = {
'method': 'POST',
'contentType': 'application/json',
'headers': {
'Authorization' : 'Bearer ' + apikey
},
'payload': JSON.stringify(data)
}
var answer = UrlFetchApp.fetch("https://api.openai.com/v1/chat/completions",options)
var response = answer.getContentText()
var json = JSON.parse(response)
return json.choices[0].message.content
}
Now do you want to be able to read the code?Basically the function is named "ai" and then a text variable is used to fill in for the prompt you can enter in the function in sheets. Any text you add in the function in side of your cell will be used as "prompt" inside the function. We'll get the apikey for the API call from the cell A1 in the tab named "apikey" Then we'll add the settings like max_tokens and top_p as data. Then we'll create the payload and the headers for the API call. In this case we're using a POST api call to essentially add the prompt text to OpenAI and we'll end up getting a response that's text. We execute the API call with UrlFetchApp.fetch() along with the options we stated earlier. Then we'll get the response, get the text, and parse it with JSON. Finally we'll return just the message content from the JSON we get back to we can read the text the AI gives us back. Now do you want to be able to Master the code?Master Spreadsheet Automation on Udemy is the course that includes learning apps script AND the OpenAI Api.
If you're already a Better Sheets member, I'd recommend Spreadsheet Automation 101 and Adventures in AI, so that you can both understand the apps script and fully use AI to it's greatest potential inside of Google Sheets.
Both of these courses are available in the one course on Udemy. -Andrew Your resident Google Sheets wizard at Better Sheets |
Older messages
If you want to sell a spreadsheets, you have to write a sales page
Monday, March 18, 2024
Better Sheets Members and Non-Members, Just added a brand new section to the course: Selling Spreadsheets Available free for Better Sheets members 👍 Selling Spreadsheets → on BetterSheets.co And the
Free Course
Wednesday, March 6, 2024
Hi, It's Andrew from Better Sheets. You've heard it before "Learn to Code" Have you ever wanted to code and just get overwhelmed? HTML → CSS →Javascript → Oh my! And then you jump
You Can Build Web Apps with Google Sheets
Monday, March 4, 2024
I recently got a kick out of building full apps within Google Sheets and Apps Script and putting those on the web. Front end and all! Of course I made some videos. Essentially I'm showing you how
How to Make a Sellable Spreadsheet
Tuesday, February 27, 2024
Hello Sheet Fans! Just added a whole new section to Selling Spreadsheets: How to Make a Spreadsheet Monthly and Lifetime members already have access here: → https://bettersheets.co/courses/selling-
Free Tool: Spintax Updated!
Friday, February 23, 2024
Hi, This week I've updated Spintax. It can now generate Spintax for you. You give it a sentence or a paragraph and it will be "spin" it. The tool is free, but uses OpenAI API KEY to
You Might Also Like
How To Plant Nearly 1,000 Trees an Hour
Friday, February 14, 2025
A regular Johnny Appleseed, minus the apples.
Optimization research not driving impact?
Friday, February 14, 2025
Here's a framework to fix it... ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
What is the 'perfectly optimised' article for SEO?
Friday, February 14, 2025
It can be daunting to decide what to do to give your news article the best chance of performing in Google. Here I look at the seven most valuable optimisation elements. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
• Book Series Promos for Authors • All in one order • FB Reader Groups + Pins
Friday, February 14, 2025
~ Book Series Ads for Authors ~ All in One Order! SEE WHAT AUTHORS ARE SAYING ABOUT CONTENTMO ! BOOK SERIES PROMOTIONS by ContentMo We want to help you get your book series out on front of readers. Our
🧙♂️ [Sponsor Games] How Jeff made $80,000 from sponsorships (without a huge audience)
Friday, February 14, 2025
real talk ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
When Naptime Conflicts With Your Civic Duty?
Friday, February 14, 2025
The only “duty” he was concerned with was spelled differently.
Is Art About Money?
Friday, February 14, 2025
Your weekly 5-minute read with timeless ideas on art and creativity intersecting with business and life͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
For Authors: Affordable Proofreading Services by ContentMo
Friday, February 14, 2025
👓 Two sets of eyes are better! 👓 👓 Two sets of eyes are better! 👓 Accurate & Affordable
Toys, scratching, and quantum strategies
Friday, February 14, 2025
Your new Strategy Toolkit newsletter (February 11, 2025) ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ 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