{"type":"video","version":"1.0","html":"<iframe src=\"https://www.loom.com/embed/a1ffe7fabcf8467a9a17ffef92602108\" frameborder=\"0\" width=\"1280\" height=\"960\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>","height":960,"width":1280,"provider_name":"Loom","provider_url":"https://www.loom.com","thumbnail_height":960,"thumbnail_width":1280,"thumbnail_url":"https://cdn.loom.com/sessions/thumbnails/a1ffe7fabcf8467a9a17ffef92602108-00001.gif","duration":126.772,"title":"GPTs in Sheets Using our Script","description":"Below is our script for you to copy and paste:\n\n// The two functions used in cell references are defined below\n// A cell with =GPT(A2) will return contents in cell A2 using faster gpt-3.5-turbo\n// and a cell with =GPT4(A2) in a cell will do the same but using the more powerful gpt-4 model.\n\nfunction GPT(input) {\n  return gptCommon(input, \"gpt-3.5-turbo\");\n}\n\nfunction GPT4(input) {\n  return gptCommon(input, \"gpt-4\");\n}\n\n\n// common function dealing with the aip calls using the model needed\nfunction gptCommon(input, model) {\n  const GPT_API = \"YOUR-OPEN-AI-API-KEY\"; //your Open AI API key goes here.\n  const BASE_URL = \"https://api.openai.com/v1/chat/completions\";\n\n  const headers = {\n    \"Content-Type\": \"application/json\",\n    \"Authorization\": `Bearer ${GPT_API}`\n  };\n\n  const options = {\n    method: \"POST\", // GET also works\n    muteHttpExceptions: true,\n    headers: headers,\n    payload: JSON.stringify({\n      model: model,\n      messages: [\n        { \"role\": \"system\", \"content\": \"\" },\n        { \"role\": \"user\", \"content\": input }\n      ],\n      temperature: 0.2  // value between 0 and 1 think of it like 0 very conservative and 1 excentric for B2B we suggest 0.2.\n    })\n  };\n\n  const response = JSON.parse(UrlFetchApp.fetch(BASE_URL, options));\n  console.log(response.choices[0].message.content);\n  return response.choices[0].message.content;\n}"}