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
Strategic Decision-Making with the ICE Framework [Scale Your Impact #118]
Sunday, May 5, 2024
What if you could decisively move forward with a small selection of strategies that are feasible to implement and will most likely make an impact?
Global South women's rights fellowship, Workshop on finding remote jobs, Head of sustainability & inclusion at Green Climate Fund
Sunday, May 5, 2024
The Bloom Issue #167, May 5
Food for Agile Thought #441: The Hexi Approach to Scaling, Good and Bad Product Coaches, Product Roadmap Failure
Sunday, May 5, 2024
Also: Kaizen, OKR Fragility, Decision Frameworks, Guide to Product Surveys
FTI #411: In retrospect...
Sunday, May 5, 2024
You don't know what you're doing. You think you do, but you don't. Neither do I. Now, on to this week's ideas... *** The Starting Five 1. How To Create A Business Process Map
Now Open <> End of May Holiday Newsletter Promo for Authors + Social media
Sunday, May 5, 2024
For Authors ~ Join Our Book Newsletter for Summer Reading Enable Images to See This Join ContentMo's MAY 2024 Summer Reading Promotion & Get Your Book Emailed ~ Tweeted & posted to Facebook
Peaky Blinders saved my life
Saturday, May 4, 2024
My morning date with Thomas Shelby
What would your life be like with LESS stuff?
Saturday, May 4, 2024
Five years ago I made a choice that changed my life. I was at home with my kids, drowning in stuff, and not the present, happy mom I wanted to be. (It wasn't even our home. We had too much consumer
🎙️ Find That Pod #260
Friday, May 3, 2024
Check out these 5 great podcasts...and bring some awesomeness to your ears. Let's take a look at this week's recommendations. ADVERTISEMENT 5 great podcasts to discover… Welcome to the 260th
Around the Newsletter Universe (May Edition)
Friday, May 3, 2024
feed your inbox.
Where do you start?
Friday, May 3, 2024
We have 4 updates for you this week: 1. Where do you start improving your website? Congrats you want to improve your website performance. Everyone has their ideas on where to start. Your competitors