{"id":654,"date":"2022-11-03T12:44:00","date_gmt":"2022-11-03T12:44:00","guid":{"rendered":"https:\/\/promptmuse.com\/?p=654"},"modified":"2022-12-03T14:59:25","modified_gmt":"2022-12-03T14:59:25","slug":"adding-open-api-script-to-google-sheets","status":"publish","type":"post","link":"https:\/\/promptmuse.com\/adding-open-api-script-to-google-sheets\/","title":{"rendered":"Adding OPEN AI Script to Google Sheets"},"content":{"rendered":"\n
In this blog, we’ll be exploring how to add GPT-3 Open AI Script to Google Sheets, allowing you to quickly and easily incorporate AI into your data analysis. We’ll be covering topics such as setting up your environment, connecting GPT-3 Open AI Script to Google Sheets, and how to use the script in the best way possible. So buckle up and get ready to learn how to add AI to your spreadsheets!
Step By Step<\/p>\n\n\n\n
1.<\/p>\n\n\n\n
Double-click \u2018Untitled spreadsheet\u2019 and give your new blank spreadsheet a new name.<\/p>\n\n\n\n 2.<\/p>\n\n\n\n Then select \u2018Extensions\u2019 from the menu<\/p>\n\n\n\n 3.<\/p>\n\n\n\n and then click \u2018Apps Script\u2019<\/p>\n\n\n\n 4.<\/p>\n\n\n\n Delete the boilerplate content which is there by default. We won’t be needing that.<\/p>\n\n\n\n 5.<\/p>\n\n\n\n Next, we paste in the script provided below:<\/p>\n\n\n\n 6.<\/p>\n\n\n\n <\/picture><\/figure>\n\n\n\n
<\/picture><\/figure>\n\n\n\n
<\/picture><\/figure>\n\n\n\n
<\/picture><\/figure>\n\n\n\n
const SECRET_KEY = 'INSERT YOUR API KEY HERE';\nconst MAX_TOKENS = 200;\n\n\/**\n * Completes your prompt with GPT-3\n *\n * @param {string} prompt Prompt\n * @param {number} temperature (Optional) Temperature. 1 is super creative while 0 is very exact and precise. Defaults to 0.4.\n * @param {string} model (Optional) GPT-3 Model to use. Defaults to \"text-davinci-002\".\n * @return Completion returned by GPT-3\n * @customfunction\n *\/\nfunction AI(prompt, temperature = 0.4, model = \"text-davinci-002\") {\n const url = \"https:\/\/api.openai.com\/v1\/completions\";\n const payload = {\n model: model,\n prompt: prompt,\n temperature: temperature,\n max_tokens: MAX_TOKENS,\n };\n const options = {\n contentType: \"application\/json\",\n headers: { Authorization: \"Bearer \" + SECRET_KEY },\n payload: JSON.stringify(payload),\n };\n const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());\n return res.choices[0].text.trim();\n}\n\n\/**\n * Classifies an item into a fixed set of categories\n * @param {range} categories Set of categories\n * @param {string} item Item to classify\n * @param {range} rules (Optional) Set of rules written in plain text\n * @return Completion returned by GPT-3\n * @customfunction\n *\/\nfunction CATEGORIZE(categories, input, rules=[]) {\n const prompt = \"The available categories are \" + categories.map((c) => `\"${c}\"`).join(\", \") + \". \" + rules.join(\". \") + \"The category for '\" + input + \"' is \";\n console.log(prompt);\n const completion = AI(prompt, 0, \"text-davinci-002\");\n \/\/ Replace \"s and .s at the start and end of the string\n return completion.replace(\/^\"\/g, '').replace(\/[\"|.]{0,2}$\/, '');\n}\n<\/code><\/pre>\n\n\n\n
<\/picture><\/figure>\n\n\n\n