Paste Below Code In AppScript and Run the run function and in google sheet column type the custom =Chat("Your Questions Here")
formula and press Enter.
const apiKey = "YOUR_OPEN_AI_API_KEY_HERE";
function run(){
Chat("Hello")
}
function Chat(question){
let payload = {
"model": "text-davinci-003",
"prompt": `${question}`,
"temperature": 0.7,
"max_tokens": 256,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
}
let options = {
"method":"post",
"headers":{
"Authorization":"Bearer "+apiKey,
"Content-Type":"application/json"
},
"payload":JSON.stringify(payload)
}
let req = UrlFetchApp.fetch("https://api.openai.com/v1/completions",options)
let res = JSON.parse(req).choices[0].text;
return res;
}