{"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

\"Prompt <\/picture><\/figure>\n\n\n\n

2.<\/p>\n\n\n\n

Then select \u2018Extensions\u2019 from the menu<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

3.<\/p>\n\n\n\n

and then click \u2018Apps Script\u2019<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\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

\"Prompt <\/picture><\/figure>\n\n\n\n

5.<\/p>\n\n\n\n

Next, we paste in the script provided below:<\/p>\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
\"Prompt <\/picture><\/figure>\n\n\n\n

6.<\/p>\n\n\n\n

Then locate the top section, and paste in your OPEN AI API key<\/a> in the section which says ‘INSERT YOUR API KEY HERE’ (Note: the key should be inside the single quotes ‘ ‘ )<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

7.<\/p>\n\n\n\n

Press SAVE<\/p>\n\n\n\n

NOTE: If you do not put your API key between the quotes, it will not work – and a message as such will display when you try to save.<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

8.<\/p>\n\n\n\n

Click the \u2018Run the selected function\u2019 button<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

9.<\/p>\n\n\n\n

It will then request a bunch of permissions. Click review, and accept.<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

11.<\/p>\n\n\n\n

Give permission to your profile.<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

12.<\/p>\n\n\n\n

As this is a custom script, it will be flagged, but nothing sus here, promise. – You can view the script yourself. It is simply a direct connection to Open API. Click Advanced.<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

13.<\/p>\n\n\n\n

Click goto project<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

14.<\/p>\n\n\n\n

Click the \u2018Allow\u2019 button<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n

15.<\/p>\n\n\n\n

All done. You can now head back to the google sheet for some fun.<\/p>\n\n\n\n

\"Prompt <\/picture><\/figure>\n\n\n\n
\"Prompt <\/picture><\/figure>\n\n\n\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

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<\/p>\n","protected":false},"author":1,"featured_media":678,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[6,1,23],"tags":[],"featured_image_src":"https:\/\/promptmuse.com\/wp-content\/uploads\/2022\/12\/55-1-1024x775.jpg","blog_images":{"medium":"https:\/\/promptmuse.com\/wp-content\/uploads\/2022\/12\/55-1-300x227.jpg","large":"https:\/\/promptmuse.com\/wp-content\/uploads\/2022\/12\/55-1-1024x775.jpg"},"acf":[],"ams_acf":[{"key":"video_url","label":"Video URL","value":""}],"_links":{"self":[{"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/posts\/654"}],"collection":[{"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/comments?post=654"}],"version-history":[{"count":0,"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/posts\/654\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/media\/678"}],"wp:attachment":[{"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/media?parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/categories?post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/promptmuse.com\/wp-json\/wp\/v2\/tags?post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}